|
1 | 1 | use crate::input::Input; |
2 | 2 | use anyhow::anyhow; |
3 | 3 | use caw_core::{SigSampleIntoBufT, Stereo}; |
4 | | -use caw_player::{ConfigSync, Player, ToF32}; |
| 4 | +use caw_player::{ |
| 5 | + ConfigOwned, ConfigSync, Player, ToF32, VisualizationDataPolicy, |
| 6 | +}; |
5 | 7 | use line_2d::Coord; |
6 | 8 | pub use rgb_int::Rgb24; |
7 | 9 | use sdl2::{ |
@@ -316,36 +318,30 @@ impl Window { |
316 | 318 | self.input.clone() |
317 | 319 | } |
318 | 320 |
|
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<()> |
324 | 322 | where |
325 | | - T: ToF32 + Send + Sync + Copy + 'static, |
326 | | - S: SigSampleIntoBufT<Item = T>, |
| 323 | + S: SigSampleIntoBufT<Item = f32> + Send + Sync + 'static, |
327 | 324 | { |
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)?; |
329 | 330 | let mut window_running = self.clone().run()?; |
330 | 331 | // Render a few frames to warm up. The first few frames can take longer than usual to |
331 | 332 | // render, so warming up prevents the audio from stuttering on startup. |
332 | 333 | for _ in 0..WARMUP_FRAMES { |
333 | 334 | window_running.handle_frame_if_enough_time_since_previous_frame(); |
334 | 335 | thread::sleep(FRAME_DURATION); |
335 | 336 | } |
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| { |
342 | 339 | window_running.add_samples_to_oscilloscope_state(buf); |
343 | 340 | window_running |
344 | 341 | .handle_frame_if_enough_time_since_previous_frame(); |
345 | | - }, |
346 | | - config, |
347 | | - )?; |
348 | | - Ok(()) |
| 342 | + }); |
| 343 | + thread::sleep(FRAME_DURATION); |
| 344 | + } |
349 | 345 | } |
350 | 346 |
|
351 | 347 | pub fn play_stereo<TL, TR, SL, SR>( |
|
0 commit comments