summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/buffer.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-08-12 08:20:24 +0000
committerDavid Robillard <d@drobilla.net>2006-08-12 08:20:24 +0000
commit30ab1fd61569f9d7fb7410d483fa68cbf9865c37 (patch)
tree60cf9b5228a2728cda6608d517528066253d1a17 /libs/ardour/ardour/buffer.h
parentcbdf686e391bc2e7b93f37a5d3fa9197cb178078 (diff)
Towards MIDI:
- Converted vector<Sample*> to BufferList and numerous counts from int to ChanCount (and related changes) - Added fancy type-generic iterators to BufferList, PortIterator (see IO::collect_input for a good example of the idea - the same code will work to read all input (of various types in a single IO, eg instruments) without modification no matter how many types we add) - Fixed comparison operator bugs with ChanCount (screwed up metering among other things) - Moved peak metering into it's own object, and moved most of the pan related code out of IO to panner (still a touch more to be done here for MIDI playback) Not directly MIDI related fixes for problems in trunk: - Fixed varispeed gain/pan automation to work properly (was reading the wrong range of automation data, probably causing nasty clicks?) - Fixed crash on varispeed looping (possibly only a 64-bit problem). It still doesn't work, but at least it doesn't die Quite a few things broken, and the new classes are pretty filthy still, but I think the direction is a lot better than all my previous plans... git-svn-id: svn://localhost/ardour2/branches/midi@795 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/buffer.h')
-rw-r--r--libs/ardour/ardour/buffer.h57
1 files changed, 44 insertions, 13 deletions
diff --git a/libs/ardour/ardour/buffer.h b/libs/ardour/ardour/buffer.h
index 981d941de7..accdd9c181 100644
--- a/libs/ardour/ardour/buffer.h
+++ b/libs/ardour/ardour/buffer.h
@@ -57,9 +57,12 @@ public:
DataType type() const { return _type; }
/** Clear (eg zero, or empty) buffer starting at TIME @a offset */
- virtual void clear(jack_nframes_t offset = 0) = 0;
+ virtual void silence(jack_nframes_t len, jack_nframes_t offset=0) = 0;
- virtual void write(const Buffer& src, jack_nframes_t offset, jack_nframes_t len) = 0;
+ /** Clear the entire buffer */
+ virtual void clear() { silence(_capacity, 0); }
+
+ virtual void read_from(const Buffer& src, jack_nframes_t offset, jack_nframes_t len) = 0;
protected:
Buffer(DataType type, size_t capacity)
@@ -88,23 +91,51 @@ public:
~AudioBuffer();
- void clear(jack_nframes_t offset=0) { memset(_data + offset, 0, sizeof (Sample) * _capacity); }
-
- /** Copy @a len frames starting at @a offset, from the start of @a src */
- void write(const Buffer& src, jack_nframes_t offset, jack_nframes_t len)
+ void silence(jack_nframes_t len, jack_nframes_t offset=0)
{
+ assert(_capacity > 0);
+ assert(offset + len <= _capacity);
+ memset(_data + offset, 0, sizeof (Sample) * len);
+ }
+
+ /** Read @a len frames FROM THE START OF @a src into self at @a offset */
+ void read_from(const Buffer& src, jack_nframes_t len, jack_nframes_t offset)
+ {
+ assert(_capacity > 0);
assert(src.type() == _type == DataType::AUDIO);
assert(offset + len <= _capacity);
- memcpy(_data + offset, ((AudioBuffer&)src).data(len, offset), sizeof(Sample) * len);
+ memcpy(_data + offset, ((AudioBuffer&)src).data(len), sizeof(Sample) * len);
}
- /** Copy @a len frames starting at @a offset, from the start of @a src */
- void write(const Sample* src, jack_nframes_t offset, jack_nframes_t len)
+ /** Accumulate (add)@a len frames FROM THE START OF @a src into self at @a offset */
+ void accumulate_from(const AudioBuffer& src, jack_nframes_t len, jack_nframes_t offset)
{
+ assert(_capacity > 0);
assert(offset + len <= _capacity);
- memcpy(_data + offset, src, sizeof(Sample) * len);
+
+ Sample* const dst_raw = _data + offset;
+ const Sample* const src_raw = src.data(len);
+
+ for (jack_nframes_t n = 0; n < len; ++n) {
+ dst_raw[n] += src_raw[n];
+ }
}
+
+ /** Accumulate (add) @a len frames FROM THE START OF @a src into self at @a offset
+ * scaling by @a gain_coeff */
+ void accumulate_with_gain_from(const AudioBuffer& src, jack_nframes_t len, jack_nframes_t offset, gain_t gain_coeff)
+ {
+ assert(_capacity > 0);
+ assert(offset + len <= _capacity);
+ Sample* const dst_raw = _data + offset;
+ const Sample* const src_raw = src.data(len);
+
+ for (jack_nframes_t n = 0; n < len; ++n) {
+ dst_raw[n] += src_raw[n] * gain_coeff;
+ }
+ }
+
/** Set the data contained by this buffer manually (for setting directly to jack buffer).
*
* Constructor MUST have been passed capacity=0 or this will die (to prevent mem leaks).
@@ -142,10 +173,10 @@ public:
~MidiBuffer();
- // FIXME: clear events starting at offset
- void clear(jack_nframes_t offset=0) { assert(offset == 0); _size = 0; }
+ // FIXME: clear events starting at offset in time
+ void silence(jack_nframes_t len, jack_nframes_t offset=0) { assert(offset == 0); _size = 0; }
- void write(const Buffer& src, jack_nframes_t offset, jack_nframes_t nframes);
+ void read_from(const Buffer& src, jack_nframes_t nframes, jack_nframes_t offset);
void set_size(size_t size) { _size = size; }