esp-adf icon indicating copy to clipboard operation
esp-adf copied to clipboard

audio_element_getinfo returns wrong info (only correct AFTER audio pipeline plays) (AUD-5657)

Open parabuzzle opened this issue 1 year ago • 1 comments

Environment

  • Audio development kit: CUSTOM
  • Audio kit version (for ESP32-LyraT/ESP32-LyraT-Mini/ESP32-S3-Korvo-2): N/A
  • [Required] Module or chip used: ESP32-WROVER-IE-N16R8
  • [Required] IDF version (run git describe --tags in $IDF_PATH folder to find it): v5.2.2
  • [Required] ADF version (run git describe --tags in $ADF_PATH folder to find it):v2.6-159-gdac74d81
  • Build system: idf.py
  • [Required] Running log:
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x3f (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1372
ho 0 tail 12 room 4
load:0x40078000,len:13576
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3044
entry 0x4008057c
I (420) cpu_start: Multicore app
I (421) quad_psram: This chip is ESP32-D0WD
I (422) esp_psram: Found 8MB PSRAM device
I (423) esp_psram: Speed: 80MHz
I (427) esp_psram: PSRAM initialized, cache is in low/high (2-core) mode.
W (434) esp_psram: Virtual address not enough for PSRAM, map as much as we can. 4MB is mapped
I (958) esp_psram: SPI SRAM memory test OK
I (990) cpu_start: Pro cpu start user code
I (990) cpu_start: cpu freq: 240000000 Hz
I (990) heap_init: Initializing. RAM available for dynamic allocation:
I (995) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (1001) heap_init: At 3FFBA160 len 00025EA0 (151 KiB): DRAM
I (1007) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (1014) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1020) heap_init: At 4009F344 len 00000CBC (3 KiB): IRAM
I (1027) esp_psram: Adding pool of 4096K of PSRAM memory to heap allocator
I (1035) spi_flash: detected chip: gd
I (1038) spi_flash: flash io: dio
I (1043) main_task: Started on CPU0
I (1053) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (1053) main_task: Calling app_main()
I (4063) ib_sd: Initializing SD card
I (8773) ib_routine_handler: Updating routines
I (10443) ib_trigger_handler: Updating triggers
I (13873) ib_relays: Initializing 8 relays
I (68433) ib_trigger_handler: Button Triggered!
I (68443) ib_routine_handler: Running routine 784gu
I (68613) ib_audio: Receive music info from decoder, sample_rates=44100, bits=16, ch=2, bps=0, duration=0, uri=/sdcard/MEDIA/The%20Game%20of%20Love.flac
W (69933) ib_routine_handler: Task is running, stopping it now
I (70593) ib_trigger_handler: Button Triggered!
I (70603) ib_routine_handler: Running routine 784gu
I (70863) ib_audio: Receive music info from decoder, sample_rates=88200, bits=16, ch=2, bps=0, duration=322148, uri=/sdcard/MEDIA/The%20Game%20of%20Love.flac
W (71393) ib_routine_handler: Task is running, stopping it now
  • Compiler version (run xtensa-esp32-elf-gcc --version in your project folder to find it): xtensa-esp-elf-gcc.exe (crosstool-NG esp-13.2.0_20230928) 13.2.0
  • Operating system: Windows
  • (Windows only) Environment type: ESP Command Prompt
  • Using an IDE?: YES - VSCode with esp-idf plugin
  • Power supply: External 3.3V

Problem Description

using audio_element_getinfo to set the clk speed doesn't return the correct file info until after it attempts to play the audio pipeline.

Expected Behavior

calling audio_element_getinfo returns the correct info for the file (sample_rate=88200, duration=322148, etc)

Actual Behavior

calling audio_element_getinfo returns the default bitrate the first time and is missing info. Once running the pipeline (at the wrong bitrate) it is correct. It seems that the audio_element_getinfo is only updated AFTER the audio pipeline is run.

