Audio Record/Play¶
Get information on the Sound Cards¶
Installed devices:
# cat /proc/asound/cards
0 [wm8904echaudio ]: simple-card - wm8904-ech-audio
wm8904-ech-audio
1 [wm8904smraudio ]: simple-card - wm8904-smr-audio
wm8904-smr-audio
List device names for playback:
# aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=wm8904echaudio
wm8904-ech-audio, 30c20000.sai-wm8904-hifi wm8904-hifi-0
Default Audio Device
sysdefault:CARD=wm8904smraudio
wm8904-smr-audio, 30c30000.sai-wm8904-hifi wm8904-hifi-0
Default Audio Device
<soundcard> that can be wm8904smraudio for codec on SMARC module and wm8904echaudio for codec on Echo-Board.
Audio Playback¶
Set PCM volume (main volume of audio codec), range :0-63
Play audio:
Example using codec on SMARC SOM:
# amixer -D hw:wm8904smraudio set Headphone 35
Simple mixer control 'Headphone',0
Capabilities: volume pswitch
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 35 [56%] [-22.00dB] Playback [on]
Front Right: 35 [56%] [-22.00dB] Playback [on]
# aplay -D plughw:wm8904smraudio /usr/share/sounds/alsa/Front_Center.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Audio Record and Play, Line-in Jack¶
Set PCM volume (main volume of audio codec), range :0-63
Set L/R capture inverting mux inputs to IN2
# amixer -D hw:<soundcard> set 'Left Capture Inverting Mux' IN2L
# amixer -D hw:<soundcard> set 'Right Capture Inverting Mux' IN2R
Set capture input source to ADC
Set DMIC Mux to DMIC2
Record CD quality audio for 10 seconds into file test.wav
Play the recorded file
Example using cocdec on SMARC SOM:
# amixer -D hw:wm8904smraudio set Headphone 35
Simple mixer control 'Headphone',0
Capabilities: volume pswitch
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 35 [56%] [-22.00dB] Playback [on]
Front Right: 35 [56%] [-22.00dB] Playback [on]
# amixer -D hw:wm8904smraudio set 'Right Capture Inverting Mux' IN2R
Simple mixer control 'Right Capture Inverting Mux',0
Capabilities: enum
Items: 'IN1R' 'IN2R' 'IN3R'
Item0: 'IN2R'
# amixer -D hw:wm8904smraudio set 'Capture Input' ADC
Simple mixer control 'Capture Input',0
Capabilities: enum
Items: 'ADC' 'DMIC'
Item0: 'ADC'
# amixer -D hw:wm8904smraudio set 'DMIC Mux' DMIC2
Simple mixer control 'DMIC Mux',0
Capabilities: enum
Items: 'DMIC1' 'DMIC2'
Item0: 'DMIC2'
# arecord -D hw:wm8904smraudio -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
# aplay -D hw:wm8904smraudio test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Audio Record and Play, DMIC¶
Set Headphones volume, range :0-63
Set capture input source to DMIC
Set DMIC Mux to DMIC1
Record CD quality audio for 10 seconds into file test.wav
Play the recorded file
Example using codec audio on SMARC SOM:
# amixer -D hw:wm8904smraudio set Headphone 35
Simple mixer control 'Headphone',0
Capabilities: volume pswitch
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 35 [56%] [-22.00dB] Playback [on]
Front Right: 35 [56%] [-22.00dB] Playback [on]
# amixer -D hw:wm8904smraudio set 'Capture Input' DMIC
Simple mixer control 'Capture Input',0
Capabilities: enum
Items: 'ADC' 'DMIC'
Item0: 'DMIC'
# amixer -D hw:wm8904smraudio set 'DMIC Mux' DMIC1
Simple mixer control 'DMIC Mux',0
Capabilities: enum
Items: 'DMIC1' 'DMIC2'
Item0: 'DMIC1'
# arecord -D hw:wm8904smraudio -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
root@imx8mp-var-dart:~# aplay -D hw:wm8904smraudio test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Advanced Controls¶
amixer -D hw:<soundcard> without a parameter will show all available controls.
For example:
# amixer -D hw:wm8904smraudio
Simple mixer control 'Headphone',0
Capabilities: volume pswitch
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 35 [56%] [-22.00dB] Playback [on]
Front Right: 35 [56%] [-22.00dB] Playback [on]
Simple mixer control 'Headphone ZC',0
Capabilities: pswitch
Playback channels: Front Left - Front Right
Mono:
Front Left: Playback [on]
Front Right: Playback [on]
Simple mixer control 'Line Output',0
Capabilities: volume pswitch
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 57 [90%] [0.00dB] Playback [on]
Front Right: 57 [90%] [0.00dB] Playback [on]
Simple mixer control 'Line Output ZC',0
Capabilities: pswitch
Playback channels: Front Left - Front Right
Mono:
Front Left: Playback [on]
Front Right: Playback [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 31
Front Left: Capture 24 [77%] [on]
Front Right: Capture 24 [77%] [on]
Simple mixer control 'Capture Input',0
Capabilities: enum
Items: 'ADC' 'DMIC'
Item0: 'DMIC'
...
Options:
amixer -D hw:<soundcard> sset sID P set contents for one mixer simple control
amixer -D hw:<soundcard> sget sID get contents for one mixer simple control
For example:
# amixer -D hw:wm8904smraudio sget 'Capture'
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 31
Front Left: Capture 24 [77%] [on]
Front Right: Capture 24 [77%] [on]
# amixer -D hw:wm8904smraudio sset 'Capture' 25
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 31
Front Left: Capture 25 [81%] [on]
Front Right: Capture 25 [81%] [on]
Capture currently now set to 81%.
Enabling the Dynamic Rate Controller (DRC)¶
The codec WM8904 provide a Dynamic Rate Controller that can be used to amplify the DMIC input using an Automatic Gain Control (AGC) configuration.
The details of how the DRC works are available in the application note WAN0215.
In latest kernels 5.4.x, dedicated patches have been introduced to provide the available parameters shown in the applications section of WAN0215.
To enable DRC, run:
To select the DRM mode, run:
The available 'DRC modes' are:
- "default": the default settings upon reset
- "peaklimiter": the signal level is unchanged for amplitudes below the knee, but sharply reduced for amplitudes above the knee. Normally the knee will be at a high amplitude e.g. around -6dB, so that the majority of the dynamic range is unchanged
- "tradition": typical traditional ALC characteristic
- "soft": used in applications where a gentler ALC characteristic is required, for example where both speech and music recording is required without reconfiguring compressor parameters
- "music": uses even gentler compression characteristics and uses a higher knee threshold to limit the gain to around 20dB
Additional modes may be added, providing the relevant registers configurations in arch/arm64/boot/dts/freescale/imx8mp-var-dart.dtsi under kernel source tree:
wm8904_smarc: codec@1a {
...
num-drc-cfgs = <5>;
drc-cfg-names = "default", "peaklimiter", "tradition", "soft", "music";
drc-cfg-regs =
/* coded default: KNEE_IP = KNEE_OP = 0, HI_COMP = LO_COMP = 1 */
<0x01af 0x3248 0x0000 0x0000>,
/* coded default: KNEE_IP = -24, KNEE_OP = -6, HI_COMP = 1/4, LO_COMP = 1 */
<0x04af 0x324b 0x0010 0x0408>,
/* coded default: KNEE_IP = -42, KNEE_OP = -3, HI_COMP = 0, LO_COMP = 1 */
<0x04af 0x324b 0x0028 0x0704>,
/* coded default: KNEE_IP = -45, KNEE_OP = -9, HI_COMP = 1/8, LO_COMP = 1 */
<0x04af 0x324b 0x0018 0x078c>,
/* coded default: KNEE_IP = -30, KNEE_OP = -10.5, HI_COMP = 1/4, LO_COMP = 1 */
<0x04af 0x324b 0x0010 0x050e>;
...
};
Save/restore system's audio settings¶
alsactl store stores all alsamixer settings into a file.
Options:
store <card> save current driver setup for one or each soundcards
to configuration file
restore <card> load current driver setup for one or each soundcards
from configuration file
Example using codec on SMARC SOM: