From b246cc77bc900f4e2861d3d249639bda0c0b994d Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Fri, 3 Nov 2023 20:04:15 +0100 Subject: [PATCH] fix broken ADPCM audio info --- .../communication-ble-client/communication-ble-client.ino | 2 +- .../communication-ble-server/communication-ble-server.ino | 2 +- src/AudioCodecs/AudioEncoded.h | 7 ++++--- src/AudioCodecs/CodecADPCM.h | 6 ++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/sandbox/ble/communication-ble-client/communication-ble-client.ino b/examples/sandbox/ble/communication-ble-client/communication-ble-client.ino index a51863ef7f..bc8136c8dd 100644 --- a/examples/sandbox/ble/communication-ble-client/communication-ble-client.ino +++ b/examples/sandbox/ble/communication-ble-client/communication-ble-client.ino @@ -14,7 +14,7 @@ #include "AudioCodecs/CodecADPCM.h" // https://github.com/pschatzmann/adpcm #include "Sandbox/BLE/AudioBLE.h" -AudioInfo info(8000, 1, 16); +AudioInfo info(44100, 2, 16); AudioBLEClient ble; I2SStream i2s; ADPCMDecoder adpcm(AV_CODEC_ID_ADPCM_IMA_WAV); diff --git a/examples/sandbox/ble/communication-ble-server/communication-ble-server.ino b/examples/sandbox/ble/communication-ble-server/communication-ble-server.ino index d8594f4692..1f3a1545dd 100644 --- a/examples/sandbox/ble/communication-ble-server/communication-ble-server.ino +++ b/examples/sandbox/ble/communication-ble-server/communication-ble-server.ino @@ -12,7 +12,7 @@ #include "AudioCodecs/CodecADPCM.h" // https://github.com/pschatzmann/adpcm #include "Sandbox/BLE/AudioBLE.h" -AudioInfo info(8000, 1, 16); +AudioInfo info(44100, 2, 16); SineWaveGenerator sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000 GeneratedSoundStream sound( sineWave); // Stream generated from sine wave AudioBLEServer ble; diff --git a/src/AudioCodecs/AudioEncoded.h b/src/AudioCodecs/AudioEncoded.h index a299f6f4b4..5fd15f96fd 100644 --- a/src/AudioCodecs/AudioEncoded.h +++ b/src/AudioCodecs/AudioEncoded.h @@ -80,7 +80,7 @@ class AudioEncoder : public AudioWriter { /// Provides the mime type of the encoded result virtual const char *mime() = 0; /// Defines the sample rate, number of channels and bits per sample - void setAudioInfo(AudioInfo from) override{}; + virtual void setAudioInfo(AudioInfo from) override{}; }; class AudioDecoderExt : public AudioDecoder { @@ -282,7 +282,6 @@ class EncodedAudioOutput : public AudioStream { TRACED(); if (this->info != info && info.channels!=0 && info.sample_rate!=0) { this->info = info; - AudioStream::setAudioInfo(info); decoder_ptr->setAudioInfo(info); encoder_ptr->setAudioInfo(info); } @@ -333,6 +332,8 @@ class EncodedAudioOutput : public AudioStream { const CodecNOP *nop = CodecNOP::instance(); if (decoder_ptr != nop || encoder_ptr != nop) { active = true; + decoder_ptr->setAudioInfo(info); + encoder_ptr->setAudioInfo(info); decoder_ptr->begin(); encoder_ptr->begin(); } else { @@ -401,7 +402,7 @@ class EncodedAudioOutput : public AudioStream { } protected: - AudioInfo info; + //AudioInfo info; AudioDecoder *decoder_ptr = CodecNOP::instance(); // decoder AudioEncoder *encoder_ptr = CodecNOP::instance(); // decoder AudioWriter *writer_ptr = nullptr; diff --git a/src/AudioCodecs/CodecADPCM.h b/src/AudioCodecs/CodecADPCM.h index 2e01106501..ee7d961a7d 100644 --- a/src/AudioCodecs/CodecADPCM.h +++ b/src/AudioCodecs/CodecADPCM.h @@ -29,6 +29,7 @@ class ADPCMDecoder : public AudioDecoderExt { void begin() override { TRACEI(); current_byte = 0; + LOGI("sample_rate: %d, channels: %d", info.sample_rate, info.channels); decoder.begin(info.sample_rate, info.channels); LOGI("frameSize: %d", (int)decoder.frameSize()); block_size = decoder.blockSize(); @@ -115,13 +116,10 @@ class ADPCMEncoder : public AudioEncoderExt { return encoder.blockSize(); } - void begin(AudioInfo info) override { - setAudioInfo(info); - begin(); - } void begin() override { TRACEI(); + LOGI("sample_rate: %d, channels: %d", info.sample_rate, info.channels); encoder.begin(info.sample_rate, info.channels); LOGI("frameSize: %d", (int)encoder.frameSize()); assert(info.sample_rate != 0);