@@ -170,6 +170,8 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
170170 if (is_started){
171171 VolumeStreamConfig cfg1 = setupAudioInfo (cfg);
172172 setupVolumeStreamConfig (cfg1);
173+ // trigger resize of vectors
174+ setVolume (info.volume );
173175 } else {
174176 begin (cfg);
175177 }
@@ -249,7 +251,6 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
249251 #endif
250252 bool is_started = false ;
251253 float max_value = 32767 ; // max value for clipping
252- int max_channels = 0 ;
253254
254255 // checks if volume needs to be updated
255256 bool isVolumeUpdate (){
@@ -259,7 +260,8 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
259260 }
260261
261262 bool isAllChannelsFullVolume (){
262- for (int ch=0 ;ch<info.channels ;ch++){
263+ int channels = MIN (info.channels , volume_values.size ());
264+ for (int ch=0 ;ch < channels;ch++){
263265 if (volume_values[ch]!=1.0 ) return false ;
264266 }
265267 return true ;
@@ -287,9 +289,6 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
287289 void setupVolumeStreamConfig (VolumeStreamConfig cfg){
288290 info = cfg;
289291 max_value = NumberConverter::maxValue (info.bits_per_sample );
290- if (info.channels >max_channels){
291- max_channels = info.channels ;
292- }
293292 }
294293
295294 float volumeValue (float vol){
@@ -311,7 +310,9 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
311310 #else
312311 float factorForChannel (int channel){
313312 #endif
314- return factor_for_channel.size ()==0 ? 1.0 : factor_for_channel[channel];
313+ if (factor_for_channel.size ()==0 ) return 1.0 ;
314+ if (channel >= factor_for_channel.size ()) return 1.0 ;
315+ return factor_for_channel[channel];
315316 }
316317
317318 void applyVolume (const uint8_t *buffer, size_t size){
0 commit comments