EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #156 background imageLoading...
Page #156 background image
SunFounder ESP32 Starter Kit
5. Play audio on the device and the audio should be played through the speaker connected to the ESP32.
Code Explanation
1. The code starts by including the BluetoothA2DPSink.h library, which is used to receive audio data from the
Bluetooth-enabled device. The BluetoothA2DPSink object is then created and configured with the I2S interface
settings.
#include "BluetoothA2DPSink.h"
BluetoothA2DPSink a2dp_sink;
2. In the setup function, the code initializes an i2s_config_t struct with the desired configuration for the I2S
(Inter-IC Sound) interface.
void setup() {
const i2s_config_t i2s_config = {
.mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_
˓BUILT_IN),
.sample_rate = 44100, // corrected by info from bluetooth
.bits_per_sample = (i2s_bits_per_sample_t) 16, // the DAC module will
˓only take the 8bits from MSB
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = (i2s_comm_format_t)I2S_COMM_FORMAT_STAND_MSB,
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};
a2dp_sink.set_i2s_config(i2s_config);
a2dp_sink.start("ESP32_Bluetooth");
}
The I2S interface is used to transfer digital audio data between devices.
The configuration includes the I2S mode, sample rate, bits per sample, channel
format, communication format, interrupt allocation flags, DMA buffer count,
DMA buffer length, and whether to use the APLL (Audio PLL) or not.
150 Chapter 1. For Arduino User

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish