Skip to content

Commit e9bc34e

Browse files
committed
Use owned player in mono interactive player
1 parent 455dd83 commit e9bc34e

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

interactive/src/window.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::input::Input;
22
use anyhow::anyhow;
33
use caw_core::{SigSampleIntoBufT, Stereo};
4-
use caw_player::{ConfigSync, Player, ToF32};
4+
use caw_player::{
5+
ConfigOwned, ConfigSync, Player, ToF32, VisualizationDataPolicy,
6+
};
57
use line_2d::Coord;
68
pub use rgb_int::Rgb24;
79
use sdl2::{
@@ -316,36 +318,30 @@ impl Window {
316318
self.input.clone()
317319
}
318320

319-
pub fn play_mono<T, S>(
320-
&self,
321-
sig: S,
322-
config: ConfigSync,
323-
) -> anyhow::Result<()>
321+
pub fn play_mono<S>(&self, sig: S, config: ConfigSync) -> anyhow::Result<()>
324322
where
325-
T: ToF32 + Send + Sync + Copy + 'static,
326-
S: SigSampleIntoBufT<Item = T>,
323+
S: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static,
327324
{
328-
let player = Player::new()?;
325+
let config = ConfigOwned {
326+
system_latency_s: config.system_latency_s,
327+
visualization_data_policy: Some(VisualizationDataPolicy::All),
328+
};
329+
let player = Player::new()?.into_owned_mono(sig, config)?;
329330
let mut window_running = self.clone().run()?;
330331
// Render a few frames to warm up. The first few frames can take longer than usual to
331332
// render, so warming up prevents the audio from stuttering on startup.
332333
for _ in 0..WARMUP_FRAMES {
333334
window_running.handle_frame_if_enough_time_since_previous_frame();
334335
thread::sleep(FRAME_DURATION);
335336
}
336-
player.play_signal_sync_mono_callback(
337-
sig,
338-
|buf| {
339-
// Interleave rendering with sending samples to the sound card. Rendering needs to
340-
// happen on the main thread as this is a requirement of SDL, and sending samples to
341-
// the sound card needs to happen on the main thread as signals are not `Send`.
337+
loop {
338+
player.with_visualization_data_and_clear(|buf| {
342339
window_running.add_samples_to_oscilloscope_state(buf);
343340
window_running
344341
.handle_frame_if_enough_time_since_previous_frame();
345-
},
346-
config,
347-
)?;
348-
Ok(())
342+
});
343+
thread::sleep(FRAME_DURATION);
344+
}
349345
}
350346

351347
pub fn play_stereo<TL, TR, SL, SR>(

0 commit comments

Comments
 (0)