Low-Pass Filter on audio from A2DP #790
-
|
Has anyone ever tried filtering audio from A2DP using the audio-tools lib (from the same dev)? I honestly need help on how to implement it since I don't quite understand on how to run the audio data through a FIR filter. Currently, here's my code: #include <Arduino.h>
#include "AudioTools.h"
#include "BluetoothA2DPSinkQueued.h"
const uint8_t S_CLK = 25;
const uint8_t S_WS = 32;
const uint8_t S_OUT = 27;
const uint8_t S_SHUT = 4;
const uint8_t led = 2;
const uint16_t channels = 2;
AudioInfo to_info(48000, 2, 16);
I2SStream out;
Equalizer3Bands eq(out);
BluetoothA2DPSinkQueued a2dp_sink(out);
FilteredStream<int16_t, float> inFiltered(out, channels);
StreamCopy copier(out, inFiltered);
float coef[] = { 0.0209967345, 0.0960112308, 0.1460005493, 0.0960112308, 0.0209967345 };
ConfigEqualizer3Bands cfg_eq;
const uint16_t low_freq = 300;
const uint16_t high_freq = 11000;
void read_data_stream(const uint8_t *data, uint32_t length) {
eq.write(data, length);
}
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
pinMode(led, OUTPUT);
pinMode(S_SHUT, OUTPUT);
digitalWrite(S_SHUT, HIGH);
inFiltered.setFilter(0, new FIR<float>(coef));
inFiltered.setFilter(1, new FIR<float>(coef));
auto cfg = out.defaultConfig(TX_MODE);
cfg.pin_bck = S_CLK;
cfg.pin_ws = S_WS;
cfg.pin_data = S_OUT;
cfg.copyFrom(to_info);
out.begin(cfg);
cfg_eq = eq.defaultConfig();
cfg_eq.setAudioInfo(to_info);
cfg_eq.freq_low = low_freq;
cfg_eq.freq_high = high_freq;
cfg_eq.gain_low = 1.1;
cfg_eq.gain_medium = 1.1;
cfg_eq.gain_high = 0.9;
eq.begin(cfg_eq);
a2dp_sink.set_stream_reader(read_data_stream, false);
a2dp_sink.set_auto_reconnect(true);
a2dp_sink.start("current.speaker");
}
void loop() {
copier.copy();
if (a2dp_sink.is_connected()) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
}
With this current code, nothing really happens and an "handle is NULL" appears in serial logs. Any help is appreciated ^^,, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
I am sorry, but this does not make any sense at all! If you just want to send the output to the filter, delete
and send the output for a2dp to the filter with
maybe a better name should be outFiltered instead of inFiltered... |
Beta Was this translation helpful? Give feedback.
This is calling end() on the defined output. It seems that for the FilteredStream this is dropping the assigned filters, so that they would need to be assigned again.
I redesigned the FilteredStream class to keep the assignenmants...
As an alternative workaround you could wrap the FilteredStream in a CallbackStream or VolumeStream.