Dummy audio codec - play & record on i.MX8MM

cancel
Showing results for 
Search instead for 
Did you mean: 

Dummy audio codec - play & record on i.MX8MM

No ratings

Dummy audio codec - play & record on i.MX8MM

Several customers met problem on audio codec porting. In order to figure out cpu dai setting problem or codec dai problem. Create the dummy codec for test purpose. 

What this dummy codec can do

This dummy codec can play up to 8 channels and record up to 6 channels.

Connect SAI1 TX data pin with SAI1 RX data pin for loopback test.

Environment

Verified with i.MX8MM EVK 

Based on Linux BSP L4.14.78

Files

Kernel patch

0001-multiple-channels-dummy-audio-codec

0002-Add-capture-for-multiple-channels

User space setting

/etc/asound.conf

/usr/share/alsa/cards/aliases.con

/usr/share/alsa/cards/DUMMY.conf

Audio test content

PCM_48_16_8_160000_1_29_jazzshort.wav

The alsa command for loopback test with multiple channels 

aplay -D surround51:CARD=dummyaudio PCM_48_16_8_160000_1_29_jazzshort.wav | arecord -D surround51:CARD=dummyaudio --disable-channels --disable-format --disable-resample -f S16_LE -r 48000 -c 6 -d 5 -v test.wav

Tags (2)
Attachments
Comments

Great documentation!

How would you configure alsa to listen to audio on SAI1 channel 5 // 6 // 7 ?

Currently I guess it's only supported for channel 0,1,2,3 with surround 7.1?

Thanks for pointing in the right direction,

Jonathan.

Yes for current setting it supports only 4 data pins of SAI which is 8 channels for 7.1.

The SAI has 8 data pins configuration in kernel device tree.

I was simply including alsa configuration such as surround71.conf to have 8 channels output.

Maybe it's a hint for you.

Where is the limiting factor of only 6 input channels defined? Can this be changed? I assume I should look to imx_dummy.c?

The device tree defines only 3 SAI data pins.  With more data pins in, there can have more input channels as I understand.

Ok, I've modified the DT to:

                MX8MM_IOMUXC_SAI1_MCLK_SAI1_MCLK         0xd6
                MX8MM_IOMUXC_SAI1_RXFS_SAI1_RX_SYNC     0xd6
                MX8MM_IOMUXC_SAI1_RXC_SAI1_RX_BCLK       0xd6
                MX8MM_IOMUXC_SAI1_RXD0_SAI1_RX_DATA0  0xd6
                MX8MM_IOMUXC_SAI1_RXD5_SAI1_RX_DATA5  0xd6
                MX8MM_IOMUXC_SAI1_RXD6_SAI1_RX_DATA6   0xd6
                MX8MM_IOMUXC_SAI1_RXD7_SAI1_RX_DATA7   0xd6

And I've changed DUMMY.conf:

DUMMY.pcm.surround51.0 {
@args [ CARD ]
@args.CARD {
type string
}
#type plug
slave.pcm {
type hw
card $CARD
}
slave.channels 6
type route
ttable.0.0 1
ttable.1.1 1
ttable.2.10 1
ttable.3.11 1
ttable.4.12 1
ttable.5.13 1
}

Then I try to record:

arecord -D surround51:CARD=dummyaudio1 -f cd --rate 48000 -d 10 test.wav

But I get an error:

ALSA lib pcm_route.c:1192:(_snd_pcm_route_load_ttable) Invalid slave channel: 10
arecord: main:828: audio open error: Invalid argument

I noticed any channel above 5 does not work :smileysad:

Not sure what's exact problem. Saw you have 6 channels setting. The record command doesn't assign channel number. Maybe it's able to adjust channel number for arecord to see if setting problem.

MaxTsai‌ Hi Max, I also use dummy codec and I customized as your documents, but I run "arecord -D sysdefault:CARD=dummy-audio" or "aplay --device=sysdefault:CARD=dummy-audio", it always shows: 

ALSA lib ../../alsa-lib-1.1.5/src/confmisc.c:767:(parse_card) cannot find card 'dummy-audio'
ALSA lib ../../alsa-lib-1.1.5/src/conf.c:4554:(_snd_config_evaluate) function snd_func_card_driver returned error: No such device
ALSA lib ../../alsa-lib-1.1.5/src/confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib ../../alsa-lib-1.1.5/src/conf.c:4554:(_snd_config_evaluate) function snd_func_concat returned error: No such device
ALSA lib ../../alsa-lib-1.1.5/src/confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib ../../alsa-lib-1.1.5/src/conf.c:4554:(_snd_config_evaluate) function snd_func_refer returned error: No such device
ALSA lib ../../alsa-lib-1.1.5/src/conf.c:5033:(snd_config_expand) Evaluate error: No such device
ALSA lib ../../../alsa-lib-1.1.5/src/pcm/pcm.c:2552:(snd_pcm_open_noupdate) Unknown PCM sysdefault:CARD=dummy-audio

Could you please send me some advices?

Thanks a lot.

From the log, “cannot find card 'dummy-audio'”.

Seems the dummy-audio card is not created successfully.

You may check it first by “aplay -l”.

card 1: AFmain [AF-main], device 0: NXP I3D IVSHMEM PCM [pcm-16]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: AFvoice [AF-voice], device 0: NXP I3D IVSHMEM PCM [pcm-2]
Subdevices: 1/1
Subdevice #0: subdevice #0

The BSP looks like I3D BSP and the dummy card is not created. Please check your device tree.

