Skip to content

Commit c93ceba

Browse files
author
xutao
committed
audio_stream: fix a issue when used multiple tone stream
1 parent 390ef29 commit c93ceba

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

components/audio_stream/include/tone_stream.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct
4343
int task_stack; /*!< Task stack size */
4444
int task_core; /*!< Task running in core (0 or 1) */
4545
int task_prio; /*!< Task priority (based on freeRTOS priority) */
46+
const char *label; /*!< Label of tone stored in flash. The default value is `flash_tone`*/
4647
bool extern_stack; /*!< Task stack allocate on the extern ram */
4748
bool use_delegate; /*!< Read tone partition with esp_delegate. If task stack is on extern ram, this MUST be TRUE */
4849
} tone_stream_cfg_t;
@@ -57,12 +58,13 @@ typedef struct
5758

5859
#define TONE_STREAM_CFG_DEFAULT() \
5960
{ \
60-
.type = AUDIO_STREAM_NONE, \
61-
.buf_sz = TONE_STREAM_BUF_SIZE, \
62-
.out_rb_size = TONE_STREAM_RINGBUFFER_SIZE, \
63-
.task_stack = TONE_STREAM_TASK_STACK, \
64-
.task_core = TONE_STREAM_TASK_CORE, \
65-
.task_prio = TONE_STREAM_TASK_PRIO, \
61+
.type = AUDIO_STREAM_NONE, \
62+
.buf_sz = TONE_STREAM_BUF_SIZE, \
63+
.out_rb_size = TONE_STREAM_RINGBUFFER_SIZE,\
64+
.task_stack = TONE_STREAM_TASK_STACK, \
65+
.task_core = TONE_STREAM_TASK_CORE, \
66+
.task_prio = TONE_STREAM_TASK_PRIO, \
67+
.label = "flash_tone", \
6668
.extern_stack = TONE_STREAM_EXT_STACK, \
6769
.use_delegate = TONE_STREAM_USE_DELEGATE, \
6870
}

components/audio_stream/tone_stream.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,17 @@ typedef struct tone_stream {
4444
bool use_delegate; /*!< Tone read with delegate*/
4545
tone_partition_handle_t tone_handle; /*!< Tone partition's operation handle*/
4646
tone_file_info_t cur_file; /*!< Address to read tone file */
47+
const char *partition_label; /*!< Label of tone stored in flash */
4748
} tone_stream_t;
4849

49-
static const char *partition_label = "flash_tone";
50-
5150
static esp_err_t _tone_open(audio_element_handle_t self)
5251
{
5352
tone_stream_t *stream = (tone_stream_t *)audio_element_getdata(self);
5453
if (stream->is_open) {
5554
ESP_LOGE(TAG, "already opened");
5655
return ESP_FAIL;
5756
}
58-
stream->tone_handle = tone_partition_init(partition_label, stream->use_delegate);
57+
stream->tone_handle = tone_partition_init(stream->partition_label, stream->use_delegate);
5958
if (stream->tone_handle == NULL) {
6059
return ESP_FAIL;
6160
}
@@ -177,6 +176,12 @@ audio_element_handle_t tone_stream_init(tone_stream_cfg_t *config)
177176
stream->type = config->type;
178177
stream->use_delegate = config->use_delegate;
179178

179+
if (config->label == NULL) {
180+
ESP_LOGE(TAG, "Please set your tone label");
181+
return NULL;
182+
} else {
183+
stream->partition_label = config->label;
184+
}
180185
if (config->type == AUDIO_STREAM_READER) {
181186
cfg.read = _tone_read;
182187
} else if (config->type == AUDIO_STREAM_WRITER) {

examples/player/pipeline_flash_tone/main/play_tone_mp3_example.c

+3
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ void app_main(void)
4949
tone_stream_cfg_t tone_cfg = TONE_STREAM_CFG_DEFAULT();
5050
tone_cfg.type = AUDIO_STREAM_READER;
5151
tone_stream_reader = tone_stream_init(&tone_cfg);
52+
AUDIO_NULL_CHECK(TAG, tone_stream_reader, return);
5253

5354
ESP_LOGI(TAG, "[2.2] Create i2s stream to write data to codec chip");
5455
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
5556
i2s_cfg.type = AUDIO_STREAM_WRITER;
5657
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
58+
AUDIO_NULL_CHECK(TAG, i2s_stream_writer, return);
5759

5860
ESP_LOGI(TAG, "[2.3] Create mp3 decoder to decode mp3 file");
5961
mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG();
6062
mp3_decoder = mp3_decoder_init(&mp3_cfg);
63+
AUDIO_NULL_CHECK(TAG, mp3_decoder, return);
6164

6265
ESP_LOGI(TAG, "[2.4] Register all elements to audio pipeline");
6366
audio_pipeline_register(pipeline, tone_stream_reader, "tone");

0 commit comments

Comments
 (0)