@@ -2,8 +2,9 @@ use caw_core::{Sig, SigBoxedVar, Stereo, StereoPair, svf32};
22use caw_player:: {
33 PlayerConfig , PlayerVisualizationData , VisualizationDataPolicy , play_stereo,
44} ;
5+ use caw_viz_udp_app_lib:: { VizAppConfig , VizUdpServer } ;
56use lazy_static:: lazy_static;
6- use std:: sync:: Mutex ;
7+ use std:: { sync:: Mutex , thread , time :: Duration } ;
78
89lazy_static ! {
910 static ref OUT : StereoPair <Sig <SigBoxedVar <f32 >>> =
@@ -13,9 +14,11 @@ lazy_static! {
1314 static ref INITIALIZED : Mutex <bool > = Mutex :: new( false ) ;
1415}
1516
16- pub fn live_stereo_visualized (
17+ pub type LiveStereoOut = StereoPair < Sig < SigBoxedVar < f32 > > > ;
18+
19+ pub fn live_stereo_viz (
1720 visualization_data_policy : VisualizationDataPolicy ,
18- ) -> ( StereoPair < Sig < SigBoxedVar < f32 > > > , PlayerVisualizationData ) {
21+ ) -> ( LiveStereoOut , PlayerVisualizationData ) {
1922 let mut initialized = INITIALIZED . lock ( ) . unwrap ( ) ;
2023 if * initialized {
2124 return ( OUT . clone ( ) , VISUALIZATION_DATA . lock ( ) . unwrap ( ) . clone ( ) ) ;
@@ -35,7 +38,20 @@ pub fn live_stereo_visualized(
3538 ( OUT . clone ( ) , visualization_data_ref. clone ( ) )
3639}
3740
38- pub fn live_stereo ( ) -> StereoPair < Sig < SigBoxedVar < f32 > > > {
41+ pub fn live_stereo_viz_udp ( config : VizAppConfig ) -> LiveStereoOut {
42+ let ( out, viz_data) = live_stereo_viz ( VisualizationDataPolicy :: All ) ;
43+ let mut viz = VizUdpServer :: new ( config) . unwrap ( ) ;
44+ thread:: spawn ( move || {
45+ loop {
46+ // TODO: Is it ok to ignore errors here?
47+ let _ = viz_data. with_and_clear ( |buf| viz. send_samples ( buf) ) ;
48+ thread:: sleep ( Duration :: from_millis ( 16 ) ) ;
49+ }
50+ } ) ;
51+ out
52+ }
53+
54+ pub fn live_stereo ( ) -> LiveStereoOut {
3955 let mut initialized = INITIALIZED . lock ( ) . unwrap ( ) ;
4056 if * initialized {
4157 return OUT . clone ( ) ;
0 commit comments