summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Chappell <jesse@essej.net>2007-05-31 03:32:29 +0000
committerJesse Chappell <jesse@essej.net>2007-05-31 03:32:29 +0000
commitc967b91ddf1bcd03ef44d62022b95257cbd94f60 (patch)
tree9055a5f28bbcc2ef6f298ab8818134eef621fbeb
parent1fedefc78592a1c1cde15891b699c75b384704f0 (diff)
added declicking xfade in audio_diskstream for truly seamless transport looping
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@1932 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--libs/ardour/audio_diskstream.cc37
-rw-r--r--libs/ardour/automation_event.cc2
2 files changed, 35 insertions, 4 deletions
diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc
index b372c14b57..484e4a621a 100644
--- a/libs/ardour/audio_diskstream.cc
+++ b/libs/ardour/audio_diskstream.cc
@@ -1001,6 +1001,8 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
nframes_t loop_start = 0;
nframes_t loop_length = 0;
nframes_t offset = 0;
+ nframes_t xfade_samples = 0;
+ Sample xfade_buf[128];
Location *loc = 0;
/* XXX we don't currently play loops in reverse. not sure why */
@@ -1063,6 +1065,26 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
return -1;
}
+ // xfade loop boundary if appropriate
+
+ if (xfade_samples > 0) {
+ // just do a linear xfade for this short bit
+
+ xfade_samples = min(xfade_samples, this_read);
+
+ float delta = 1.0f / xfade_samples;
+ float scale = 0.0f;
+ Sample * tmpbuf = buf+offset;
+
+ for (size_t i=0; i < xfade_samples; ++i) {
+ *tmpbuf = (*tmpbuf * scale) + xfade_buf[i]*(1.0f - scale);
+ ++tmpbuf;
+ scale += delta;
+ }
+
+ xfade_samples = 0;
+ }
+
_read_data_count = _playlist->read_data_count();
if (reversed) {
@@ -1070,13 +1092,22 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
swap_by_ptr (buf, buf + this_read - 1);
} else {
-
+ start += this_read;
+
/* if we read to the end of the loop, go back to the beginning */
if (reloop) {
+ // read crossfade samples to apply to the next read
+
+ xfade_samples = min((nframes_t) 128, cnt-this_read);
+
+ if (audio_playlist()->read (xfade_buf, mixdown_buffer, gain_buffer, start, xfade_samples, channel) != xfade_samples) {
+ error << string_compose(_("AudioDiskstream %1: cannot read xfade samples %2 from playlist at frame %3"),
+ _id, xfade_samples,start) << endmsg;
+ memset(xfade_buf, 0, xfade_samples * sizeof(Sample)); // just in case
+ }
+
start = loop_start;
- } else {
- start += this_read;
}
}
diff --git a/libs/ardour/automation_event.cc b/libs/ardour/automation_event.cc
index 341fa82091..7b79cdf62c 100644
--- a/libs/ardour/automation_event.cc
+++ b/libs/ardour/automation_event.cc
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
+
*/
#include <set>