@@ -170,6 +170,8 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
170
170
if (is_started){
171
171
VolumeStreamConfig cfg1 = setupAudioInfo (cfg);
172
172
setupVolumeStreamConfig (cfg1);
173
+ // trigger resize of vectors
174
+ setVolume (info.volume );
173
175
} else {
174
176
begin (cfg);
175
177
}
@@ -249,7 +251,6 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
249
251
#endif
250
252
bool is_started = false ;
251
253
float max_value = 32767 ; // max value for clipping
252
- int max_channels = 0 ;
253
254
254
255
// checks if volume needs to be updated
255
256
bool isVolumeUpdate (){
@@ -259,7 +260,8 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
259
260
}
260
261
261
262
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++){
263
265
if (volume_values[ch]!=1.0 ) return false ;
264
266
}
265
267
return true ;
@@ -287,9 +289,6 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
287
289
void setupVolumeStreamConfig (VolumeStreamConfig cfg){
288
290
info = cfg;
289
291
max_value = NumberConverter::maxValue (info.bits_per_sample );
290
- if (info.channels >max_channels){
291
- max_channels = info.channels ;
292
- }
293
292
}
294
293
295
294
float volumeValue (float vol){
@@ -311,7 +310,9 @@ class VolumeStream : public ModifyingStream, public VolumeSupport {
311
310
#else
312
311
float factorForChannel (int channel){
313
312
#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];
315
316
}
316
317
317
318
void applyVolume (const uint8_t *buffer, size_t size){
0 commit comments