imx8mm i2s have audio data lost when playback >=192k pcm signal

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

imx8mm i2s have audio data lost when playback >=192k pcm signal

1,132 Views
Brady
Contributor I

Hi Developer,

When debug the high resolution audio playback there have very clear noise from imx8mm I2S output, we can see there have i2s data drop during the playback, the high resolution the more data lost.

we can confirm the audio data is correct and the "feed" audio data speed is egough=>no underrun. we consider the problem is from "snd_pcm_writei".
 
details.
we used SAI3 and here i attach the dts on SAI3.
&sai3 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sai3>;
assigned-clocks = <&clk IMX8MM_CLK_SAI3>;
assigned-clock-parents = <&clk IMX8MM_AUDIO_PLL1_OUT>;
clocks = <&clk IMX8MM_CLK_SAI1_IPG>, <&clk IMX8MM_CLK_DUMMY>,
<&clk IMX8MM_CLK_SAI3_ROOT>, <&clk IMX8MM_CLK_DUMMY>,
<&clk IMX8MM_CLK_DUMMY>, <&clk IMX8MM_AUDIO_PLL1_OUT>,
<&clk IMX8MM_AUDIO_PLL2_OUT>;
assigned-clock-rates = <49152000>,<45158400>;
clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3", "pll8k", "pll11k";
status = "okay";
};
 
and the alsa card is init to block mode details check below:
 
snd_pcm_open(&playback_handle_pcm, "default", SND_PCM_STREAM_PLAYBACK, 0);
snd_pcm_hw_params_malloc(&hw_params_pcm);
snd_pcm_hw_params_any(playback_handle_pcm, hw_params_pcm);
snd_pcm_hw_params_set_access(playback_handle_pcm, hw_params_pcm, SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(playback_handle_pcm, hw_params_pcm, (snd_pcm_format_t)fromat);
snd_pcm_hw_params_set_rate_near(playback_handle_pcm, hw_params_pcm, (unsigned int *)&sampleRate, 0);
periodsize = 480 * 100 * 8; //set alsa buffer to 4bytes * 32(peirod) * 100 = less than 100ms
chunk_size_pcm = 480; //set peirod size to 32
snd_pcm_hw_params_set_buffer_size_near(playback_handle_pcm, hw_params_pcm, &periodsize);
snd_pcm_hw_params_set_period_size_near(playback_handle_pcm, hw_params_pcm, &chunk_size_pcm, 0);
snd_pcm_hw_params_get_period_size(hw_params_pcm, &chunk_size_pcm, 0);
snd_pcm_hw_params_get_buffer_size(hw_params_pcm, &periodsize);
ALOGI("chunk_size_pcm:" GREEN "%ld %ld" NONE "\r\n", chunk_size_pcm,periodsize);
snd_pcm_hw_params_set_channels(playback_handle_pcm, hw_params_pcm, curChannelsPCM);
snd_pcm_hw_params(playback_handle_pcm, hw_params_pcm);
snd_pcm_hw_params_get_period_size(hw_params_pcm, &chunk_size_pcm, 0);
snd_pcm_hw_params_free(hw_params_pcm);
snd_pcm_prepare(playback_handle_pcm);
 
the input audio format is S32 and actually 16bit or 24bit data, come to kernel the sysclk and fromat i have checked correctly set. and the issue could be from kernel alsa core?
 
please help me, This issue almost kill me...
 
here is the issue happen picture you can see the i2s audio data is corrupted.
微信图片_20220905191945.jpg微信图片_20220905191954.jpg
Labels (1)
0 Kudos
Reply
4 Replies

1,058 Views
xiaocong_fu
NXP Employee
NXP Employee

Problem solved with following change. We can close this ticket.

&sai3 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sai3>;
assigned-clocks = <&clk IMX8MM_CLK_SAI3_SRC>,
<&clk IMX8MM_CLK_SAI3_DIV>;
assigned-clock-parents = <&clk IMX8MM_AUDIO_PLL1_OUT>;
clocks = <&clk IMX8MM_CLK_SAI3_IPG>, <&clk IMX8MM_CLK_DUMMY>,
<&clk IMX8MM_CLK_SAI3_ROOT>, <&clk IMX8MM_CLK_DUMMY>,
<&clk IMX8MM_CLK_DUMMY>, <&clk IMX8MM_AUDIO_PLL1_OUT>,
<&clk IMX8MM_AUDIO_PLL2_OUT>;
assigned-clock-rates = <0>,<49152000>;
clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3", "pll8k", "pll11k";
status = "okay";
};

0 Kudos
Reply

1,100 Views
Brady
Contributor I

Hi Developer,

I would like to update the latest status there.

the playback i2s issue is always there including 44.1k,48k. if the sample rate up to 176.4khz or higher we can hear the noise. 

- during my test, i have test continuely write fixed data with snd_pcm_writei and i can see if set card "hw 0:0" to 48k takes 1.024~1.025 sec to finish 48k frame data write. I use block mode and period seize 512 buffer size 8192. Then i do measure I2S output of IMX8MM the L/R clock is stable 48khz and bclk stable 3.072M. I guess something must be wrong with the SAI3 from kernel. on the other words SAI3 playback 48k frame audio data while application do not fill 48k audio data.

- with above similar setup, if playback 768k, the data from i2s lost around 8%, and snd_pcm_writei logic compelete wrong it can only write 700k frame in 1 sec.

 

       

 

0 Kudos
Reply

1,107 Views
Brady
Contributor I

I have try a specifial task keep block writing data with snd_pcm_writei, i keep writing 0x01,0x02 for example then i measured the i2s out the data corrupt still there. so the issue is from snd_pcm_writei down layer...

0 Kudos
Reply

1,107 Views
Brady
Contributor I
with snd_pcm_hw_params_set_buffer_size_min i can increase the alsa buffer size to 1024*256. 
but no help, so the problem looks like from alsa core?
please. 
0 Kudos
Reply