Skip to content

Commit

Permalink
Converters use standard notification
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 5, 2024
1 parent ee0f04f commit 740b2a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/AudioTools/AudioCodecs/AudioEncoded.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class EncodedAudioStream : public ReformatBaseStream {
}

bool begin() {
is_output_notify = false;
//is_output_notify = false;
reader.setByteCountFactor(10);
setupReader();
ReformatBaseStream::begin();
Expand All @@ -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);
}

Expand Down
33 changes: 17 additions & 16 deletions src/AudioTools/CoreAudio/AudioIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -194,20 +195,20 @@ class ReformatBaseStream : public ModifyingStream {
TransformationReader<ReformatBaseStream> 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) {
Expand Down
18 changes: 9 additions & 9 deletions src/AudioTools/CoreAudio/AudioStreamsConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(toChannels) / static_cast<float>(fromChannels);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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<int8_t>()->write(data, len);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}

Expand Down
24 changes: 0 additions & 24 deletions src/AudioTools/CoreAudio/AudioTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(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){
Expand Down
4 changes: 2 additions & 2 deletions src/AudioTools/CoreAudio/ResampleStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 740b2a6

Please sign in to comment.