Hi All,
There are 2 audio codecs connect to i.MX6ULL in my application, we are trying to forward audio PCM bitstream between SAI 1/2/3. Is there anyone knows how to do that?
For example, record audio from SAI1 and redirect to SAI2 playback, at the same time, record audio from SAI2 and redirect to SAI1 playback. The sample rate are 16K Hz and 16bit word.
Currently, I use "loopback" module in PulseAudio to do it like this:
pacmd load-module module-loopback source=alsa_input.1 sink=alsa_output.2
pacmd load-module module-loopback source=alsa_input.2 sink=alsa_output.1
It works, but not perfect. The measured audio latency takes about 450ms by this method. Even if I decrease "default-fragments" and "default-fragment-size-msec" in the configuration file of PulseAudio.
So my question is, is there perfect method that can copy/forward between SAIs with lowest latency?
BRs,
-Engin
Hi @enginlee,
Hi @Dhruvit,
Thanks for giving me a hint.
We are using Linux kernel 4.14.98 with configuration CONFIG_SND_SOC_IMX_PCM_DMA=1
And the following message shown while booting kernel:
imx-sdma 20ec000.sdma: loaded firmware 3.4
mxs-dma 1804000.dma-apbh: initialized
So I guess we are go with DMA, am I right?
Or you mean using DMA transfer between SAI 1/2/3? If so, how to do it?
I can't find any detail information in i.MX reference manual, is there any example code or application note for this use scenario?
BRs,
-Engin
Hi @enginlee,
Hi @Dhruvit
Thanks for replying.
I found DMA configuration for SAI nodes inside 'imx6ul.dtsi':
sai1: sai@02028000 {
#sound-dai-cells = <0>;
compatible = "fsl,imx6ul-sai", "fsl,imx6sx-sai";
reg = <0x02028000 0x4000>;
interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks IMX6UL_CLK_SAI1_IPG>,
<&clks IMX6UL_CLK_DUMMY>,
<&clks IMX6UL_CLK_SAI1>,
<&clks IMX6UL_CLK_DUMMY>, <&clks IMX6UL_CLK_DUMMY>;
clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
dmas = <&sdma 35 24 0>,
<&sdma 36 24 0>;
dma-names = "rx", "tx";
status = "disabled";
};
sai2: sai@0202c000 {
#sound-dai-cells = <0>;
compatible = "fsl,imx6ul-sai", "fsl,imx6sx-sai";
reg = <0x0202c000 0x4000>;
interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks IMX6UL_CLK_SAI2_IPG>,
<&clks IMX6UL_CLK_DUMMY>,
<&clks IMX6UL_CLK_SAI2>,
<&clks IMX6UL_CLK_DUMMY>, <&clks IMX6UL_CLK_DUMMY>;
clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
dmas = <&sdma 37 24 0>,
<&sdma 38 24 0>;
dma-names = "rx", "tx";
status = "disabled";
};
sai3: sai@02030000 {
#sound-dai-cells = <0>;
compatible = "fsl,imx6ul-sai", "fsl,imx6
sx-sai";
reg = <0x02030000 0x4000>;
interrupts = <GIC_SPI 24 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks IMX6UL_CLK_SAI3_IPG>,
<&clks IMX6UL_CLK_DUMMY>,
<&clks IMX6UL_CLK_SAI3>,
<&clks IMX6UL_CLK_DUMMY>, <&clks IMX6UL_CLK_DUMMY>;
clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
dmas = <&sdma 39 24 0>,
<&sdma 40 24 0>;
dma-names = "rx", "tx";
status = "disabled";
};
Just like all dts files for i.MX6UL EVKs, 'imx6ul.dtsi' has been included in our board configuration.
And there are 'dmas' and 'dma-names' property in my Linux pseudo file system:
# pwd
/sys/devices/soc0/sound1/driver/sound1/subsystem/devices/2028000.sai/of_node
# ls -al
drwxr-xr-x 2 root root 0 Jul 3 02:14 .
drwxr-xr-x 14 root root 0 Jul 3 02:14 ..
-r--r--r-- 1 root root 8 Jul 3 02:14 assigned-clock-parents
-r--r--r-- 1 root root 8 Jul 3 02:14 assigned-clock-rates
-r--r--r-- 1 root root 16 Jul 3 02:14 assigned-clocks
-r--r--r-- 1 root root 28 Jul 3 02:14 clock-names
-r--r--r-- 1 root root 40 Jul 3 02:14 clocks
-r--r--r-- 1 root root 30 Jul 3 02:14 compatible
-r--r--r-- 1 root root 6 Jul 3 02:14 dma-names
-r--r--r-- 1 root root 32 Jul 3 02:14 dmas
-r--r--r-- 1 root root 0 Jul 3 02:14 fsl,sai-synchronous-rx
-r--r--r-- 1 root root 12 Jul 3 02:14 interrupts
-r--r--r-- 1 root root 4 Jul 3 02:14 linux,phandle
-r--r--r-- 1 root root 4 Jul 3 02:14 name
-r--r--r-- 1 root root 4 Jul 3 02:14 phandle
-r--r--r-- 1 root root 4 Jul 3 02:14 pinctrl-0
-r--r--r-- 1 root root 8 Jul 3 02:14 pinctrl-names
-r--r--r-- 1 root root 8 Jul 3 02:14 reg
-r--r--r-- 1 root root 5 Jul 3 02:14 status
#
So I guess we DMA is working fine with SAI driver.
Is there any method or tool we can use to find/test the audio latency?
BRs,
-Engin
Hi @enginlee,
Is there any method or tool we can use to find/test the audio latency?
=>No such tool is available for the same. If the DMA is enabled then there are fewer chances to improve latency from the CPU side.
There is little information related to audio latency in the loopback mode you are implementing in section 4.4.3 Audio latency in loopback mode from the Harpoon User's Guide.