@@ -21,6 +21,8 @@ struct AppState {
2121 monitor_running : Arc < AtomicBool > ,
2222 monitor_cancel : Arc < AtomicBool > ,
2323 monitor_peak_reset : Arc < AtomicBool > ,
24+ pink_noise_running : Arc < AtomicBool > ,
25+ pink_noise_cancel : Arc < AtomicBool > ,
2426}
2527
2628#[ derive( Debug , Serialize ) ]
@@ -58,6 +60,7 @@ async fn run_latency_test(
5860 request : LatencyTestRequest ,
5961) -> Result < LatencyTestReport , String > {
6062 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
63+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
6164
6265 if state. running . swap ( true , Ordering :: SeqCst ) {
6366 return Err ( "A latency test is already running." . to_string ( ) ) ;
@@ -102,6 +105,7 @@ async fn run_sweep_fr_test(
102105 request : SweepFrRequest ,
103106) -> Result < TestResultPayload , String > {
104107 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
108+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
105109
106110 if state. running . swap ( true , Ordering :: SeqCst ) {
107111 return Err ( "A test is already running." . to_string ( ) ) ;
@@ -178,13 +182,60 @@ fn reset_input_monitor_peak(state: State<'_, AppState>) {
178182 state. monitor_peak_reset . store ( true , Ordering :: SeqCst ) ;
179183}
180184
185+ #[ tauri:: command]
186+ async fn start_pink_noise (
187+ app : tauri:: AppHandle ,
188+ state : State < ' _ , AppState > ,
189+ ) -> Result < ( ) , String > {
190+ if state. running . load ( Ordering :: SeqCst ) {
191+ return Err ( "Cannot start pink noise while a test is running." . to_string ( ) ) ;
192+ }
193+ if state. pink_noise_running . swap ( true , Ordering :: SeqCst ) {
194+ return Ok ( ( ) ) ;
195+ }
196+
197+ state. pink_noise_cancel . store ( false , Ordering :: SeqCst ) ;
198+
199+ let settings = {
200+ let engine = state. audio . lock ( ) . await ;
201+ engine. settings ( )
202+ } ;
203+ let cancel = state. pink_noise_cancel . clone ( ) ;
204+ let running_flag = state. pink_noise_running . clone ( ) ;
205+ let app_handle = app. clone ( ) ;
206+
207+ tauri:: async_runtime:: spawn_blocking ( move || {
208+ if let Err ( error) = AudioEngine :: run_pink_noise ( settings, cancel) {
209+ let _ = app_handle. emit (
210+ "test-progress" ,
211+ TestProgressEvent {
212+ test : "pink_noise" . to_string ( ) ,
213+ current : 0 ,
214+ total : 0 ,
215+ value : None ,
216+ message : format ! ( "pink noise error: {error}" ) ,
217+ } ,
218+ ) ;
219+ }
220+ running_flag. store ( false , Ordering :: SeqCst ) ;
221+ } ) ;
222+
223+ Ok ( ( ) )
224+ }
225+
226+ #[ tauri:: command]
227+ fn stop_pink_noise ( state : State < ' _ , AppState > ) {
228+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
229+ }
230+
181231#[ tauri:: command]
182232async fn run_thd_test (
183233 app : tauri:: AppHandle ,
184234 state : State < ' _ , AppState > ,
185235 request : ThdRequest ,
186236) -> Result < TestResultPayload , String > {
187237 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
238+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
188239
189240 if state. running . swap ( true , Ordering :: SeqCst ) {
190241 return Err ( "A test is already running." . to_string ( ) ) ;
@@ -217,6 +268,7 @@ async fn run_balance_test(
217268 request : BalanceRequest ,
218269) -> Result < TestResultPayload , String > {
219270 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
271+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
220272
221273 if state. running . swap ( true , Ordering :: SeqCst ) {
222274 return Err ( "A test is already running." . to_string ( ) ) ;
@@ -248,6 +300,7 @@ async fn run_crosstalk_test(
248300 request : CrosstalkRequest ,
249301) -> Result < TestResultPayload , String > {
250302 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
303+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
251304
252305 if state. running . swap ( true , Ordering :: SeqCst ) {
253306 return Err ( "A test is already running." . to_string ( ) ) ;
@@ -279,6 +332,7 @@ async fn run_isolation_test(
279332 request : IsolationRequest ,
280333) -> Result < TestResultPayload , String > {
281334 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
335+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
282336
283337 if state. running . swap ( true , Ordering :: SeqCst ) {
284338 return Err ( "A test is already running." . to_string ( ) ) ;
@@ -308,6 +362,7 @@ async fn run_isolation_test(
308362fn stop_test ( state : State < ' _ , AppState > ) {
309363 state. cancel . store ( true , Ordering :: SeqCst ) ;
310364 state. monitor_cancel . store ( true , Ordering :: SeqCst ) ;
365+ state. pink_noise_cancel . store ( true , Ordering :: SeqCst ) ;
311366}
312367
313368#[ tauri:: command]
@@ -330,6 +385,8 @@ fn main() {
330385 monitor_running : Arc :: new ( AtomicBool :: new ( false ) ) ,
331386 monitor_cancel : Arc :: new ( AtomicBool :: new ( false ) ) ,
332387 monitor_peak_reset : Arc :: new ( AtomicBool :: new ( false ) ) ,
388+ pink_noise_running : Arc :: new ( AtomicBool :: new ( false ) ) ,
389+ pink_noise_cancel : Arc :: new ( AtomicBool :: new ( false ) ) ,
333390 } ;
334391
335392 tauri:: Builder :: default ( )
@@ -344,6 +401,8 @@ fn main() {
344401 start_input_monitor,
345402 stop_input_monitor,
346403 reset_input_monitor_peak,
404+ start_pink_noise,
405+ stop_pink_noise,
347406 run_thd_test,
348407 run_balance_test,
349408 run_crosstalk_test,
0 commit comments