-/** 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 ();
- }
- }
-
- int32_t const old_allocated = _allocated_frames;
- _allocated_frames = frames;
- if (old_allocated < _allocated_frames) {
- make_silent (old_allocated, _allocated_frames - old_allocated);
- }
-}