Hello,
Over a year later and I'm still at it! The ESP32 implementation works ok, but I didn't like the workflow. I searched on a way to build the project with Arduino IDE instead, and found that a user pschatzmann on github made this ESP32-A2DP project, and it compiles fine!
OK, so fire up a sketch and hook up I2S to my project like this.

As posted on the github project page, and similarly to the ESP32 I2S library, you can define the I2S stream. Here is my code:
Code:
/*
Streaming Music from Bluetooth Phil Schatzmann
Copyright (C) 2020 Phil Schatzmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//default I2S pins: – bck_io_num = 26, – ws_io_num = 25, – data_out_num = 22,
#include "BluetoothA2DPSink.h"
BluetoothA2DPSink a2dp_sink;
void setup() {
static const i2s_config_t i2s_config = {
//
.mode = (i2s_mode_t) (I2S_MODE_SLAVE | I2S_MODE_TX ),
.sample_rate = 44100, // corrected by info from bluetooth
.bits_per_sample = (i2s_bits_per_sample_t) 32, /* the DAC module will only take the 8bits from MSB */
// I2S_CHANNEL_FMT_RIGHT_LEFT, I2S_CHANNEL_FMT_ALL_RIGHT, I2S_CHANNEL_FMT_ALL_LEFT, I2S_CHANNEL_FMT_ONLY_RIGHT, I2S_CHANNEL_FMT_ONLY_LEFT
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = (i2s_comm_format_t) (0X01), //I2S_COMM_FORMAT_STAND_I2S
//.communication_format = (i2s_comm_format_t) (0X03), //I2S_COMM_FORMAT_STAND_MSB
//.communication_format = (i2s_comm_format_t) (0x02), //I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_LSB
//.communication_format = (i2s_comm_format_t) (0x04), //I2S_COMM_FORMAT_PCM
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = 16,
.dma_buf_len = 64,
.use_apll = false
};
static const i2s_pin_config_t pin_config = {
.bck_io_num = 26,
.ws_io_num = 25,
.data_out_num = 21,
.data_in_num = I2S_PIN_NO_CHANGE
};
//i2s_set_pin(i2s_num, pin_config);
a2dp_sink.set_i2s_config(i2s_config);
a2dp_sink.start("MyMusic2");
}
void loop() {
}
For the Teensy config, I've tried it with an I2S/I2S2 configuration as well as a TDM/I2S2 configuration and I get the same results. I get sound from the bluetooth sink, but it sounds high pitched (chipmunk). When I set the bitrate to 16 bit audio I get loud noise, when I set it to 32 bit audio it's high pitched but it is audible.
If you have any interest in getting this working it's a pretty simple setup. Run a passthrough USB sketch on teensy, confirm sound, then add your I2S2 object (and a pair of mixers) to the project and hook up the 3 I2S lines (.bck_io_num = 26, .ws_io_num = 25 (lrclk), .data_out_num = 21). Here is some sample code for the Teensy...
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputI2S2 i2s2_1; //xy=413.88890075683594,363.88888931274414
AudioInputUSB usb1; //xy=420.8888854980469,282.99999886751175
AudioMixer4 mixer1; //xy=623.8888854980469,296.8888854980469
AudioMixer4 mixer2; //xy=627.8888320922852,383.8888854980469
AudioOutputI2S i2s1; //xy=797.8889083862305,277.99999237060547
AudioConnection patchCord1(i2s2_1, 0, mixer2, 0);
AudioConnection patchCord2(i2s2_1, 1, mixer1, 1);
AudioConnection patchCord3(usb1, 0, mixer1, 0);
AudioConnection patchCord4(usb1, 1, mixer2, 1);
AudioConnection patchCord5(mixer1, 0, i2s1, 0);
AudioConnection patchCord6(mixer2, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=565.8888702392578,518.0000267028809
// GUItool: end automatically generated code
void setup() {
AudioMemory(12);
sgtl5000_1.enable();
sgtl5000_1.volume(0.6);
}
void loop() {
// read the PC's volume setting
float vol = usb1.volume();
// scale to a nice range (not too loud)
// and adjust the audio shield output volume
if (vol > 0) {
// scale 0 = 1.0 range to:
// 0.3 = almost silent
// 0.8 = really loud
vol = 0.3 + vol * 0.5;
}
// use the scaled volume setting. Delete this for fixed volume.
sgtl5000_1.volume(vol);
delay(100);
}
// Teensyduino 1.35 & earlier had a problem with USB audio on Macintosh
// computers. For more info and a workaround:
// https://forum.pjrc.com/threads/34855-Distorted-audio-when-using-USB-input-on-Teensy-3-1?p=110392&viewfull=1#post110392
Does anyone have any advice on how to further debug this? From experience debugging my other modules I'm certain it is a data format/timing issue...
Thanks for your input!
Jay