Skip to content

Commit

Permalink
InputMixer setLimitToAvailableData()
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Sep 16, 2023
1 parent 40dcba6 commit 921684c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/AudioTools/AudioStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,12 @@ class InputMixer : public AudioStream {
LOGW("readBytes: %d",(int)len);
return 0;
}

if (limit_available_data){
len = min(len, availableBytes());
}

// result_len must be full frames

int result_len = len * frame_size / frame_size;
// replace sample based with vector based implementation
//readBytesSamples((T*)data, result_len));
Expand All @@ -1354,11 +1358,17 @@ class InputMixer : public AudioStream {
// return result;
// }

/// Do not wait for all data to be available
void setLimitToAvailableData(bool flag){
limit_available_data = flag;
}

protected:
Vector<Stream*> streams{10};
Vector<int> weights{10};
int total_weights = 0;
int frame_size = 4;
bool limit_available_data = false;;

Vector<int> result_vect;
Vector<T> current_vect;
Expand All @@ -1383,6 +1393,15 @@ class InputMixer : public AudioStream {
}
}

/// Provides the available bytes from the first stream with data
int availableBytes() {
int result = DEFAULT_BUFFER_SIZE;
for (int j=0;j<size();j++){
result = min(result, streams[j]->available());
}
return result;
}

void resultAdd(float fact){
for (int j=0;j<current_vect.size();j++){
current_vect[j]*=fact;
Expand Down

0 comments on commit 921684c

Please sign in to comment.