Skip to content

Commit 99b0578

Browse files
Initialize buffers with zero-fill
vec! can make use of calloc to initialize buffer in a identically fast and safer way.
1 parent 08c8b79 commit 99b0578

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/audio_unit/render_callback.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,15 @@ impl AudioUnit {
484484
// First, get the current buffer size for pre-allocating the `AudioBuffer`s.
485485
let id = sys::kAudioDevicePropertyBufferFrameSize;
486486
let mut buffer_frame_size: u32 = self.get_property(id, Scope::Global, Element::Output)?;
487-
let mut data: Vec<u8> = vec![];
488487
let sample_bytes = stream_format.sample_format.size_in_bytes();
489488
let n_channels = stream_format.channels_per_frame;
490489
let data_byte_size = buffer_frame_size * sample_bytes as u32 * n_channels;
491-
data.reserve_exact(data_byte_size as usize);
490+
let data = vec![0u8; data_byte_size as usize];
492491
let audio_buffer = sys::AudioBuffer {
493492
mDataByteSize: data_byte_size,
494493
mNumberChannels: n_channels,
495494
mData: data.as_mut_ptr() as *mut _,
496495
};
497-
unsafe {
498-
data.set_len(data_byte_size as usize);
499-
}
500496
// Relieve ownership of the `Vec` until we're ready to drop the `AudioBufferList`.
501497
mem::forget(data);
502498
let audio_buffer_list = Box::new(sys::AudioBufferList {

0 commit comments

Comments
 (0)