Skip to content

Commit 8b4e51d

Browse files
committed
i2s: add workaround for i2s apll clock at 44100Hz 16-bit 2ch
1 parent 4f888b6 commit 8b4e51d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

main/src/chip/i2s.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
#include "freertos/FreeRTOS.h"
1111
#include "driver/i2s.h"
12+
#include "soc/rtc.h"
1213

1314
#define TAG "i2s"
1415

15-
static int i2s0_sample_rate = 44100;
16+
static int i2s0_sample_rate = 48000;
1617
static int i2s0_bits_per_sample = 16;
1718

1819
void i2s0_init(void)
@@ -44,7 +45,13 @@ void i2s0_init(void)
4445
void i2s0_set_sample_rate(int rate)
4546
{
4647
if (rate != i2s0_sample_rate) {
47-
i2s_set_sample_rates(I2S_NUM_0, rate);
48+
// workaround as i2s apll clock is inaccurate at 44100Hz 16-bit 2ch
49+
if (rate == 44100) {
50+
rtc_clk_apll_enable(1, 15, 8, 5, 6);
51+
ESP_LOGW(TAG, "enable workaround for i2s apll clock at 44100Hz 16-bit 2ch");
52+
} else {
53+
i2s_set_sample_rates(I2S_NUM_0, rate);
54+
}
4855
i2s0_sample_rate = rate;
4956
}
5057
}

0 commit comments

Comments
 (0)