Great thanks.

error log show in my demo board when I aplay test.wav, the logs shows as below.

[ 676.486207] fsl-sai 30010000.sai: failed to derive required Rx rate: 1536000
[ 676.493286] fsl-sai 30010000.sai: ASoC: can't set 30010000.sai hw params: -22
[ 676.500665] fsl-sai 30010000.sai: failed to derive required Rx rate: 1536000
[ 676.507743] fsl-sai 30010000.sai: ASoC: can't set 30010000.sai hw params: -22
[ 676.515121] fsl-sai 30010000.sai: failed to derive required Rx rate: 1536000
[ 676.522198] fsl-sai 30010000.sai: ASoC: can't set 30010000.sai hw params: -22
[ 676.534227] fsl-sai 30010000.sai: failed to derive required Tx rate: 1536000
[ 676.541459] fsl-sai 30010000.sai: ASoC: can't set 30010000.sai hw params: -22

I use your play command  will  show error as well, could you please help check where the problem is?

Great thanks!

aplay -D surround51:CARD=dummyaudio t.wav

Seems your test.wav required special rate but failed. Please try a fixed sample rate or use my attached wave file.

[ 676.486207] fsl-sai 30010000.sai: failed to derive required Rx rate: 1536000

Thanks for you replay!

This error always happen whatever play or record, the log I show you is just aplay command.

I saw there only 2 channels setting in your tdm slot, is it correct? because the error is fsl_sai.c is the clk setting error.

I guess the channel not align with the clk setting, I add some log in fsl_sai.c. the log as below.

1. code for tdm slot settting in imx-dummy.c

ret = snd_soc_dai_set_tdm_slot(cpu_dai,
BIT(channels) - 1, BIT(channels) - 1,
2, params_physical_width(params));

2.add log in fsl_sai.c where the error log.

static int fsl_sai_set_bclk(struct snd_soc_dai *dai, bool tx, u32 freq)
519 {
520 struct fsl_sai *sai = snd_soc_dai_get_drvdata(dai);
521 unsigned char offset = sai->soc->reg_offset;
522 unsigned long clk_rate;
523 unsigned int reg = 0;
524 u32 ratio, savesub = freq, saveratio = 0, savediv = 0;
525 u32 id;
526 int ret = 0;
527
528 /* Don't apply to slave mode */
529 if (sai->slave_mode[tx])
530 return 0;
531
532 fsl_sai_check_ver(dai);
533
534 for (id = 0; id < FSL_SAI_MCLK_MAX; id++) {
535 clk_rate = clk_get_rate(sai->mclk_clk[id]);
536 if (!clk_rate)
537 continue;
538
539 ratio = clk_rate / freq;
540
541 ret = clk_rate - ratio * freq;
542
543 dev_err(dai->dev, "###### clk_rate %ld ratio: %ld freq: %ld ret: %ld\n",
544 clk_rate, ratio, freq, ret);
545 /*
546 * Drop the source that can not be
547 * divided into the required rate.
548 */
549 if (ret != 0 && clk_rate / ret < 1000)
550 continue;

3.the log when I paly and record with cmd, t.wav is the file you attached.

aplay -D surround40:CARD=dummyaudio t.wav | arecord -D surround51:CARD=dummyaudio --disable-channels --disable-format --disable-resample -f S16_LE -r 48000 -c 6 -d 5 -v test.wav

Playing WAVE 't.wav' : [ 2895.436717] fsl-sai 30010000.sai: ###### clk_rate 50000000 ratio: 8 freq: 6144000 ret: 848000
Signed 16 bit Little Endian, Rate[ 2895.446424] fsl-sai 30010000.sai: failed to derive required Tx rate: 6144000
48000 Hz, Channels 8
Recording [ 2895.456918] fsl-sai 30010000.sai: ASoC: can't set 30010000.sai hw params: -22
WAVE 'test.wav' : Signed 16 bit L[ 2895.466442] fsl-sai 30010000.sai: ###### clk_rate 50000000 ratio: 8 freq: 6144000 ret: 848000
ittle Endian, Rate 48000 Hz, Chan[ 2895.477791] fsl-sai 30010000.sai: failed to derive required Rx rate: 6144000
nels 6
aplay: set_params:1403: U[ 2895.487699] fsl-sai 30010000.sai: ASoC: can't set 30010000.sai hw params: -22
nable to install hw params:
ACCESS: RW_INTERLEAVED
FORMAT: arecord: set_params:1403: S16_LE
SUBFORMAT: Unable to install hw params: STD
SAMPLE_BITS:
16
FRAME_BITS: 128ACCESS:
CHANNELS: 8
RW_INTERLEAVEDRATE:
48000FORMAT:
PERIOD_TIME: S16_LE(42666 42667)

SUBFORMAT: PERIOD_SIZE: 2048STD

PERIOD_BYTES: SAMPLE_BITS: 3276816

PERIODS: FRAME_BITS: 496

BUFFER_TIME: CHANNELS: (170666 170667)6

BUFFER_SIZE: RATE: 819248000

BUFFER_BYTES: PERIOD_TIME: 131072(28437 28438)

TICK_TIME: PERIOD_SIZE: 01365

PERIOD_BYTES: 16380
PERIODS: 4
BUFFER_TIME: 113750
BUFFER_SIZE: 5460
BUFFER_BYTES: 65520
TICK_TIME: 0

Version history
Revision #:
1 of 1
Last update:
‎07-04-2019 02:36 AM
Updated by: