diff --git a/src/buffer.rs b/src/buffer.rs index 1610b95a..774c9983 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -64,10 +64,10 @@ pub struct AudioBufferOptions { /// /// - `cargo run --release --example audio_buffer` /// -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug)] pub struct AudioBuffer { - channels: Vec, - sample_rate: f32, + pub(crate) channels: Vec, + pub(crate) sample_rate: f32, } impl AudioBuffer { diff --git a/src/node/audio_buffer_source.rs b/src/node/audio_buffer_source.rs index 1f8cf20d..817b3a6f 100644 --- a/src/node/audio_buffer_source.rs +++ b/src/node/audio_buffer_source.rs @@ -781,8 +781,12 @@ impl AudioProcessor for AudioBufferSourceRenderer { // Avoid deallocation in the render thread by swapping the buffers. std::mem::swap(current_buffer, buffer); } else { - // The default buffer is empty and does not cause allocations. - self.buffer = Some(std::mem::take(buffer)); + // Creating the tombstone buffer does not cause allocations. + let tombstone_buffer = AudioBuffer { + channels: Default::default(), + sample_rate: Default::default(), + }; + self.buffer = Some(std::mem::replace(buffer, tombstone_buffer)); } return; };