Steps to Reproduce

  1. Setup a flac decoder pipeline to read off of an sdcard
  2. get the music info and notice it's wrong
  3. play the audio pipeline (notice its not playing correctly)
  4. get the music info again.. and see its correct

Code to Reproduce This Issue

Ripped out of working application.. may not be fully complete.. but I think the gist is here

#include "esp_log.h"
#include "flac_decoder.h"
#include "i2s_stream.h"
#include "fatfs_stream.h"
#include "audio_pipeline.h"
#include "audio_common.h"
#include "audio_event_iface.h"
 
static audio_pipeline_handle_t player;
static audio_element_handle_t i2s_stream_writer, flac_decoder, fatfs_stream_reader;


void app_main()
{
 i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
  i2s_stream_writer = i2s_stream_init(&i2s_cfg);

  flac_decoder_cfg_t flac_cfg = DEFAULT_FLAC_DECODER_CONFIG();
  flac_cfg.out_rb_size = 1024 * 8; // need to increase this buffer size for FLAC for HQ audio
  flac_decoder = flac_decoder_init(&flac_cfg);

  fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT();
  fatfs_cfg.type = AUDIO_STREAM_READER;
  fatfs_cfg.buf_sz = 1024 * 8;
  fatfs_cfg.ext_stack = true;
  fatfs_cfg.out_rb_size = 1024 * 8;
  fatfs_stream_reader = fatfs_stream_init(&fatfs_cfg);

  audio_element_set_uri(fatfs_stream_reader, fp);
  audio_element_set_uri(decoder, fp);

  audio_element_run(decoder);
  audio_element_run(fatfs_stream_reader);
  audio_element_run(i2s_stream_writer);

  audio_pipeline_register(player, fatfs_stream_reader, "fatfs");
  audio_pipeline_register(player, i2s_stream_writer, "i2s");
  audio_pipeline_register(player, flac_decoder, "flac");

  ESP_LOGD(TAG, "Linking audio elements");
  audio_pipeline_link(player, (const char *[]){"fatfs", "flac", "i2s"}, 3);

  audio_element_info_t music_info = {0};
  audio_element_getinfo(decoder, &music_info);

  ESP_LOGI(TAG, "Receive music info from decoder, sample_rates=%d, bits=%d, ch=%d, bps=%d, duration=%d, uri=%s",
           music_info.sample_rates, music_info.bits, music_info.channels, music_info.bps, music_info.duration, music_info.uri);
  audio_element_setinfo(i2s_stream_writer, &music_info);
  i2s_stream_set_clk(i2s_stream_writer, music_info.sample_rates, music_info.bits, music_info.channels);

  audio_pipeline_run(player);

  audio_pipeline_wait_for_stop(player);

  audio_element_getinfo(decoder, &music_info);

  ESP_LOGI(TAG, "Receive music info from decoder, sample_rates=%d, bits=%d, ch=%d, bps=%d, duration=%d, uri=%s",
           music_info.sample_rates, music_info.bits, music_info.channels, music_info.bps, music_info.duration, music_info.uri);
  audio_element_setinfo(i2s_stream_writer, &music_info);
  i2s_stream_set_clk(i2s_stream_writer, music_info.sample_rates, music_info.bits, music_info.channels);

  audio_pipeline_run(player);

  audio_pipeline_wait_for_stop(player);
}

parabuzzle avatar Aug 30 '24 21:08 parabuzzle

@parabuzzle You can refer to the ADF example 'pipeline_play_sdcard_music'. Music information can only be obtained when receive the msg 'AEL_MSG_CMD_REPORT_MUSIC_INFO'.

majingjing123 avatar Sep 03 '24 09:09 majingjing123

This topic has become inactive, so I'm closing the issue. Please reopen it if you have any questions or need any further assistance.

jason-mao avatar Dec 10 '24 07:12 jason-mao