-/** 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 (int32_t frames)
-{
- if (_allocated_frames >= frames) {
- return;
- }
-
- /* Round up frames to the next power of 2 to reduce the number
- of realloc()s that are necessary.
- */
- frames--;
- frames |= frames >> 1;
- frames |= frames >> 2;
- frames |= frames >> 4;
- frames |= frames >> 8;
- frames |= frames >> 16;
- frames++;
-
- for (int i = 0; i < _channels; ++i) {
- _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;
-}