summaryrefslogtreecommitdiff
path: root/libs/ardour/reverse.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-03-18 06:07:08 +0000
committerDavid Robillard <d@drobilla.net>2007-03-18 06:07:08 +0000
commit99904735e066804358f1d0bd138a84f1e9ecda91 (patch)
tree71a924cf1660b5b00231275bd481bbd27094dd9b /libs/ardour/reverse.cc
parenteb270e70a12c410cdd98585ad25bb6d8e384a4f5 (diff)
Merged with trunk R1612.
git-svn-id: svn://localhost/ardour2/branches/midi@1614 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/reverse.cc')
-rw-r--r--libs/ardour/reverse.cc33
1 files changed, 16 insertions, 17 deletions
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 <algorithm>
@@ -47,10 +46,9 @@ Reverse::run (boost::shared_ptr<AudioRegion> 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<AudioRegion> 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<AudioRegion> 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<AudioRegion> 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<AudioRegion> region)
out:
+ if (buf) {
+ delete [] buf;
+ }
+
if (ret) {
for (si = nsrcs.begin(); si != nsrcs.end(); ++si) {
boost::shared_ptr<AudioSource> asrc(boost::dynamic_pointer_cast<AudioSource>(*si));