X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Freverse.cc;h=c7ebecea317029172a8d927a7cb005421861b3ab;hb=c7e404a1c0ee9af941a335e4bdd2f667b0c6317a;hp=2279331701be94f2f145c2bdb642d25b271023d8;hpb=fedf3d34f32264ac57c6a222b678dc90f2bb1a88;p=ardour.git diff --git a/libs/ardour/reverse.cc b/libs/ardour/reverse.cc index 2279331701..c7ebecea31 100644 --- a/libs/ardour/reverse.cc +++ b/libs/ardour/reverse.cc @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #include @@ -47,10 +46,9 @@ Reverse::run (boost::shared_ptr region) { SourceList nsrcs; SourceList::iterator si; - const nframes_t blocksize = 256 * 1048; - Sample buf[blocksize]; + nframes_t blocksize = 256 * 1024; + Sample* buf = 0; nframes_t fpos; - nframes_t fend; nframes_t fstart; nframes_t to_read; int ret = -1; @@ -61,20 +59,19 @@ Reverse::run (boost::shared_ptr region) goto out; } - fend = region->start() + region->length(); fstart = region->start(); - if (blocksize < fend) { - fpos =max(fstart, fend - blocksize); - } else { - fpos = fstart; + if (blocksize > region->length()) { + blocksize = region->length(); } - to_read = min (region->length(), blocksize); + fpos = max (fstart, (fstart + region->length() - blocksize)); + buf = new Sample[blocksize]; + to_read = blocksize; /* now read it backwards */ - while (1) { + while (to_read) { uint32_t n; @@ -85,7 +82,7 @@ Reverse::run (boost::shared_ptr region) if (region->audio_source (n)->read (buf, fpos, to_read) != to_read) { goto out; } - + /* swap memory order */ for (nframes_t i = 0; i < to_read/2; ++i) { @@ -101,13 +98,11 @@ Reverse::run (boost::shared_ptr region) } } - if (fpos == fstart) { - break; - } else if (fpos > fstart + to_read) { + if (fpos > fstart + blocksize) { fpos -= to_read; - to_read = min (fstart - fpos, blocksize); + to_read = blocksize; } else { - to_read = fpos-fstart; + to_read = fpos - fstart; fpos = fstart; } }; @@ -116,6 +111,10 @@ Reverse::run (boost::shared_ptr region) out: + if (buf) { + delete [] buf; + } + if (ret) { for (si = nsrcs.begin(); si != nsrcs.end(); ++si) { boost::shared_ptr asrc(boost::dynamic_pointer_cast(*si));