-
Notifications
You must be signed in to change notification settings - Fork 13
Fix redundantly setting i2s_format #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,8 @@ typedef struct audio_instance { | |
| HMP3Decoder mp3_decoder; | ||
| mp3_instance mp3_data; | ||
| #endif | ||
|
|
||
| format i2s_format; // last configured i2s format | ||
| } audio_instance_t; | ||
|
|
||
| static audio_instance_t instance; | ||
|
|
@@ -238,9 +240,6 @@ static esp_err_t aplay_file(audio_instance_t *i, FILE *fp) | |
| { | ||
| LOGI_1("start to decode"); | ||
|
|
||
| format i2s_format; | ||
| memset(&i2s_format, 0, sizeof(i2s_format)); | ||
|
|
||
| esp_err_t ret = ESP_OK; | ||
| audio_player_event_t audio_event = { .type = AUDIO_PLAYER_REQUEST_NONE, .fp = NULL }; | ||
|
|
||
|
|
@@ -359,17 +358,17 @@ static esp_err_t aplay_file(audio_instance_t *i, FILE *fp) | |
| } | ||
|
|
||
| /* Configure I2S clock if the output format changed */ | ||
| if ((i2s_format.sample_rate != i->output.fmt.sample_rate) || | ||
| (i2s_format.channels != i->output.fmt.channels) || | ||
| (i2s_format.bits_per_sample != i->output.fmt.bits_per_sample)) { | ||
| i2s_format = i->output.fmt; | ||
| LOGI_1("format change: sr=%d, bit=%d, ch=%d", | ||
| i2s_format.sample_rate, | ||
| i2s_format.bits_per_sample, | ||
| i2s_format.channels); | ||
| i2s_slot_mode_t channel_setting = (i2s_format.channels == 1) ? I2S_SLOT_MODE_MONO : I2S_SLOT_MODE_STEREO; | ||
| ret = i->config.clk_set_fn(i2s_format.sample_rate, | ||
| i2s_format.bits_per_sample, | ||
| if ((instance.i2s_format.sample_rate != i->output.fmt.sample_rate) || | ||
| (instance.i2s_format.channels != i->output.fmt.channels) || | ||
| (instance.i2s_format.bits_per_sample != i->output.fmt.bits_per_sample)) { | ||
| instance.i2s_format = i->output.fmt; | ||
| LOGI_1("format change: sr=%d, bit=%lu, ch=%lu", | ||
| instance.i2s_format.sample_rate, | ||
| instance.i2s_format.bits_per_sample, | ||
| instance.i2s_format.channels); | ||
| i2s_slot_mode_t channel_setting = (instance.i2s_format.channels == 1) ? I2S_SLOT_MODE_MONO : I2S_SLOT_MODE_STEREO; | ||
| ret = i->config.clk_set_fn(instance.i2s_format.sample_rate, | ||
| instance.i2s_format.bits_per_sample, | ||
|
||
| channel_setting); | ||
| ESP_GOTO_ON_ERROR(ret, clean_up, TAG, "i2s_set_clk"); | ||
| } | ||
|
|
@@ -381,7 +380,7 @@ static esp_err_t aplay_file(audio_instance_t *i, FILE *fp) | |
| * to ensure playback without interruption. | ||
| */ | ||
| size_t i2s_bytes_written = 0; | ||
| size_t bytes_to_write = i->output.frame_count * i->output.fmt.channels * (i2s_format.bits_per_sample / 8); | ||
| size_t bytes_to_write = i->output.frame_count * i->output.fmt.channels * (instance.i2s_format.bits_per_sample / 8); | ||
| LOGI_2("c %d, bps %d, bytes %d, frame_count %d", | ||
| i->output.fmt.channels, | ||
| i2s_format.bits_per_sample, | ||
|
|
@@ -558,6 +557,8 @@ esp_err_t audio_player_new(audio_player_config_t config) | |
| TAG, "Failed create MP3 decoder"); | ||
| #endif | ||
|
|
||
| memset(&instance.i2s_format, 0, sizeof(instance.i2s_format)); | ||
|
|
||
| instance.running = true; | ||
| task_val = xTaskCreatePinnedToCore( | ||
| (TaskFunction_t) audio_task, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] For consistency and future support of multiple instances, consider using
i->i2s_formatinstead of the globalinstanceinside this function.