From 41dff5d8cc8e1f1fc682171b97b75cd04b1ab76d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 3 Feb 2023 13:55:20 -0600 Subject: [PATCH] espressif: i2sout: don't needlessly set sample rate this may reduce glitches when starting samples --- ports/espressif/common-hal/audiobusio/__init__.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/espressif/common-hal/audiobusio/__init__.c b/ports/espressif/common-hal/audiobusio/__init__.c index eb35c83908..d1a695fbf3 100644 --- a/ports/espressif/common-hal/audiobusio/__init__.c +++ b/ports/espressif/common-hal/audiobusio/__init__.c @@ -223,7 +223,11 @@ void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) { audiosample_reset_buffer(self->sample, false, 0); - CHECK_ESP_RESULT(i2s_set_sample_rates(self->instance, audiosample_sample_rate(sample))); + uint32_t sample_rate = audiosample_sample_rate(sample); + if (sample_rate != self->i2s_config.sample_rate) { + CHECK_ESP_RESULT(i2s_set_sample_rates(self->instance, audiosample_sample_rate(sample))); + self->i2s_config.sample_rate = sample_rate; + } background_callback_add(&self->callback, i2s_callback_fun, self); }