From 740b2a6cc7387a0bffdbd266d9ddf08466716a73 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Tue, 5 Nov 2024 18:16:44 +0100 Subject: [PATCH] Converters use standard notification --- src/AudioTools/AudioCodecs/AudioEncoded.h | 4 +-- src/AudioTools/CoreAudio/AudioIO.h | 33 ++++++++++--------- .../CoreAudio/AudioStreamsConverter.h | 18 +++++----- src/AudioTools/CoreAudio/AudioTypes.h | 24 -------------- src/AudioTools/CoreAudio/ResampleStream.h | 4 +-- 5 files changed, 30 insertions(+), 53 deletions(-) diff --git a/src/AudioTools/AudioCodecs/AudioEncoded.h b/src/AudioTools/AudioCodecs/AudioEncoded.h index a05d2a734..7fb00a3a2 100644 --- a/src/AudioTools/AudioCodecs/AudioEncoded.h +++ b/src/AudioTools/AudioCodecs/AudioEncoded.h @@ -345,7 +345,7 @@ class EncodedAudioStream : public ReformatBaseStream { } bool begin() { - is_output_notify = false; + //is_output_notify = false; reader.setByteCountFactor(10); setupReader(); ReformatBaseStream::begin(); @@ -360,7 +360,7 @@ class EncodedAudioStream : public ReformatBaseStream { int availableForWrite() { return enc_out.availableForWrite(); } size_t write(const uint8_t *data, size_t len) { - addNotifyOnFirstWrite(); + //addNotifyOnFirstWrite(); return enc_out.write(data, len); } diff --git a/src/AudioTools/CoreAudio/AudioIO.h b/src/AudioTools/CoreAudio/AudioIO.h index cf1c94e56..4ecec95ad 100644 --- a/src/AudioTools/CoreAudio/AudioIO.h +++ b/src/AudioTools/CoreAudio/AudioIO.h @@ -151,13 +151,14 @@ class ReformatBaseStream : public ModifyingStream { TRACED(); p_stream = &stream; p_print = &stream; - setNotifyOnOutput(stream); + //setNotifyOnOutput(stream); + addNotifyAudioChange(stream); } virtual void setOutput(AudioOutput &print) { TRACED(); p_print = &print; - setNotifyOnOutput(print); + addNotifyAudioChange(print); } virtual void setOutput(Print &print) override { @@ -194,20 +195,20 @@ class ReformatBaseStream : public ModifyingStream { TransformationReader reader; Stream *p_stream = nullptr; Print *p_print = nullptr; - bool is_output_notify = false; - AudioInfoSupport *p_notify_on_output = nullptr; - - /// Define potential notification - void setNotifyOnOutput(AudioInfoSupport &info) { p_notify_on_output = &info; } - - /// Add notification on first call of write - void addNotifyOnFirstWrite() { - if (!is_output_notify) { - if (p_notify_on_output != nullptr) - addNotifyAudioChange(*p_notify_on_output); - is_output_notify = true; - } - } +// bool is_output_notify = false; +// AudioInfoSupport *p_notify_on_output = nullptr; + + // /// Define potential notification + // void setNotifyOnOutput(AudioInfoSupport &info) { p_notify_on_output = &info; } + + // /// Add notification on first call of write + // void addNotifyOnFirstWrite() { + // if (!is_output_notify) { + // if (p_notify_on_output != nullptr) + // addNotifyAudioChange(*p_notify_on_output); + // is_output_notify = true; + // } + // } void setupReader() { if (getStream() != nullptr) { diff --git a/src/AudioTools/CoreAudio/AudioStreamsConverter.h b/src/AudioTools/CoreAudio/AudioStreamsConverter.h index 7182a898a..7c3ddc75e 100644 --- a/src/AudioTools/CoreAudio/AudioStreamsConverter.h +++ b/src/AudioTools/CoreAudio/AudioStreamsConverter.h @@ -22,7 +22,7 @@ class ChannelFormatConverterStreamT : public ReformatBaseStream { bool begin(int fromChannels, int toChannels) { LOGI("begin %d -> %d channels", fromChannels, toChannels); - is_output_notify = false; + //is_output_notify = false; from_channels = fromChannels; to_channels = toChannels; factor = static_cast(toChannels) / static_cast(fromChannels); @@ -40,7 +40,7 @@ class ChannelFormatConverterStreamT : public ReformatBaseStream { virtual size_t write(const uint8_t *data, size_t len) override { TRACED(); if (p_print == nullptr) return 0; - addNotifyOnFirstWrite(); + //addNotifyOnFirstWrite(); if (from_channels == to_channels) { return p_print->write(data, len); } @@ -169,7 +169,7 @@ class ChannelFormatConverterStream : public ReformatBaseStream { bool begin(AudioInfo cfg, int toChannels) { assert(toChannels != 0); - is_output_notify = false; + //is_output_notify = false; to_channels = toChannels; from_channels = cfg.channels; bits_per_sample = cfg.bits_per_sample; @@ -190,7 +190,7 @@ class ChannelFormatConverterStream : public ReformatBaseStream { virtual size_t write(const uint8_t *data, size_t len) override { LOGD("ChannelFormatConverterStream::write: %d", (int)len); if (p_print == nullptr) return 0; - addNotifyOnFirstWrite(); + //addNotifyOnFirstWrite(); switch (bits_per_sample) { case 8: return getConverter()->write(data, len); @@ -354,14 +354,14 @@ class NumberFormatConverterStreamT : public ReformatBaseStream { bool begin() override { LOGI("begin %d -> %d bits", (int)sizeof(TFrom), (int)sizeof(TTo)); - is_output_notify = false; + //is_output_notify = false; return true; } virtual size_t write(const uint8_t *data, size_t len) override { TRACED(); if (p_print == nullptr) return 0; - addNotifyOnFirstWrite(); + //addNotifyOnFirstWrite(); if (sizeof(TFrom) == sizeof(TTo)) return p_print->write(data, len); size_t samples = len / sizeof(TFrom); size_t result_size = 0; @@ -485,7 +485,7 @@ class NumberFormatConverterStream : public ReformatBaseStream { bool begin(int from_bit_per_samples, int to_bit_per_samples, float gain = 1.0) { assert(to_bit_per_samples > 0); - is_output_notify = false; + //is_output_notify = false; this->gain = gain; LOGI("begin %d -> %d bits", from_bit_per_samples, to_bit_per_samples); bool result = true; @@ -761,7 +761,7 @@ class FormatConverterStream : public ReformatBaseStream { /// (Re-)Starts the processing: call setAudioInfo and setAudioInfoOut before bool begin() override { TRACED(); - is_output_notify = false; + //is_output_notify = false; // build output chain if (getStream() != nullptr) { sampleRateConverter.setStream(*getStream()); @@ -797,7 +797,7 @@ class FormatConverterStream : public ReformatBaseStream { virtual size_t write(const uint8_t *data, size_t len) override { LOGD("FormatConverterStream::write: %d", (int)len); - addNotifyOnFirstWrite(); + //addNotifyOnFirstWrite(); return channelFormatConverter.write(data, len); } diff --git a/src/AudioTools/CoreAudio/AudioTypes.h b/src/AudioTools/CoreAudio/AudioTypes.h index fcd2decda..44f778f4c 100644 --- a/src/AudioTools/CoreAudio/AudioTypes.h +++ b/src/AudioTools/CoreAudio/AudioTypes.h @@ -297,30 +297,6 @@ class AudioTime { */ class NumberConverter { public: - // static int32_t convertFrom24To32(int24_t value) { - // return value.scale32(); - // } - - // static int16_t convertFrom24To16(int24_t value) { - // return value.scale16(); - // } - - // static float convertFrom24ToFloat(int24_t value) { - // return value.scaleFloat(); - // } - - // static int16_t convertFrom32To16(int32_t value) { - // return static_cast(value) / INT32_MAX * INT16_MAX; - // } - - // static int16_t convert16(int value, int value_bits_per_sample){ - // return value * NumberConverter::maxValue(16) / NumberConverter::maxValue(value_bits_per_sample); - // } - - // static int16_t convert8(int value, int value_bits_per_sample){ - // return value * NumberConverter::maxValue(8) / NumberConverter::maxValue(value_bits_per_sample); - // } - /// provides the biggest number for the indicated number of bits static int64_t maxValue(int value_bits_per_sample){ switch(value_bits_per_sample){ diff --git a/src/AudioTools/CoreAudio/ResampleStream.h b/src/AudioTools/CoreAudio/ResampleStream.h index 9834da588..9adf88cce 100644 --- a/src/AudioTools/CoreAudio/ResampleStream.h +++ b/src/AudioTools/CoreAudio/ResampleStream.h @@ -62,7 +62,7 @@ class ResampleStream : public ReformatBaseStream { bool begin(ResampleConfig cfg) { LOGI("begin step_size: %f", cfg.step_size); - is_output_notify = false; + //is_output_notify = false; to_sample_rate = cfg.to_sample_rate; out_buffer.resize(cfg.buffer_size); @@ -161,7 +161,7 @@ class ResampleStream : public ReformatBaseStream { size_t write(const uint8_t *data, size_t len) override { LOGD("ResampleStream::write: %d", (int)len); - addNotifyOnFirstWrite(); + //addNotifyOnFirstWrite(); size_t written = 0; switch (info.bits_per_sample) { case 16: