@@ -67,13 +67,17 @@ impl Default for EngineConfig {
6767 }
6868}
6969
70- /// Real-time audio levels
70+ /// Real-time audio levels (stereo)
7171#[ derive( Debug , Clone , Default ) ]
7272pub struct AudioLevels {
73- pub input_level : f32 ,
74- pub output_level : f32 ,
75- pub input_peak : f32 ,
76- pub output_peak : f32 ,
73+ pub input_level_l : f32 ,
74+ pub input_level_r : f32 ,
75+ pub output_level_l : f32 ,
76+ pub output_level_r : f32 ,
77+ pub input_peak_l : f32 ,
78+ pub input_peak_r : f32 ,
79+ pub output_peak_l : f32 ,
80+ pub output_peak_r : f32 ,
7781 pub remote_levels : Vec < ( String , f32 ) > ,
7882 pub backing_level : f32 ,
7983}
@@ -944,14 +948,17 @@ impl AudioEngine {
944948 stereo_buffer. push ( right_sample) ;
945949 }
946950
947- // Calculate input level
948- let level = stereo_buffer
949- . iter ( )
950- . map ( |s| s. abs ( ) )
951- . fold ( 0.0_f32 , f32:: max) ;
951+ // Calculate input levels (stereo) - interleaved L/R samples
952+ let ( level_l, level_r) = stereo_buffer
953+ . chunks_exact ( 2 )
954+ . fold ( ( 0.0_f32 , 0.0_f32 ) , |( max_l, max_r) , chunk| {
955+ ( max_l. max ( chunk[ 0 ] . abs ( ) ) , max_r. max ( chunk[ 1 ] . abs ( ) ) )
956+ } ) ;
952957 if let Ok ( mut lvl) = levels. try_write ( ) {
953- lvl. input_level = level;
954- lvl. input_peak = lvl. input_peak . max ( level) ;
958+ lvl. input_level_l = level_l;
959+ lvl. input_level_r = level_r;
960+ lvl. input_peak_l = lvl. input_peak_l . max ( level_l) ;
961+ lvl. input_peak_r = lvl. input_peak_r . max ( level_r) ;
955962 }
956963
957964 // Stream audio to browser (browser applies effects via Web Audio)
@@ -1084,11 +1091,17 @@ impl AudioEngine {
10841091 * sample = sample. tanh ( ) ;
10851092 }
10861093
1087- // Update output level for metering
1088- let level = data. iter ( ) . map ( |s| s. abs ( ) ) . fold ( 0.0_f32 , f32:: max) ;
1094+ // Update output levels for metering (stereo) - interleaved L/R samples
1095+ let ( level_l, level_r) = data
1096+ . chunks_exact ( 2 )
1097+ . fold ( ( 0.0_f32 , 0.0_f32 ) , |( max_l, max_r) , chunk| {
1098+ ( max_l. max ( chunk[ 0 ] . abs ( ) ) , max_r. max ( chunk[ 1 ] . abs ( ) ) )
1099+ } ) ;
10891100 if let Ok ( mut lvl) = levels. try_write ( ) {
1090- lvl. output_level = level;
1091- lvl. output_peak = lvl. output_peak . max ( level) ;
1101+ lvl. output_level_l = level_l;
1102+ lvl. output_level_r = level_r;
1103+ lvl. output_peak_l = lvl. output_peak_l . max ( level_l) ;
1104+ lvl. output_peak_r = lvl. output_peak_r . max ( level_r) ;
10921105 lvl. backing_level = backing_level;
10931106 }
10941107 }
0 commit comments