Skip to content

Commit

Permalink
MetaDataFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Oct 28, 2024
1 parent d2539de commit b3dec88
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,38 @@
#include "SD.h"

AudioInfo info(32000, 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
AudioBoardStream out(AudioKitEs8388V1);
StreamCopy copier(out, sound); // copies sound into i2s
SineWaveGenerator<int16_t> sineWave(
32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(
sineWave); // Stream generated from sine wave
DriverPins my_pins;
AudioBoard board(AudioDriverES8388, my_pins);
AudioBoardStream out(board);
StreamCopy copier(out, sound); // copies sound into i2s

// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
while(!Serial);
while (!Serial);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
//LOGLEVEL_AUDIOKIT = AudioKitDebug;

// sd pins: clk, miso, mosi,cs,
my_pins.addSPI(ESP32PinsSD{PinFunction::SD, 44, 42, 43, 2, SPI});
// add i2c codec pins: scl, sda, port, frequency
my_pins.addI2C(PinFunction::CODEC, 35, 36);
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
my_pins.addI2S(PinFunction::CODEC, 47, 21, 12, 14, 11);

// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
config.sd_active = false;
// i2c
config.pins.i2c_sda = 36;
config.pins.i2c_scl = 35;
// i2s
config.pin_mck = 47;
config.pin_bck = 21;
config.pin_ws = 12;
config.pin_data = 14;
config.pin_data_rx = 11;

//config.sd_active = false;
config.pins.sd_cs = 2;
config.pins.sd_miso = 42;
config.pins.sd_mosi = 43;
config.pins.sd_clk = 44;
out.begin(config, false);
config.sd_active = true;
out.begin(config);

// check SD drive
if(!SD.begin(config.pins.sd_cs)){
if (!SD.begin(2)) {
Serial.println("Card Mount Failed");
stop();
}
Expand All @@ -59,6 +54,4 @@ void setup(void) {
}

// Arduino loop - copy sound to out
void loop() {
copier.copy();
}
void loop() { copier.copy(); }
18 changes: 1 addition & 17 deletions src/AudioTools/AudioCodecs/CodecMP3Helix.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class MP3DecoderHelix : public AudioDecoder {
mp3 = new libhelix::MP3DecoderHelix();
if (mp3!=nullptr){
mp3->setReference(this);
filter.setDecoder(mp3);
} else {
LOGE("Not enough memory for libhelix");
}
Expand All @@ -37,7 +36,6 @@ class MP3DecoderHelix : public AudioDecoder {
mp3 = new libhelix::MP3DecoderHelix();
if (mp3!=nullptr){
mp3->setReference(this);
filter.setDecoder(mp3);
} else {
LOGE("Not enough memory for libhelix");
}
Expand All @@ -56,7 +54,6 @@ class MP3DecoderHelix : public AudioDecoder {
mp3 = new libhelix::MP3DecoderHelix();
if (mp3!=nullptr){
mp3->setReference(this);
filter.setDecoder(mp3);
} else {
LOGE("Not enough memory for libhelix");
}
Expand All @@ -83,7 +80,6 @@ class MP3DecoderHelix : public AudioDecoder {
if (mp3!=nullptr) {
//mp3->setDelay(CODEC_DELAY_MS);
mp3->begin();
filter.begin();
}
return true;
}
Expand Down Expand Up @@ -111,7 +107,7 @@ class MP3DecoderHelix : public AudioDecoder {
size_t write(const uint8_t* data, size_t len) {
LOGD("%s: %zu", LOG_METHOD, len);
if (mp3==nullptr) return 0;
return use_filter ? filter.write((uint8_t*)data, len): mp3->write((uint8_t*)data, len);
return mp3->write((uint8_t*)data, len);
}

/// checks if the class is active
Expand Down Expand Up @@ -146,16 +142,6 @@ class MP3DecoderHelix : public AudioDecoder {
}
}

/// Activates a filter that makes sure that helix does not get any metadata segments
void setFilterMetaData(bool filter){
use_filter = filter;
}

/// Check if the metadata filter is active
bool isFilterMetaData() {
return use_filter;
}

/// Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value
size_t maxFrameSize() {
return mp3->maxFrameSize();
Expand All @@ -177,8 +163,6 @@ class MP3DecoderHelix : public AudioDecoder {
}
protected:
libhelix::MP3DecoderHelix *mp3=nullptr;
MetaDataFilter<libhelix::MP3DecoderHelix> filter;
bool use_filter = false;

};

Expand Down
Loading

0 comments on commit b3dec88

Please sign in to comment.