Skip to content

Commit

Permalink
further fixes in (modified) adf-sdk to support finish on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gnumpi committed Jun 14, 2024
1 parent 7ec8951 commit 817e9bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
13 changes: 7 additions & 6 deletions esphome/components/adf_pipeline/speaker/esp_adf_speaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static const char *const TAG = "esp_adf.speaker";

void ADFSpeaker::setup() {
ESP_LOGCONFIG(TAG, "Setting up ESP ADF Speaker...");
pipeline.set_finish_timeout_ms(100);
pipeline.set_finish_timeout_ms(10000);
}

void ADFSpeaker::dump_config() {
Expand Down Expand Up @@ -68,11 +68,12 @@ size_t ADFSpeaker::play(const uint8_t *data, size_t length) {
ESP_LOGE(TAG, "Failed to play audio, speaker is in failed state.");
return 0;
}
/*
if (this->state_ != speaker::STATE_RUNNING && this->state_ != speaker::STATE_STARTING) {
this->start();

if (this->state_ != speaker::STATE_RUNNING) {
ESP_LOGW(TAG, "Trying to play audio while speaker not running.");
return 0;
}
*/

size_t remaining = length;
size_t index = 0;
while (remaining > 0) {
Expand All @@ -93,7 +94,7 @@ void ADFSpeaker::request_pipeline_settings_(){
request.sampling_rate = 16000;
request.bit_depth = 16;
request.number_of_channels = 1;
request.finish_on_timeout = 5000; //ms
request.finish_on_timeout = 1000; //ms
request.target_volume = 1.;
if (!this->pipeline.request_settings(request)) {
esph_log_e(TAG, "Requested audio settings, didn't get accepted");
Expand Down
9 changes: 4 additions & 5 deletions esphome/components/i2s_audio/adf_pipeline/adf_i2s_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ bool ADFElementI2SOut::init_adf_elements_() {
.uninstall_drv = false,
.need_expand = i2s_config.bits_per_sample != I2S_BITS_PER_SAMPLE_16BIT,
.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT,
.finish_on_timeout = this->finish_on_timeout_ms_ > 0,
.finish_on_timeout = false, //don't set it yet, set it in the preparation phase instead
};

this->adf_i2s_stream_writer_ = i2s_stream_init(&i2s_cfg);
this->adf_i2s_stream_writer_->buf_size = 1 * 1024;

this->install_i2s_driver(i2s_config);
if( this->finish_on_timeout_ms_ > 0 ){
audio_element_set_input_timeout(this->adf_i2s_stream_writer_, this->finish_on_timeout_ms_ / portTICK_PERIOD_MS);
}

audio_element_set_input_timeout(this->adf_i2s_stream_writer_, 1000 / portTICK_PERIOD_MS);
this->finish_on_timeout_ms_ = 0;

#ifdef I2S_EXTERNAL_DAC
if (this->external_dac_ != nullptr){
Expand Down Expand Up @@ -133,6 +131,7 @@ void ADFElementI2SOut::on_settings_request(AudioPipelineSettingsRequest &request
esph_log_d(TAG, "Setting finish_on_timout to (ms): %d", request.finish_on_timeout);
this->finish_on_timeout_ms_ = request.finish_on_timeout;
i2s_stream_t *i2s = (i2s_stream_t *) audio_element_getdata(this->adf_i2s_stream_writer_);
esph_log_d(TAG, "finish on timeout was: %s",i2s->finish_on_timeout ? "true":"false");
i2s->finish_on_timeout = this->finish_on_timeout_ms_ > 0;
audio_element_set_input_timeout(this->adf_i2s_stream_writer_, this->finish_on_timeout_ms_ / portTICK_PERIOD_MS);
}
Expand Down
3 changes: 3 additions & 0 deletions esphome/components/i2s_audio/adf_pipeline/i2s_stream_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ static esp_err_t _i2s_open(audio_element_handle_t self)
return ESP_OK;
}

/*
if (i2s->type == AUDIO_STREAM_WRITER) {
audio_element_set_input_timeout(self, 10 / portTICK_RATE_MS);
ESP_LOGI(TAG, "AUDIO_STREAM_WRITER");
}
*/
i2s->is_open = true;
if (i2s->use_alc) {
i2s->volume_handle = alc_volume_setup_open();
Expand Down Expand Up @@ -275,6 +277,7 @@ static int _i2s_process(audio_element_handle_t self, char *in_buffer, int in_len
#endif
{
if( i2s->finish_on_timeout ){
ESP_LOGI(TAG, "Sending finish status after time out occurred." );
audio_element_report_status(self, AEL_STATUS_STATE_FINISHED);
return 0;
}
Expand Down

0 comments on commit 817e9bd

Please sign in to comment.