Skip to content

Commit 8913df8

Browse files
committed
InputMixer: new methods remove() & indexOf()
1 parent 08fb568 commit 8913df8

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/AudioTools/CoreAudio/AudioStreams.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,19 +1142,22 @@ class InputMixer : public AudioStream {
11421142
public:
11431143
InputMixer() = default;
11441144

1145-
/// Adds a new input stream
1146-
void add(Stream &in, int weight = 100) {
1145+
/// Adds a new input stream and returns it's actual index position
1146+
int add(Stream &in, int weight = 100) {
11471147
streams.push_back(&in);
11481148
weights.push_back(weight);
11491149
total_weights += weight;
1150+
return streams.indexOf(&in);
11501151
}
11511152

1152-
/// Replaces a stream at the indicated channel
1153-
void set(int channel, Stream &in) {
1153+
/// Replaces a stream at the indicated index
1154+
bool set(int index, Stream &in) {
11541155
if (channel < size()) {
1155-
streams[channel] = &in;
1156+
streams[index] = &in;
1157+
return true;
11561158
} else {
11571159
LOGE("Invalid channel %d - max is %d", channel, size() - 1);
1160+
return false;
11581161
}
11591162
}
11601163

@@ -1224,6 +1227,20 @@ class InputMixer : public AudioStream {
12241227
/// abort the read and provide empty data
12251228
void setRetryCount(int retry) { retry_count = retry; }
12261229

1230+
/// Removes a stream by index position
1231+
bool remove(int idx){
1232+
if (idx < 0 || idx >= size()) {
1233+
return false;
1234+
}
1235+
streams.erase(idx);
1236+
return true;
1237+
}
1238+
1239+
/// Provides the actual index of the stream
1240+
int indexOf(Stream& stream){
1241+
return streams.indexOf(&stream);
1242+
}
1243+
12271244
protected:
12281245
Vector<Stream *> streams{0};
12291246
Vector<int> weights{0};

0 commit comments

Comments
 (0)