diff --git a/timeline/src/Audio_Region.H b/timeline/src/Audio_Region.H index 9e3978c..df45c9e 100644 --- a/timeline/src/Audio_Region.H +++ b/timeline/src/Audio_Region.H @@ -60,17 +60,17 @@ public: return length < rhs.length; } - float increment ( void ) const + double increment ( void ) const { - return 1.0f / (float)length; + return 1.0f / length; } /** Return gain for frame /index/ of /nframes/ on a gain curve * of type /type/.*/ /* FIXME: calling a function per sample is bad, switching on * type mid fade is bad. */ - inline float - gain ( const float fi ) const + inline double + gain ( const double fi ) const { switch ( type ) { @@ -87,7 +87,7 @@ public: } } - void apply ( sample_t *buf, fade_dir_e dir, long start, nframes_t end, nframes_t nframes ) const; + void apply ( sample_t *buf, fade_dir_e dir, nframes_t start, nframes_t nframes ) const; }; /* struct Fade_In : public Fade; */ diff --git a/timeline/src/Engine/Audio_Region.C b/timeline/src/Engine/Audio_Region.C index 465c1fc..4219922 100644 --- a/timeline/src/Engine/Audio_Region.C +++ b/timeline/src/Engine/Audio_Region.C @@ -33,31 +33,18 @@ -/** Apply a (portion of) fade from /start/ to /end/ assuming a - * buffer size of /nframes/. /start/ and /end/ are relative to the - * given buffer, and /start/ may be negative. */ +/** Apply a (portion of) fade from /start/ to a buffer up to size /nframes/. */ void -Audio_Region::Fade::apply ( sample_t *buf, Audio_Region::Fade::fade_dir_e dir, long start, nframes_t end, nframes_t nframes ) const +Audio_Region::Fade::apply ( sample_t *buf, Audio_Region::Fade::fade_dir_e dir, nframes_t start, nframes_t nframes ) const { // printf( "apply fade %s: start=%ld end=%lu\n", dir == Fade::Out ? "out" : "in", start, end ); - if ( ! nframes ) return; - const nframes_t i = start > 0 ? start : 0; - const nframes_t e = end > nframes ? nframes : end; - - assert( i < nframes ); - - const float inc = increment(); - float fi = ( i - start ) / (float)length; - -// buf += i; - buf = &buf[ i ]; + nframes_t n = nframes; - nframes_t n = e - i; - - assert( i + n <= nframes ); + const double inc = increment(); + double fi = start / (double)length; if ( dir == Fade::Out ) { @@ -94,18 +81,22 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe /* calculate offsets into file and sample buffer */ - nframes_t sofs, ofs, cnt; + nframes_t sofs, /* offset into source */ + ofs, /* offset into buffer */ + cnt; cnt = nframes; if ( pos < r.start ) { + /* region starts somewhere after the beginning of this buffer */ sofs = 0; ofs = r.start - pos; cnt -= ofs; } else { + /* region started before this buffer */ ofs = 0; sofs = pos - r.start; } @@ -161,34 +152,22 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe declick.type = Fade::Linear; { + assert( cnt <= nframes ); + Fade fade; fade = declick < _fade_in ? _fade_in : declick; /* do fade in if necessary */ if ( sofs < fade.length ) - { - const long d = 0L - (long)sofs; - - assert( cnt <= nframes ); - - fade.apply( buf + ofs, Fade::In, d, d + fade.length, cnt ); - } + fade.apply( buf + ofs, Fade::In, sofs , cnt ); fade = declick < _fade_out ? _fade_out : declick; /* do fade out if necessary */ -// if ( start + cnt + fade.length > r.end ) - if ( start + fade.length > ( r.offset + r.length ) ) - { - const nframes_t d = ( r.offset + r.length ) - start; - - assert( cnt <= nframes ); - - fade.apply( buf, Fade::Out, cnt + (long)d - fade.length, cnt + d, cnt ); - } + if ( start + fade.length > r.offset + r.length ) + fade.apply( buf, Fade::Out, ( start + fade.length ) - ( r.offset + r.length ), cnt ); } -// printf( "read %lu frames\n", cnt ); return cnt; }