@@ -1174,11 +1174,7 @@ class InputMixer : public AudioStream {
1174
1174
void setWeight (int channel, int weight) {
1175
1175
if (channel < size ()) {
1176
1176
weights[channel] = weight;
1177
- int total = 0 ;
1178
- for (int j = 0 ; j < weights.size (); j++) {
1179
- total += weights[j];
1180
- }
1181
- total_weights = total;
1177
+ recalculateWeights ();
1182
1178
} else {
1183
1179
LOGE (" Invalid channel %d - max is %d" , channel, size () - 1 );
1184
1180
}
@@ -1233,14 +1229,30 @@ class InputMixer : public AudioStream {
1233
1229
return false ;
1234
1230
}
1235
1231
streams.erase (idx);
1232
+ weights.erase (idx);
1233
+ recalculateWeights ();
1236
1234
return true ;
1237
1235
}
1238
1236
1237
+ // / Removes all streams which have no data available
1238
+ bool remove () {
1239
+ bool rc = false ;
1240
+ int idx = nextEmptyIndex ();
1241
+ while (idx >= 0 ) {
1242
+ rc = true ;
1243
+ streams.erase (idx);
1244
+ weights.erase (idx);
1245
+ idx = nextEmptyIndex ();
1246
+ }
1247
+ recalculateWeights ();
1248
+ return rc;
1249
+ }
1250
+
1239
1251
// / Provides the actual index of the stream
1240
1252
int indexOf (Stream &stream) { return streams.indexOf (&stream); }
1241
1253
1242
1254
// / Provides the stream pointer at the indicated index
1243
- Stream * operator [](int idx) {
1255
+ Stream *operator [](int idx) {
1244
1256
if (idx < 0 || idx >= size ()) return nullptr ;
1245
1257
return streams[idx];
1246
1258
}
@@ -1265,6 +1277,15 @@ class InputMixer : public AudioStream {
1265
1277
Vector<int > result_vect;
1266
1278
Vector<T> current_vect;
1267
1279
1280
+ // / Recalculate the weights
1281
+ void recalculateWeights () {
1282
+ int total = 0 ;
1283
+ for (int j = 0 ; j < weights.size (); j++) {
1284
+ total += weights[j];
1285
+ }
1286
+ total_weights = total;
1287
+ }
1288
+
1268
1289
// / mixing using a vector of samples
1269
1290
int readBytesVector (T *p_data, int byteCount) {
1270
1291
int samples = byteCount / sizeof (T);
@@ -1475,8 +1496,8 @@ class CallbackStream : public ModifyingStream {
1475
1496
// / defines the callback to receive the actual audio info
1476
1497
void setAudioInfoCallback (void (*cb)(AudioInfo info)) {
1477
1498
this ->cb_audio_info = cb;
1478
- }
1479
-
1499
+ }
1500
+
1480
1501
// / Updates the audio info and calls the callback
1481
1502
void setAudioInfo (AudioInfo info) override {
1482
1503
ModifyingStream::setAudioInfo (info);
@@ -1714,9 +1735,9 @@ class VolumeMeter : public ModifyingStream {
1714
1735
return begin ();
1715
1736
}
1716
1737
1717
- bool begin () override {
1738
+ bool begin () override {
1718
1739
setAudioInfo (audioInfo ());
1719
- return true ;
1740
+ return true ;
1720
1741
}
1721
1742
1722
1743
void setAudioInfo (AudioInfo info) override {
0 commit comments