pschatzmann / arduino-audio-tools

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

4-channel AAC example? #1571

Closed andriesess closed 5 months ago

andriesess commented 6 months ago

Problem Description

I'm trying to stream 4-channel AAC audio (16-bit, 48kHz) over WiFi to two I2S ports by trying to combine two of your examples:

  1. streams-sd_wav4-i2s
  2. streams-url_aac-i2s

Sadly my ESP32 S3 board does not have an SD card slot so I can't truly test the 4-channel wav, however the goal is to stream 4-channel compressed audio (like AAC) over WiFi.

I tried multiple variations, I have to say I'm not too experienced, but for some reason more than 2 channels fails to work with AAC. Is this a limitation of the AACHelix codec?

Is it überhaupt possible to use a single 4-channel AAC stream, but split it up for 2 I2S ports? If it is not possible with AACHelix, do you have any suggestions or alternatives besides wav to achieve this goal?

I do have access to a oscilloscope, which was quiet helpfull to inspect the emitted samplerates, bitdepths, etc.

Device Description

QTPy ESP32-S3 with PS RAM

4x MAX98357A DAC's

Sketch

/**
 * @file streams-sd_wav4-i2s.ino
 * @author Phil Schatzmann
 * @brief decode WAV file with 4 channels and output it on 2 I2S ports
 * @version 0.1
 * @date 2021-96-25
 *
 * @copyright Copyright (c) 2021
 */

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

URLStream url("MyWifi","MyPassword");
I2SStream i2s_1;  // final output port 0
I2SStream i2s_2;  // final output port 1
ChannelsSelectOutput out;
EncodedAudioOutput decoder(&out, new AACDecoderHelix());  // Decoding stream
StreamCopy copier; // copy url to decoder

AudioInfo info(48000, 2, 16);

void setup() {
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Info);

  // setup i2s
  auto config1 = i2s_1.defaultConfig(TX_MODE);
    config1.pin_ws = 9;
    config1.pin_bck = 17;
    config1.pin_data = 18;
    config1.copyFrom(info);
    config1.port_no = 0;
  i2s_1.begin(config1);

  auto config2 = i2s_2.defaultConfig(TX_MODE);
    config2.pin_ws = 36;
    config2.pin_bck = 37;
    config2.pin_data = 35;
    config2.copyFrom(info);
    config2.port_no = 1;
  i2s_2.begin(config2);

  // split channels to different i2s ports
  out.addOutput(i2s_1, 0, 1);
  out.addOutput(i2s_2, 2, 3);
  // you might want to update the format changes automatically
  //out.addNotifyAudioChange(i2s_1); 
  //out.addNotifyAudioChange(i2s_2);
  out.begin(info);

  // aac radio
  url.begin("http://192.168.129.76:8000/stream","audio/aac");  

  // setup decoder
  decoder.begin(info);

  // begin copy
  copier.begin(decoder, url);
}

void loop() {
  if (!copier.copy()) {
    stop();
  }
}

Other Steps to Reproduce

No response

What is your development environment

Arduino IDE

I have checked existing issues, discussions and online documentation

pschatzmann commented 5 months ago

See Multichannel in the AAC Readme