Skip to content

Commit

Permalink
AudioBuffer: Revert derive of Default
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Jul 18, 2023
1 parent d1a86ce commit 78d4551
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelData>,
sample_rate: f32,
pub(crate) channels: Vec<ChannelData>,
pub(crate) sample_rate: f32,
}

impl AudioBuffer {
Expand Down
8 changes: 6 additions & 2 deletions src/node/audio_buffer_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 78d4551

Please sign in to comment.