From 801c1c484c3f84f2523c5d07d112bbf361add56c Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 31 May 2008 16:00:00 -0500 Subject: [PATCH] Don't drop frames when buffer crosses loop boundaries. --- Timeline/Engine/Audio_Region.C | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Timeline/Engine/Audio_Region.C b/Timeline/Engine/Audio_Region.C index 1b491de..f940c80 100644 --- a/Timeline/Engine/Audio_Region.C +++ b/Timeline/Engine/Audio_Region.C @@ -118,19 +118,24 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe if ( _loop ) { + nframes_t lofs = sofs % _loop; + nframes_t lstart = r.offset + lofs; -/* /\* keep things simple *\/ */ -/* assert( _loop > len ); */ - - nframes_t lstart = r.offset + ( sofs % _loop ); + if ( lofs + len > _loop ) + { + /* this buffer covers a loop bounary */ - cnt = _clip->read( buf + ofs, channel, lstart, len ); + /* read the first part */ + cnt = _clip->read( buf + ofs, channel, lstart, len - ( ( lofs + len ) - _loop ) ); + /* read the second part */ + cnt += _clip->read( buf + ofs + cnt, channel, lstart + cnt, len - cnt ); -/* /\* read the part before the loop point *\/ */ -/* cnt = _clip->read( buf + ofs, channel, start, min( len, _loop - start ) ); */ -/* /\* read the part after the loop point *\/ */ -/* cnt += _clip->read( buf + ofs + cnt, channel, _loop, len - cnt ); */ + /* TODO: declick/crossfade transition? */ + assert( cnt == len ); + } + else + cnt = _clip->read( buf + ofs, channel, lstart, len ); } else cnt = _clip->read( buf + ofs, channel, start, len );