Play MP3 files in FreeRTOS tasks
Posted: Wed Jan 16, 2019 9:25 am
Hello,
I'm trying to play mp3 files based on the example https://github.com/espressif/esp-adf/tr ... ay_mp3_dac. I've only 1 DAC channel available (GPIO25). So I've created a custom DAC configuration.
#define I2S_STREAM_INTERNAL_DAC_CFG_CUSTOM() { \
.type = AUDIO_STREAM_WRITER, \
.task_prio = I2S_STREAM_TASK_PRIO, \
.task_core = I2S_STREAM_TASK_CORE, \
.task_stack = I2S_STREAM_TASK_STACK, \
.out_rb_size = I2S_STREAM_RINGBUFFER_SIZE, \
.i2s_config = { \
.mode = I2S_MODE_MASTER | I2S_MODE_DAC_BUILT_IN | I2S_MODE_TX, \
.sample_rate = 44100, \
.bits_per_sample = 16, \
.channel_format = I2S_CHANNEL_FMT_ALL_RIGHT, \
.communication_format = I2S_COMM_FORMAT_I2S_MSB, \
.dma_buf_count = 3, \
.dma_buf_len = 300, \
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, \
}, \
.i2s_port = 0, \
}
My firmware has several Freertos tasks and I would like to play mp3 files inside these tasks.
I've 2 issues:
--------------------------------------------------------------------------------------
1. If I run the example in my main() function, the mp3 is played correctly but at the end of the music, the following code is not executed.
I (207) cpu_start: Pro cpu start user code
I (2) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (4) gpio: GPIO[27]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (12) uart: UART is initialized
I (15) i2c: I2C is initialized
I (18) mp3: [ 1 ] Create audio pipeline, add all elements to pipeline, and subscribe pipeline event
I (28) mp3: [1.1] Create mp3 decoder to decode mp3 file and set custom read callback
I (37) mp3: [1.2] Create i2s stream to write data to ESP32 internal DAC
I (45) mp3: [1.3] Register all elements to audio pipeline
I (50) mp3: [1.4] Link it together [mp3_music_read_cb]-->mp3_decoder-->i2s_stream-->[ESP32 DAC]
I (59) mp3: [ 2 ] Setup event listener
I (64) mp3: [2.1] Listening event from all elements of pipeline
I (70) mp3: [ 3 ] Start audio_pipeline
I (88) mp3: [ * ] Receive music info from mp3 decoder, sample_rates=44100, bits=16, ch=2
I (6837) mp3: [ 4 ] Stop audio_pipeline
W (6838) AUDIO_PIPELINE: There are no listener registered
--------------------------------------------------------------------------------------
2. If I run inside a task, I've the following error and the mp3 is not played.
I (176) main: Start Sensor Task
I (10404) mp3: [ 1 ] Create audio pipeline, add all elements to pipeline, and subscribe pipeline event
I (10404) mp3: [1.1] Create mp3 decoder to decode mp3 file and set custom read callback
I (10412) mp3: [1.2] Create i2s stream to write data to ESP32 internal DAC
E (10420) I2S: Register I2S Interrupt error
--------------------------------------------------------------------------------------
Thank you for your help and best regards.
I'm trying to play mp3 files based on the example https://github.com/espressif/esp-adf/tr ... ay_mp3_dac. I've only 1 DAC channel available (GPIO25). So I've created a custom DAC configuration.
#define I2S_STREAM_INTERNAL_DAC_CFG_CUSTOM() { \
.type = AUDIO_STREAM_WRITER, \
.task_prio = I2S_STREAM_TASK_PRIO, \
.task_core = I2S_STREAM_TASK_CORE, \
.task_stack = I2S_STREAM_TASK_STACK, \
.out_rb_size = I2S_STREAM_RINGBUFFER_SIZE, \
.i2s_config = { \
.mode = I2S_MODE_MASTER | I2S_MODE_DAC_BUILT_IN | I2S_MODE_TX, \
.sample_rate = 44100, \
.bits_per_sample = 16, \
.channel_format = I2S_CHANNEL_FMT_ALL_RIGHT, \
.communication_format = I2S_COMM_FORMAT_I2S_MSB, \
.dma_buf_count = 3, \
.dma_buf_len = 300, \
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, \
}, \
.i2s_port = 0, \
}
My firmware has several Freertos tasks and I would like to play mp3 files inside these tasks.
I've 2 issues:
--------------------------------------------------------------------------------------
1. If I run the example in my main() function, the mp3 is played correctly but at the end of the music, the following code is not executed.
I (207) cpu_start: Pro cpu start user code
I (2) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (4) gpio: GPIO[27]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (12) uart: UART is initialized
I (15) i2c: I2C is initialized
I (18) mp3: [ 1 ] Create audio pipeline, add all elements to pipeline, and subscribe pipeline event
I (28) mp3: [1.1] Create mp3 decoder to decode mp3 file and set custom read callback
I (37) mp3: [1.2] Create i2s stream to write data to ESP32 internal DAC
I (45) mp3: [1.3] Register all elements to audio pipeline
I (50) mp3: [1.4] Link it together [mp3_music_read_cb]-->mp3_decoder-->i2s_stream-->[ESP32 DAC]
I (59) mp3: [ 2 ] Setup event listener
I (64) mp3: [2.1] Listening event from all elements of pipeline
I (70) mp3: [ 3 ] Start audio_pipeline
I (88) mp3: [ * ] Receive music info from mp3 decoder, sample_rates=44100, bits=16, ch=2
I (6837) mp3: [ 4 ] Stop audio_pipeline
W (6838) AUDIO_PIPELINE: There are no listener registered
--------------------------------------------------------------------------------------
2. If I run inside a task, I've the following error and the mp3 is not played.
I (176) main: Start Sensor Task
I (10404) mp3: [ 1 ] Create audio pipeline, add all elements to pipeline, and subscribe pipeline event
I (10404) mp3: [1.1] Create mp3 decoder to decode mp3 file and set custom read callback
I (10412) mp3: [1.2] Create i2s stream to write data to ESP32 internal DAC
E (10420) I2S: Register I2S Interrupt error
--------------------------------------------------------------------------------------
Thank you for your help and best regards.