0
\$\begingroup\$

I have a CODEC circuit with a AUX audio output. Is it possible to connect that output back to the ESP32 and transmit to a Bluetooth speaker using the ESP32-A2DP library?

If so, would this be the bones of the program:

/*
  Streaming of sound data with Bluetooth to other Bluetooth device.
  We generate 2 tones which will be sent to the 2 channels.
  
  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/>.
*/
#include "BluetoothA2DPSource.h"
#include <math.h> 

#define c3_frequency  130.81

BluetoothA2DPSource a2dp_source;

// The supported audio codec in ESP32 A2DP is SBC. SBC audio stream is encoded
// from PCM data normally formatted as 44.1kHz sampling rate, two-channel 16-bit sample data
int32_t get_data_frames(Frame *frame, int32_t frame_count) {
    static float m_time = 0.0;
    float m_amplitude = 10000.0;  // -32,768 to 32,767
    float m_deltaTime = 1.0 / 44100.0;
    float m_phase = 0.0;
    float pi_2 = PI * 2.0;
    // fill the channel data
    for (int sample = 0; sample < frame_count; ++sample) {
        float angle = pi_2 * c3_frequency * m_time + m_phase;
        frame[sample].channel1 = m_amplitude * sin(angle);
        frame[sample].channel2 = frame[sample].channel1;
        m_time += m_deltaTime;
    }

    return frame_count;
}


void setup() {
  //a2dp_source.set_auto_reconnect(false);
  a2dp_source.start("LEXON MINO L", get_data_frames);  
  a2dp_source.set_volume(30);
}

void loop() {
  // to prevent watchdog in release > 1.0.6
  delay(10);
}

https://github.com/pschatzmann/ESP32-A2DP/blob/main/examples/bt_music_sender/bt_music_sender.ino

Right now, as a proof of concept, I just bought an off the shelf Bluetooth transmitter:

enter image description here

So, I want to get rid of the off the shelf Bluetooth transmitter to hopefully feed the audio into the ESP32 to transmit instead.

\$\endgroup\$
2
  • \$\begingroup\$ I think you’d want to use an audio codec board, not the midi synth board you’ve shown. \$\endgroup\$
    – Kartman
    Commented Aug 1, 2023 at 22:29
  • \$\begingroup\$ The synth board shown has built-in musical instrument sounds which are used. The application is not music, but instead just emitting different rudimentary tones. \$\endgroup\$
    – adamaero
    Commented Aug 2, 2023 at 13:11

2 Answers 2

1
\$\begingroup\$

According to the A2DP Source (Music Sender), yes it is possible.

You need to set the Bluetooth device name (sink) that you want to connect to and a callback that can supply PCM audio data to be sent.

This feature looks to have been added in the September 2023 release.

\$\endgroup\$
0
\$\begingroup\$

The ESP32 ADC is not suitable for any serious audio signals, but it can sample audio at a very low quality. You will need a separate codec board to digitise your audio if you want to listen to music.

See the answers in ESP32 ADC not good enough for audio/music?

\$\endgroup\$
3
  • \$\begingroup\$ The audio is rudimentary sounds, not music. I'm mainly wondering if the ESP32 has the capability to be fed these sounds and transmit them via Bluetooth. \$\endgroup\$
    – adamaero
    Commented Aug 2, 2023 at 13:12
  • \$\begingroup\$ That may work, if you don't do those things simultaneously - activating Bluetooth will probably use too much processing power to sample the audio effectively. Sampling first and transmitting later may work. \$\endgroup\$
    – Paul
    Commented Aug 2, 2023 at 13:46
  • \$\begingroup\$ Aw, ok. It needs to be in real time and the device is battery powered. \$\endgroup\$
    – adamaero
    Commented Aug 2, 2023 at 13:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.