From 921684cb3bb7aaf335ad8907b609e2a9f0bc6adf Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 15 Sep 2023 11:45:03 +0200 Subject: [PATCH] InputMixer setLimitToAvailableData() --- src/AudioTools/AudioStreams.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/AudioTools/AudioStreams.h b/src/AudioTools/AudioStreams.h index 8d319a304f..1ccf40c2df 100644 --- a/src/AudioTools/AudioStreams.h +++ b/src/AudioTools/AudioStreams.h @@ -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)); @@ -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 streams{10}; Vector weights{10}; int total_weights = 0; int frame_size = 4; + bool limit_available_data = false;; Vector result_vect; Vector current_vect; @@ -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;javailable()); + } + return result; + } + void resultAdd(float fact){ for (int j=0;j