Update atomic variable once per buffer, not once per frame

This commit is contained in:
Rob Watson 2020-09-10 18:48:14 +02:00
parent 2d458651e6
commit 05f0144419
1 changed files with 5 additions and 2 deletions

View File

@ -115,13 +115,16 @@ impl Player {
.build_output_stream(
config,
move |output: &mut [T], _| {
let frames = output.chunks_mut(num_channels);
let mut idx = idx.fetch_add(frames.len(), Ordering::Relaxed);
for frame in output.chunks_mut(num_channels) {
let i = idx.fetch_add(1, Ordering::Relaxed);
for (j, sample) in frame.iter_mut().enumerate() {
let buffer = &audio_data.buffers[j];
let value: T = Sample::from::<f32>(&buffer[i]);
let value: T = Sample::from::<f32>(&buffer[idx]);
*sample = value;
}
idx += 1;
}
},
err_fn,