You are using staging server - a separate instance of the ESP Component Registry that allows you to try distribution tools and processes without affecting the real registry.
# Play music from flash - [中文版](./README_CN.md) ## Example Brief This example demonstrates how to use Embed Flash IO to read music from flash memory, decode it using a decoder element, apply audio effects processing to the decoded data, and then output the music through CODEC_DEV_TX IO. The example supports MP3, WAV, FLAC, AAC, M4A, TS, AMRNB, and AMRWB audio formats, with MP3 as the default format. ## Example Set Up ### Default IDF Branch This example supports IDF release/v5.3 and later branches. ### Prerequisites The audio files used in this example are in the [Embedding Binary Data](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/build-system.html#cmake-embed-data), which is compiled with the code and downloaded to the flash memory. This example provides two test files, `ff-16b-1c-44100hz.mp3` and `alarm.mp3`, located in the `${PROJECT_DIR}/main/` folder. The files `esp_embed_tone.h` and `esp_embed_tone.cmake` are generated by the script `$YOUR_GMF_PATH/elements/gmf_io/mk_flash_embed_tone.py`. If you need to replace the audio files, you must rerun the script to regenerate these two files. Python script command is as follows: ``` python $YOUR_GMF_PATH/elements/gmf_io/mk_flash_embed_tone.py -p $YOUR_GMF_PATH/gmf_examples/basic_examples/pipeline_play_embed_music/main ``` ### Configuration This example supports the ESP32-LyraT-Mini, ESP32c3-Lyra, ESP32s3_Korvo_2, ESP32p4_Function_EV_Board boards. Other boards support need to modify the following content in the [ system_common ](../../system_common): | Configuration | Related Files | Related Functions | |:----:| :-----: | :---- | |I2S Port and I2S Format| `esp_gmf_gpio_config.h`<br>`esp_gmf_setup_peripheral.c` | `setup_periph_create_i2s` | |I2C Port| `esp_gmf_gpio_config.h`<br>`esp_gmf_setup_peripheral.c` | `esp_gmf_setup_periph_i2c` | |Codec Type and Format|`esp_gmf_setup_peripheral.c` |`setup_periph_new_play_codec` | |PA Port| `esp_gmf_gpio_config.h`<br>`esp_gmf_setup_peripheral.c` | `setup_periph_new_play_codec` | ### Build and Flash Before compiling this example, ensure that the ESP-IDF environment is properly configured. If it is already set up, you can proceed to the next configuration step. If not, run the following script in the root directory of ESP-IDF to set up the build environment. For detailed steps on configuring and using ESP-IDF, please refer to the [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/index.html) ``` ./install.sh . ./export.sh ``` Here are the summarized steps for compilation: - Enter the location where the Flash playback test project is stored ``` cd $YOUR_GMF_PATH/gmf_examples/basic_examples/pipeline_play_embed_music ``` - Select the target chip for compilation. For example, to use the ESP32S3: ``` idf.py set-target esp32s3 ``` - Build the Example ``` idf.py build ``` - Flash the program and run the monitor tool to view serial output (replace PORT with the port name): ``` idf.py -p PORT flash monitor ``` - Exit the debugging interface using ``Ctrl-]`` ## How to use the Example ### Example Functionality - After the example starts running, it will retrieve the MP3 audio embedded in the flash binary data and play it, stop and exit after playback is complete, with the following output: ```c I (1100) PLAY_EMBED_MUSIC: [ 1 ] Mount sdcard I (1106) gpio: GPIO[15]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (1115) gpio: GPIO[7]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (1124) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (1175) PLAY_EMBED_MUSIC: [ 2 ] Register all the elements and set audio information to play codec device I (1181) ES8311: Work in Slave mode I (1184) gpio: GPIO[48]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 E (1188) i2s_common: i2s_channel_disable(1107): the channel has not been enabled yet I (1196) I2S_IF: channel mode 0 bits:16/16 channel:2 mask:3 I (1202) I2S_IF: STD Mode 1 bits:16/16 channel:2 sample_rate:48000 mask:3 I (1226) Adev_Codec: Open codec device OK I (1226) ESP_GMF_POOL: Registered items on pool:0x3c1e7640, app_main-60 I (1227) ESP_GMF_POOL: IO, Item:0x3c1e7714, H:0x3c1e7654, TAG:http I (1233) ESP_GMF_POOL: IO, Item:0x3c1e77e4, H:0x3c1e7724, TAG:http I (1240) ESP_GMF_POOL: IO, Item:0x3c1e7880, H:0x3c1e77f4, TAG:file I (1247) ESP_GMF_POOL: IO, Item:0x3c1e791c, H:0x3c1e7890, TAG:file I (1254) ESP_GMF_POOL: IO, Item:0x3c1e7a4c, H:0x3c1e79b8, TAG:embed_flash I (1262) ESP_GMF_POOL: IO, Item:0x3c1e88a0, H:0x3c1e8810, TAG:codec_dev_tx I (1269) ESP_GMF_POOL: EL, Item:0x3c1e79a8, H:0x3c1e792c, TAG:copier I (1276) ESP_GMF_POOL: EL, Item:0x3c1e7b60, H:0x3c1e7a5c, TAG:encoder I (1283) ESP_GMF_POOL: EL, Item:0x3c1e7c54, H:0x3c1e7b70, TAG:decoder I (1290) ESP_GMF_POOL: EL, Item:0x3c1e7d30, H:0x3c1e7c64, TAG:alc I (1297) ESP_GMF_POOL: EL, Item:0x3c1e7df4, H:0x3c1e7d40, TAG:eq I (1304) ESP_GMF_POOL: EL, Item:0x3c1e7e28, H:0x3c1e7f5c, TAG:ch_cvt I (1311) ESP_GMF_POOL: EL, Item:0x3c1e7e58, H:0x3c1e8000, TAG:bit_cvt I (1318) ESP_GMF_POOL: EL, Item:0x3c1e8140, H:0x3c1e80a4, TAG:rate_cvt I (1325) ESP_GMF_POOL: EL, Item:0x3c1e821c, H:0x3c1e8150, TAG:fade I (1332) ESP_GMF_POOL: EL, Item:0x3c1e8318, H:0x3c1e822c, TAG:sonic I (1339) ESP_GMF_POOL: EL, Item:0x3c1e83f8, H:0x3c1e8328, TAG:deinterleave I (1346) ESP_GMF_POOL: EL, Item:0x3c1e84d4, H:0x3c1e8408, TAG:interleave I (1354) ESP_GMF_POOL: EL, Item:0x3c1e85d4, H:0x3c1e84e4, TAG:mixer I (1361) PLAY_EMBED_MUSIC: [ 3 ] Create audio pipeline, add all elements to pipeline W (1369) AUD_SDEC_REG: Overwrote ES decoder 6 W (1374) AUD_SDEC_REG: Overwrote ES decoder 7 W (1379) AUD_SDEC_REG: Overwrote ES decoder 8 I (1385) PLAY_EMBED_MUSIC: [ 3.1 ] Set audio url to play I (1390) PLAY_EMBED_MUSIC: [ 3.2 ] Create gmf task, bind task to pipeline and load linked element jobs to the bind task I (1402) ESP_GMF_TASK: Waiting to run... [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x0, run:0] I (1410) ESP_GMF_THREAD: The TSK_0x3fcba980 created on internal memory I (1418) ESP_GMF_TASK: Waiting to run... [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x3c1e90cc, run:0] I (1427) PLAY_EMBED_MUSIC: [ 3.3 ] Create envent group and listening event from pipeline I (1436) PLAY_EMBED_MUSIC: [ 4 ] Start audio_pipeline I (1441) EMBED_FLASH_IO: The read item is 1, embed://tone/1 I (1448) PLAY_EMBED_MUSIC: CB: RECV Pipeline EVT: el:OBJ_GET_TAG(event->from)-0x3c1e88b0, type:2000, sub:ESP_GMF_EVENT_STATE_OPENING, payload:0x0, size:0,0x3fcbbc90 I (1463) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e90cc,ctx:0x3c1e88e8, label:decoder_open] I (1473) ESP_GMF_PORT: ACQ IN, new self payload:0x3c1e90cc, port:0x3c1e8f50, el:0x3c1e88e8-decoder I (1483) ESP_GMF_PORT: ACQ OUT SET, new self payload:0x3c1e9338, p:0x3c1e8ae8, el:0x3c1e88e8-decoder W (1493) ESP_GMF_ADEC: Not enough memory for out, need:2304, old: 1024, new: 2304 I (1502) ESP_GMF_ADEC: NOTIFY Info, rate: 44100, bits: 16, ch: 1 --> rate: 44100, bits: 16, ch: 1 I (1510) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e9134,ctx:0x3c1e89dc, label:bit_cvt_open] I (1601) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e919c,ctx:0x3c1e8b70, label:rate_cvt_open] I (1601) ESP_GMF_PORT: ACQ OUT SET, new self payload:0x3c1e919c, p:0x3c1e8e34, el:0x3c1e8b70-rate_cvt I (1610) PLAY_EMBED_MUSIC: CB: RECV Pipeline EVT: el:OBJ_GET_TAG(event->from)-0x3c1e8d14, type:3000, sub:ESP_GMF_EVENT_STATE_INITIALIZED, payload:0x3fcbb8f0, size:12,0x3fcbbc90 I (1626) PLAY_EMBED_MUSIC: CB: RECV Pipeline EVT: el:OBJ_GET_TAG(event->from)-0x3c1e8d14, type:2000, sub:ESP_GMF_EVENT_STATE_RUNNING, payload:0x0, size:0,0x3fcbbc90 I (1641) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e9134,ctx:0x3c1e8d14, label:ch_cvt_open] I (1669) PLAY_EMBED_MUSIC: Func:app_main, Line:90, MEM Total:6577140 Bytes, Inter:278727 Bytes, Dram:278727 Bytes I (1670) PLAY_EMBED_MUSIC: [ 5 ] Wait stop event to the pipeline and stop all the pipeline W (23606) EMBED_FLASH_IO: No more data, ret:0, pos: 231725/231725 I (23606) ESP_GMF_ADEC: Total: 1951682 bytes(194) I (23607) ESP_GMF_TASK: Job is done, [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x3c1e9100, job:0x3c1e88e8-decoder_proc] I (23618) ESP_GMF_TASK: Job is done, [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x3c1e9168, job:0x3c1e89dc-bit_cvt_proc] I (23629) ESP_GMF_TASK: Job is done, [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x3c1e91d0, job:0x3c1e8b70-rate_cvt_proc] I (23640) ESP_GMF_TASK: Job is done, [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x3c1e9204, job:0x3c1e8d14-ch_cvt_proc] I (23651) EMBED_FLASH_IO: Closed, pos: 231725/231725 I (23656) ESP_GMF_CODEC_IO: CLose, 0x3c1e8f94, pos = 4248560/0 I (23663) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e90f0,ctx:0x3c1e88e8, label:decoder_close] I (23673) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e9110,ctx:0x3c1e89dc, label:bit_cvt_close] I (23684) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e9144,ctx:0x3c1e8b70, label:rate_cvt_close] I (23694) ESP_GMF_TASK: One times job is complete, del[wk:0x3c1e9178,ctx:0x3c1e8d14, label:ch_cvt_close] I (23704) PLAY_EMBED_MUSIC: CB: RECV Pipeline EVT: el:OBJ_GET_TAG(event->from)-0x3c1e88b0, type:2000, sub:ESP_GMF_EVENT_STATE_FINISHED, payload:0x0, size:0,0x3fcbbc90 I (23719) ESP_GMF_TASK: Waiting to run... [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x0, run:0] I (23728) ESP_GMF_TASK: Waiting to run... [tsk:TSK_0x3fcba980-0x3fcba980, wk:0x0, run:0] W (23737) ESP_GMF_TASK: Already stopped, ESP_GMF_EVENT_STATE_FINISHED, [TSK_0x3fcba980,0x3fcba980] I (23747) PLAY_EMBED_MUSIC: [ 6 ] Destroy all the resources E (23755) I2C_If: Fail to write to dev 30 E (23767) i2s_common: i2s_channel_disable(1107): the channel has not been enabled yet I (23768) PLAY_EMBED_MUSIC: Func:app_main, Line:104, MEM Total:6716288 Bytes, Inter:328699 Bytes, Dram:328699 Bytes ```
To create a project from this example, run:
idf.py create-project-from-example "jason-mao/gmf_examples=0.7.0:pipeline_play_embed_music"