From bb753424a4524850a8073192030b37da6ce2c73e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 27 Feb 2008 16:26:00 +0000 Subject: make AudioRegion::master_read() obey length limit of (first) master source, not the region length git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3129 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/audioregion.h | 3 ++- libs/ardour/audioregion.cc | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index c5d8618a1c..b2a6b275fa 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -169,7 +169,8 @@ class AudioRegion : public Region void recompute_gain_at_end (); void recompute_gain_at_start (); - nframes_t _read_at (const SourceList&, Sample *buf, Sample *mixdown_buffer, + nframes_t _read_at (const SourceList&, nframes_t limit, + Sample *buf, Sample *mixdown_buffer, float *gain_buffer, nframes_t position, nframes_t cnt, uint32_t chan_n = 0, nframes_t read_frames = 0, diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index bcb36ab85a..3e41b4df2f 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -458,7 +458,7 @@ nframes64_t AudioRegion::read (Sample* buf, nframes64_t position, nframes64_t cnt, int channel) const { /* raw read, no fades, no gain, nada */ - return _read_at (sources, buf, 0, 0, _position + position, cnt, channel, 0, 0, true); + return _read_at (sources, _length, buf, 0, 0, _position + position, cnt, channel, 0, 0, true); } nframes_t @@ -467,18 +467,19 @@ AudioRegion::read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, n uint32_t chan_n, nframes_t read_frames, nframes_t skip_frames) const { /* regular diskstream/butler read complete with fades etc */ - return _read_at (sources, buf, mixdown_buffer, gain_buffer, position, cnt, chan_n, read_frames, skip_frames, false); + return _read_at (sources, _length, buf, mixdown_buffer, gain_buffer, position, cnt, chan_n, read_frames, skip_frames, false); } nframes_t AudioRegion::master_read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, nframes_t position, nframes_t cnt, uint32_t chan_n) const { - return _read_at (master_sources, buf, mixdown_buffer, gain_buffer, position, cnt, chan_n, 0, 0); + return _read_at (master_sources, master_sources.front()->length(), buf, mixdown_buffer, gain_buffer, position, cnt, chan_n, 0, 0); } nframes_t -AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buffer, float *gain_buffer, +AudioRegion::_read_at (const SourceList& srcs, nframes_t limit, + Sample *buf, Sample *mixdown_buffer, float *gain_buffer, nframes_t position, nframes_t cnt, uint32_t chan_n, nframes_t read_frames, @@ -504,11 +505,11 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff buf_offset = 0; } - if (internal_offset >= _length) { + if (internal_offset >= limit) { return 0; /* read nothing */ } - if ((to_read = min (cnt, _length - internal_offset)) == 0) { + if ((to_read = min (cnt, limit - internal_offset)) == 0) { return 0; /* read nothing */ } @@ -580,31 +581,31 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff /* see if some part of this read is within the fade out */ /* ................. >| REGION - _length + limit { } FADE fade_out_length ^ - _length - fade_out_length + limit - fade_out_length |--------------| ^internal_offset ^internal_offset + to_read we need the intersection of [internal_offset,internal_offset+to_read] with - [_length - fade_out_length, _length] + [limit - fade_out_length, limit] */ nframes_t fade_out_length = (nframes_t) _fade_out.back()->when; - nframes_t fade_interval_start = max(internal_offset, _length-fade_out_length); - nframes_t fade_interval_end = min(internal_offset + to_read, _length); + nframes_t fade_interval_start = max(internal_offset, limit-fade_out_length); + nframes_t fade_interval_end = min(internal_offset + to_read, limit); if (fade_interval_end > fade_interval_start) { /* (part of the) the fade out is in this buffer */ nframes_t limit = fade_interval_end - fade_interval_start; - nframes_t curve_offset = fade_interval_start - (_length-fade_out_length); + nframes_t curve_offset = fade_interval_start - (limit-fade_out_length); nframes_t fade_offset = fade_interval_start - internal_offset; _fade_out.get_vector (curve_offset,curve_offset+limit, gain_buffer, limit); -- cgit v1.2.3