}
}
+void
+AudioBuffers::make_silent (int from, int frames)
+{
+ assert ((from + frames) <= _allocated_frames);
+
+ for (int c = 0; c < _channels; ++c) {
+ for (int i = from; i < (from + frames); ++i) {
+ _data[c][i] = 0;
+ }
+ }
+}
+
/** Copy data from another AudioBuffers to this one. All channels are copied.
* @param from AudioBuffers to copy from; must have the same number of channels as this.
* @param frames_to_copy Number of frames to copy.
/** Add data from from `from', `from_channel' to our channel `to_channel' */
void
-AudioBuffers::accumulate (AudioBuffers const * from, int from_channel, int to_channel)
+AudioBuffers::accumulate_channel (AudioBuffers const * from, int from_channel, int to_channel)
{
int const N = frames ();
assert (from->frames() == N);
+ assert (to_channel <= _channels);
float* s = from->data (from_channel);
float* d = _data[to_channel];
}
}
+/** Ensure we have space for at least a certain number of frames. If we extend
+ * the buffers, fill the new space with silence.
+ */
void
AudioBuffers::ensure_size (int frames)
{
}
for (int i = 0; i < _channels; ++i) {
- _data[i] = static_cast<float*> (realloc (_data[i], _frames * sizeof (float)));
+ _data[i] = static_cast<float*> (realloc (_data[i], frames * sizeof (float)));
if (!_data[i]) {
throw bad_alloc ();
}
+ for (int j = _allocated_frames; j < frames; ++j) {
+ _data[i][j] = 0;
+ }
}
+
+ _allocated_frames = frames;
}
+
+void
+AudioBuffers::accumulate_frames (AudioBuffers const * from, int read_offset, int write_offset, int frames)
+{
+ assert (_channels == from->channels ());
+
+ for (int i = 0; i < _channels; ++i) {
+ for (int j = 0; j < frames; ++j) {
+ _data[i][j + write_offset] += from->data()[i][j + read_offset];
+ }
+ }
+}
+