Skip to content

Commit f86637c

Browse files
78Xiaoxia
andauthored
fix: codec unexpectedly closed by timer after open (#1046)
Co-authored-by: Xiaoxia <[email protected]>
1 parent 3630736 commit f86637c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

main/audio/audio_service.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ void AudioService::Stop() {
152152

153153
bool AudioService::ReadAudioData(std::vector<int16_t>& data, int sample_rate, int samples) {
154154
if (!codec_->input_enabled()) {
155-
codec_->EnableInput(true);
155+
esp_timer_stop(audio_power_timer_);
156156
esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000);
157+
codec_->EnableInput(true);
157158
}
158159

159160
if (codec_->input_sample_rate() != sample_rate) {
@@ -287,8 +288,9 @@ void AudioService::AudioOutputTask() {
287288
lock.unlock();
288289

289290
if (!codec_->output_enabled()) {
290-
codec_->EnableOutput(true);
291+
esp_timer_stop(audio_power_timer_);
291292
esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000);
293+
codec_->EnableOutput(true);
292294
}
293295
codec_->OutputData(task->pcm);
294296

0 commit comments

Comments
 (0)