Skip to content

Commit

Permalink
EncodedAudioStream config for buffer sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Dec 9, 2024
1 parent 17b6eca commit c62d71e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/AudioTools/AudioCodecs/AudioEncoded.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ class EncodedAudioStream : public ReformatBaseStream {

bool begin() {
//is_output_notify = false;
reader.setByteCountFactor(10);
setupReader();
ReformatBaseStream::begin();
return enc_out.begin(audioInfo());
Expand All @@ -372,7 +371,9 @@ class EncodedAudioStream : public ReformatBaseStream {
enc_out.addNotifyAudioChange(bi);
}

float getByteFactor() { return 1.0f; }
/// approx compression factor: e.g. mp3 is around 4
float getByteFactor() { return byte_factor; }
void setByteFactor(float factor) {byte_factor = factor;}

#if USE_AUDIO_LOGGING
/// Defines the class specific custom log level
Expand All @@ -384,6 +385,7 @@ class EncodedAudioStream : public ReformatBaseStream {

protected:
EncodedAudioOutput enc_out;
float byte_factor = 2.0f;

};

Expand Down
12 changes: 7 additions & 5 deletions src/AudioTools/CoreAudio/AudioIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class TransformationReader {
void resizeReadBuffer(int size) {
buffer.resize(size);
}

/// Defines the queue size for result
void resizeResultQueue(int size) {
result_queue_buffer.resize(size);
result_queue.begin();
}


size_t readBytes(uint8_t *data, size_t len) {
LOGD("TransformationReader::readBytes: %d", (int)len);
if (!active) {
Expand All @@ -74,7 +74,7 @@ class TransformationReader {

if (result_queue_buffer.size() == 0) {
// make sure that the ring buffer is big enough
int rb_size = len * byte_count_factor;
int rb_size = len * result_queue_factor;
LOGI("buffer size: %d", rb_size);
result_queue_buffer.resize(rb_size);
result_queue.begin();
Expand Down Expand Up @@ -117,7 +117,8 @@ class TransformationReader {
buffer.resize(0);
}

void setByteCountFactor(int f) { byte_count_factor = f; }
/// Defines the queue size dependent on the read size
void setResultQueueFactor(int factor) { result_queue_factor = factor; }

protected:
RingBuffer<uint8_t> result_queue_buffer{0};
Expand All @@ -126,7 +127,8 @@ class TransformationReader {
Vector<uint8_t> buffer{0}; // we allocate memory only when needed
T *p_transform = nullptr;
bool active = false;
int byte_count_factor = 3;
int result_queue_factor = 10;
int result_queue_size = 0;

/// Makes sure that the data is written to the array
/// @param data
Expand Down Expand Up @@ -203,7 +205,7 @@ class ReformatBaseStream : public ModifyingStream {
}

/// Provides access to the TransformationReader
TransformationReader<ReformatBaseStream> &getReader() {return reader;}
virtual TransformationReader<ReformatBaseStream> &transformationReader() {return reader;}

protected:
TransformationReader<ReformatBaseStream> reader;
Expand Down

0 comments on commit c62d71e

Please sign in to comment.