Skip to content

Commit eae1026

Browse files
committed
Do not overcomplicate live audio rendering with Cow
The object is copy-on-write already so there is not much to gain
1 parent 075276c commit eae1026

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/render/thread.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Communicates with the control thread and ships audio samples to the hardware
22
3-
use std::borrow::Cow;
43
use std::cell::Cell;
54
use std::sync::atomic::{AtomicU64, Ordering};
65
use std::sync::Arc;
@@ -258,14 +257,12 @@ impl RenderThread {
258257
node_id: Cell::new(AudioNodeId(0)), // placeholder value
259258
};
260259

261-
// render audio graph, and use a Cow in case we need to mutate/store the value later
262-
let mut rendered = Cow::Borrowed(self.graph.as_mut().unwrap().render(&scope));
260+
// render audio graph, clone it in case we need to mutate/store the value later
261+
let mut rendered = self.graph.as_mut().unwrap().render(&scope).clone();
263262

264263
// online AudioContext allows channel count to be less than no of hardware channels
265264
if rendered.number_of_channels() != self.number_of_channels {
266-
rendered
267-
.to_mut()
268-
.mix(self.number_of_channels, ChannelInterpretation::Discrete);
265+
rendered.mix(self.number_of_channels, ChannelInterpretation::Discrete);
269266
}
270267

271268
// copy rendered audio into output slice
@@ -282,7 +279,7 @@ impl RenderThread {
282279
// this is the last chunk, and it contained less than RENDER_QUANTUM_SIZE samples
283280
let channel_offset = data.len() / self.number_of_channels;
284281
debug_assert!(channel_offset < RENDER_QUANTUM_SIZE);
285-
self.buffer_offset = Some((channel_offset, rendered.into_owned()));
282+
self.buffer_offset = Some((channel_offset, rendered));
286283
}
287284

288285
// handle addition/removal of nodes/edges

0 commit comments

Comments
 (0)