Skip to content

Commit fad6c2a

Browse files
committed
InputMixer
1 parent f44e898 commit fad6c2a

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/AudioTools/CoreAudio/AudioStreams.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,11 +1174,7 @@ class InputMixer : public AudioStream {
11741174
void setWeight(int channel, int weight) {
11751175
if (channel < size()) {
11761176
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();
11821178
} else {
11831179
LOGE("Invalid channel %d - max is %d", channel, size() - 1);
11841180
}
@@ -1233,14 +1229,30 @@ class InputMixer : public AudioStream {
12331229
return false;
12341230
}
12351231
streams.erase(idx);
1232+
weights.erase(idx);
1233+
recalculateWeights();
12361234
return true;
12371235
}
12381236

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+
12391251
/// Provides the actual index of the stream
12401252
int indexOf(Stream &stream) { return streams.indexOf(&stream); }
12411253

12421254
/// Provides the stream pointer at the indicated index
1243-
Stream * operator [](int idx) {
1255+
Stream *operator[](int idx) {
12441256
if (idx < 0 || idx >= size()) return nullptr;
12451257
return streams[idx];
12461258
}
@@ -1265,6 +1277,15 @@ class InputMixer : public AudioStream {
12651277
Vector<int> result_vect;
12661278
Vector<T> current_vect;
12671279

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+
12681289
/// mixing using a vector of samples
12691290
int readBytesVector(T *p_data, int byteCount) {
12701291
int samples = byteCount / sizeof(T);
@@ -1475,8 +1496,8 @@ class CallbackStream : public ModifyingStream {
14751496
/// defines the callback to receive the actual audio info
14761497
void setAudioInfoCallback(void (*cb)(AudioInfo info)) {
14771498
this->cb_audio_info = cb;
1478-
}
1479-
1499+
}
1500+
14801501
/// Updates the audio info and calls the callback
14811502
void setAudioInfo(AudioInfo info) override {
14821503
ModifyingStream::setAudioInfo(info);
@@ -1714,9 +1735,9 @@ class VolumeMeter : public ModifyingStream {
17141735
return begin();
17151736
}
17161737

1717-
bool begin() override {
1738+
bool begin() override {
17181739
setAudioInfo(audioInfo());
1719-
return true;
1740+
return true;
17201741
}
17211742

17221743
void setAudioInfo(AudioInfo info) override {

0 commit comments

Comments
 (0)