Run audio pipeline with offset in bytes position

chr1st0s
Posts: 15
Joined: Fri Nov 01, 2019 10:05 am

Run audio pipeline with offset in bytes position

Postby chr1st0s » Thu Jan 16, 2020 10:15 pm

Hi,

We are currently playing an audio track using the following ADF pipeline:

FatFS Stream Reader :arrow: AAC Decoder :arrow: Equalizer :arrow: I2S Stream Writer

but we cannot get the audio to start with an offset, e.g. 200000 bytes from the beginning of the track.

The code without the start position offset looks like this:

Code: Select all

// This is a snippet. All variables are local to this code block and we exit this block only when the audio finishes.

// FatFS stream reader
fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT();
fatfs_cfg.type = AUDIO_STREAM_READER;
fat_reader = fatfs_stream_init(&fatfs_cfg);
audio_element_set_uri(fat_reader, "/sdcard/track123");
audio_pipeline_register(file_pipeline, fat_reader, "fat");

// AAC Decoder
aac_decoder_cfg_t aac_cfg = DEFAULT_AAC_DECODER_CONFIG();
audio_decoder = aac_decoder_init(&aac_cfg);
audio_pipeline_register(file_pipeline, audio_decoder, "aac");

// Equalizer
equalizer_cfg_t eq_cfg = DEFAULT_EQUALIZER_CONFIG();
int set_gain[] = { -13, 7, 7, 4, 0, -7, -5, -1, 4, 3, -13, 7, 7, 4, 0, -7, -5, -1, 4, 3 };
eq_cfg.channel = 2;
eq_cfg.task_core = 1;
eq_cfg.task_stack = (8 * 1024);
eq_cfg.set_gain = set_gain;
equalizer = equalizer_init(&eq_cfg);
audio_pipeline_register(file_pipeline, equalizer, "equalizer");

// I2S stream writer
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_cfg.i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
audio_pipeline_register(file_pipeline, i2s_stream_writer, "i2s");

// Link the pipeline
audio_pipeline_link(file_pipeline, (const char *[]) {"fat", "aac", "equalizer", "i2s"}, 4);

// Set-up an event listener
audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG();
audio_event_iface_handle_t evt = audio_event_iface_init(&evt_cfg);
audio_pipeline_set_listener(file_pipeline, evt);

// Start audio
audio_pipeline_run(file_pipeline);

// Then we scan for events and setting up the equalizer info, which works fine
// When the audio finishes, we terminate the pipeline, unregister the elements, destroy event listeners and deinit the pipeline
Now, I add the following lines before the FatFS stream reader, hoping to shift the start position by 2303964 bytes:

Code: Select all

// ... code as in previous snipet
fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT();
fatfs_cfg.type = AUDIO_STREAM_READER;
fat_reader = fatfs_stream_init(&fatfs_cfg);
audio_element_info_t info;
audio_element_getinfo(fat_reader, &info);
info.byte_pos = 2303964;
audio_element_setinfo(fat_reader, &info);
audio_element_set_uri(fat_reader, "/sdcard/track123");
audio_pipeline_register(file_pipeline, fat_reader, "fat");
// ... code as in previous snippet
There is no error, but the decoder detects the track as RAW AAC instead of AAC and no sound is playing. Still, the pipeline turns off once the track finishes.

Do you know what I might be missing here?

Thank you in advance
Christos

jason.mao
Posts: 96
Joined: Mon Nov 19, 2018 2:05 am

Re: Run audio pipeline with offset in bytes position

Postby jason.mao » Tue Mar 24, 2020 10:45 am

Hi Christos,

The code look like is ok.
Could you testing your code without `Equalizer` once?

Thanks.

Who is online

Users browsing this forum: No registered users and 30 guests