Skip to content

Commit

Permalink
* setting SFC_SET_SCALE_FLOAT_INT_READ to SF_TRUE to fix beschulz#7
Browse files Browse the repository at this point in the history
  • Loading branch information
beschulz committed Aug 8, 2013
1 parent 2639f0e commit e1decdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/wav2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void compute_waveform(
using std::endl;

// you can change it to float or short, short was much faster for me.
typedef float sample_type;
typedef short sample_type;

samples = std::min(wav.frames(), (sf_count_t)samples);

Expand All @@ -123,6 +123,10 @@ void compute_waveform(
channel = Options::LEFT;
}

// https://github.com/beschulz/wav2json/pull/7
// http://www.mega-nerd.com/libsndfile/api.html#note2
const_cast<SndfileHandle&>(wav).command(SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);

/*
the processing works like this:
for each vertical pixel in the image (x), read frames_per_pixel frames from
Expand All @@ -131,7 +135,7 @@ void compute_waveform(
for (size_t x = 0; x < samples; ++x)
{
// read frames
sf_count_t n = const_cast<SndfileHandle&>(wav).readf(&block[0], frames_per_pixel) * wav.channels();
sf_count_t n = const_cast<SndfileHandle&>(wav).read(&block[0], frames_per_pixel) * wav.channels();
assert(n <= (sf_count_t)block.size());

// find min and max
Expand Down
Loading

0 comments on commit e1decdb

Please sign in to comment.