pschatzmann / arduino-audio-tools

Arduino Audio Tools (a powerful Audio library not only for Arduino)
GNU General Public License v3.0
1.54k stars 237 forks source link

EncodedAudioStream (URLStream) combined with AudioEffectsStream #1583

Closed vegasje closed 5 months ago

vegasje commented 6 months ago

Problem Description

First off, let me say that this project is absolutely incredible, and you have done an amazing thing for the community by making all this functionality available. I truly appreciate all the effort that has gone into this codebase.

The issue I'm running into is that I cannot seem to get Audio Effects working with an EncodedAudioStream. I am currently using a VolumeStream to control the volume of an internet radio stream. I am attempting to swap out the VolumeStream for an AudioEffectStream with a Boost effect applied.

The included code will output no audio, however if I comment out pipeline.add(effectsStream);, then audio is emitted.

If I change the logger to output Debug information, it looks like 0 bytes of data gets copied once the AudioEffectStream is added to the pipeline.

Any advice would be greatly appreciated.

Device Description

ESP32-S3-DevKitC-1-N8R8

Sketch

#include <Arduino.h>

#include "AudioTools.h"
#include "AudioCodecs/CodecMP3Helix.h"

// Define I2S connections
#define I2S_DOUT  15
#define I2S_BCLK  16
#define I2S_LRC   17
#define VOL_CONTROL 5

float volume = 0.1;

const char* ssid = "SSID";
const char* password = "PASS";

Pipeline pipeline;
URLStream urlStream(ssid, password);
EncodedAudioStream encAudioStream(new MP3DecoderHelix());
VolumeStream volumeStream;
AudioEffectStream effectsStream;
I2SStream i2sStream; // Final output of decoded stream.
StreamCopy copier(i2sStream, pipeline);

const int sample_rate = 44100;
Delay dly(998, 0.5, 1.0, sample_rate);

Boost boost(volume);

void setup() {
  Serial.begin(115200);

  AudioLogger::instance().begin(Serial, AudioLogger::Warning);

  auto config = i2sStream.defaultConfig(TX_MODE);
  config.pin_bck = I2S_BCLK;
  config.pin_ws = I2S_LRC;
  config.pin_data = I2S_DOUT;
  i2sStream.begin(config);

  urlStream.begin("http://0n-80s.radionetz.de:8000/0n-70s.mp3", "audio/mp3");

  volumeStream.setVolume(volume);

  effectsStream.addEffect(boost);
  // effectsStream.addEffect(dly);
  // effectsStream.begin(config);

  pipeline.setInput(urlStream);
  pipeline.add(encAudioStream);
  // pipeline.add(volumeStream);
  pipeline.add(effectsStream);
  pipeline.begin();
}

void loop() {
  // Get the volume level.
  // min in 0 - max is 1.0
  volume = static_cast<float>(analogRead(VOL_CONTROL)) / 4095.0;
  volumeStream.setVolume(volume);
  boost.setVolume(volume);

  copier.copy();
}

Other Steps to Reproduce

No response

What is your development environment

Arduino IDE 2.3.2, MacOS

I have checked existing issues, discussions and online documentation

pschatzmann commented 5 months ago

I committed a correction for this.

Please note that the AudioEffectStream does not support stereo and it will output 2 identical mono channels as a result if you feed some stereo to it.

I think it would also be a bit more memory efficient to use the pipline on the output side.

vegasje commented 5 months ago

Thank you! That worked perfectly.