@@ -15,7 +15,10 @@ impl AudioStream {
1515 /// This function converts an audio stream from packet into producer
1616 /// apply any necessary conversions based on the audio format
1717 /// and returns mono channel f32 vector for audio wave display
18- pub fn process_audio_packet ( & mut self , packet : AudioPacketMessage ) -> anyhow:: Result < Vec < f32 > > {
18+ pub fn process_audio_packet (
19+ & mut self ,
20+ packet : AudioPacketMessage ,
21+ ) -> anyhow:: Result < Option < Vec < f32 > > > {
1922 match self . audio_params . target_format . audio_format {
2023 AudioFormat :: I16 => self . process_audio_packet_internal :: < i16 > ( packet) ,
2124 AudioFormat :: I24 => self . process_audio_packet_internal :: < f32 > ( packet) ,
@@ -32,7 +35,7 @@ impl AudioStream {
3235 fn process_audio_packet_internal < F > (
3336 & mut self ,
3437 packet : AudioPacketMessage ,
35- ) -> anyhow:: Result < Vec < f32 > >
38+ ) -> anyhow:: Result < Option < Vec < f32 > > >
3639 where
3740 F : cpal:: SizedSample + AudioBytes + std:: fmt:: Debug + ' static ,
3841 {
@@ -130,18 +133,22 @@ impl AudioStream {
130133 }
131134 }
132135
133- // prepare mono channel buffer to return
134- let buffer_mono = if config. target_format . channel_count . to_number ( ) == 1 {
135- buffer[ 0 ] . clone ( )
136- } else {
137- // if not mono, average the channels
138- let mut mono_buffer: Vec < f32 > = Vec :: with_capacity ( buffer[ 0 ] . len ( ) ) ;
139- for i in 0 ..buffer[ 0 ] . len ( ) {
140- let sample: f32 = buffer. iter ( ) . map ( |ch| ch[ i] ) . sum :: < f32 > ( )
141- / config. target_format . channel_count . to_number ( ) as f32 ;
142- mono_buffer. push ( sample) ;
136+ let buffer_mono = if self . is_window_visible {
137+ // prepare mono channel buffer to return
138+ if config. target_format . channel_count . to_number ( ) == 1 {
139+ Some ( buffer[ 0 ] . clone ( ) )
140+ } else {
141+ // if not mono, average the channels
142+ let mut mono_buffer: Vec < f32 > = Vec :: with_capacity ( buffer[ 0 ] . len ( ) ) ;
143+ for i in 0 ..buffer[ 0 ] . len ( ) {
144+ let sample: f32 = buffer. iter ( ) . map ( |ch| ch[ i] ) . sum :: < f32 > ( )
145+ / config. target_format . channel_count . to_number ( ) as f32 ;
146+ mono_buffer. push ( sample) ;
147+ }
148+ Some ( mono_buffer)
143149 }
144- mono_buffer
150+ } else {
151+ None
145152 } ;
146153
147154 Ok ( buffer_mono)
0 commit comments