Skip to content

Commit

Permalink
fix broken ADPCM audio info
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 3, 2023
1 parent a7a6ecf commit b246cc7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
AudioBLEServer ble;
Expand Down
7 changes: 4 additions & 3 deletions src/AudioCodecs/AudioEncoded.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/AudioCodecs/CodecADPCM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b246cc7

Please sign in to comment.