Linux Audio record play
From Variscite Wiki
DART-Mx8M - Audio Record/Play
Get information on the Sound Cards
Installed devices:
root@imx8m-var-dart:~# cat /proc/asound/cards 0 [imxwm8904 ]: imx-wm8904 - imx-wm8904 imx-wm8904
List device names for playback:
root@imx6ul-var-dart:~# aplay -L null Discard all samples (playback) or generate zero samples (capture) pulse PulseAudio Sound Server sysdefault:CARD=imxwm8904 imx-wm8904, Default Audio Device
Audio Playback
Set PCM volume (main volume of audio codec), range :0-63
# amixer set Headphone 30 Play audio: <pre> # aplay /usr/share/sounds/alsa/Front_Center.wav
Example:
root@imx8m-var-dart:~# amixer set set Headphone 30 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: 30 [48%] [-27.00dB] Playback [on] Front Right: 30 [48%] [-27.00dB] Playback [on] root@imx8m-var-dart:~# aplay /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
# amixer set 'Capture' 22 # arecord -f cd -d 10 test.wav # aplay test.wav
Example:
root@imx6ul-var-dart:~# arecord -f cd -d 10 test.wav Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo root@imx6ul-var-dart:~# aplay test.wav Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Advanced Controls
amixer without a parameter will show all available controls. For example:
root@imx6ul-var-dart:~# amixer Simple mixer control 'Master',0 Capabilities: pvolume Playback channels: Front Left - Front Right Limits: Playback 0 - 127 Mono: Front Left: Playback 125 [98%] [4.00dB] Front Right: Playback 125 [98%] [4.00dB] Simple mixer control 'Master Playback ZC',0 Capabilities: pswitch Playback channels: Front Left - Front Right Mono: Front Left: Playback [off] Front Right: Playback [off] Simple mixer control 'Sidetone',0 Capabilities: pvolume pvolume-joined Playback channels: Mono Limits: Playback 0 - 3 Mono: Playback 3 [100%] [-6.00dB] Simple mixer control 'Mic',0 Capabilities: cswitch cswitch-joined Capture channels: Mono Mono: Capture [off] Simple mixer control 'Mic Boost',0 Capabilities: volume volume-joined Playback channels: Mono Capture channels: Mono Limits: 0 - 1 Mono: 0 [0%] [0.00dB] Simple mixer control 'Playback Deemphasis',0 Capabilities: pswitch pswitch-joined Playback channels: Mono Mono: Playback [off] Simple mixer control 'Capture',0 Capabilities: cvolume Capture channels: Front Left - Front Right Limits: Capture 0 - 31 Front Left: Capture 31 [100%] [12.00dB] Front Right: Capture 31 [100%] [12.00dB] Simple mixer control 'ADC High Pass Filter',0 Capabilities: pswitch pswitch-joined Playback channels: Mono Mono: Playback [on] Simple mixer control 'Input Mux',0 Capabilities: enum Items: 'Line In' 'Mic' Item0: 'Line In' Simple mixer control 'Output Mixer HiFi',0 Capabilities: pswitch pswitch-joined Playback channels: Mono Mono: Playback [on] Simple mixer control 'Output Mixer Line Bypass',0 Capabilities: pswitch pswitch-joined Playback channels: Mono Mono: Playback [off] Simple mixer control 'Output Mixer Mic Sidetone',0 Capabilities: pswitch pswitch-joined Playback channels: Mono Mono: Playback [off] Simple mixer control 'Store DC Offset',0 Capabilities: pswitch pswitch-joined Playback channels: Mono Mono: Playback [off]
Options:
amixer sset sID P set contents for one mixer simple control amixer sget sID get contents for one mixer simple control
For example:
root@imx6ul-var-dart:~# amixer sget 'Capture' Simple mixer control 'Capture',0 Capabilities: cvolume Capture channels: Front Left - Front Right Limits: Capture 0 - 31 Front Left: Capture 31 [100%] [12.00dB] Front Right: Capture 31 [100%] [12.00dB]
HP DAC is a headphones DAC gain currently set to 60%. The optional values are 0-118 equal to 0%-100%.
root@imx6ul-var-dart:~# amixer sset 'Capture' 25 Simple mixer control 'Capture',0 Capabilities: cvolume Capture channels: Front Left - Front Right Limits: Capture 0 - 31 Front Left: Capture 25 [81%] [3.00dB] Front Right: Capture 25 [81%] [3.00dB]
Capture currently now set to 81%.
Save / restore system's audio settings
alsactl store stores all alsamixer settings into a file
alsctl
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:
# alsactl store -f 123.conf # alsactl restore -f 123.conf