Hello,
I am intending to extract audio from the onboard microphone of nrf5340-audio-dk.
I used the nrf5340_audio application as reference but cutting off the bluetooth and everything from there is a lot of work so I tried to build a separate small application that will extract the PCM audio through I2S from the onboard CS47L63 where the microphone is connected and encode it with LC3 and put it over UART.
Because I have some issues, I stripped the LC3 part away and I put raw PCM data over UART directly so I can test it.
The problem that I have is that the resulted audio is very very bad (ultra noisy and robotic), but I can hear myself talking to microphone (so it's not like nothing is working) but the actual output is extremely bad.
The application is building over nrf5340 audio board (so includes the DTS from there) and I have the extra:
&clock {
hfclkaudio-frequency = <12288000>;
};
&i2s0 {
status = "okay";
pinctrl-0 = <&i2s0_default>;
pinctrl-1 = <&i2s0_sleep>;
pinctrl-names = "default", "sleep";
clock-source = "ACLK";
};
&pinctrl {
uart2_default: uart2_default {
group1 {
psels = <NRF_PSEL(UART_TX, 1, 12)>,
<NRF_PSEL(UART_RX, 1, 13)>;
};
};
};
&uart2 {
status = "okay";
pinctrl-0 = <&uart2_default>;
pinctrl-names = "default";
current-speed = <1000000>;
};
And the actual important code is:
struct i2s_config cfg = {
.word_size = 16,
.channels = 2,
.format = I2S_FMT_DATA_FORMAT_I2S | I2S_FMT_DATA_ORDER_MSB,
.options = I2S_OPT_BIT_CLK_MASTER | I2S_OPT_FRAME_CLK_MASTER | I2S_OPT_BIT_CLK_CONT,
.frame_clk_freq = 16000,
.block_size = 640,
.timeout = 1000,
.mem_slab = &i2s_rx_slab
};
I added the actual initialization of the HW codec from nrf5340_audio app by copying the hw_codec h and c and also the communication driver and I did 2 changes: in the hw_codec_default_conf_enable I added the pdm microphone config by default and in the cs47l63_reg_conf.h I put