Skip to content

Audio Record/Play

NOTE: Hardware Changes – Audio Codec Update

Due to End-of-Life (EOL), the Cirrus Logic WM8731 audio codec has been replaced by the Cirrus Logic WM8904.

Variscite is updating all relevant software repositories and recommends impacted users to upgrade to the latest software version or to update their U-Boot and kernel to the latest commit ID of the branch they are already based on.

For details, see the changelogs:

Get Information on the Sound Cards

Installed Sound Cards

To check the installed devices for different codecs, use:

cat /proc/asound/cards

Example outputs:

  • WM8731 codec:
 0 [ASRCM2M        ]: fsl-asrc-m2m - ASRC-M2M
                      ASRC-M2M
 1 [wm8731audio    ]: simple-card - wm8731audio
                      wm8731audio
  • WM8904 codec:
 0 [ASRCM2M        ]: fsl-asrc-m2m - ASRC-M2M
                      ASRC-M2M
 1 [wm8904audio    ]: simple-card - wm8904audio
                      wm8904audio

List Available Playback Devices

To list playback device names, use:

aplay -L

Example outputs:

  • WM8731 codec:
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=wm8731audio
    wm8731audio, sai-tx-rx-wm8731-hifi wm8731-hifi-0
    Default Audio Device
  • WM8904 codec:
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=wm8904audio
    wm8904audio, sai-tx-rx-wm8904-hifi wm8904-hifi-0
    Default Audio Device

Audio Playback

Set PCM Volume

The main volume of the audio codec can be adjusted using amixer. The volume range varies by codec:

  • WM8731 codec: 0-127

  • WM8904 codec: 0-63

To set the maximum volume for each codec, use:

amixer -D hw:wm8731audio set Master 127       # For WM8731
amixer -D hw:wm8904audio set Headphone 63     # For WM8904

For WM8731, also enable the output mixer:

amixer -D hw:wm8731audio set 'Output Mixer HiFi' 'on'

Play Audio

To play a sample audio file:

aplay -D hw:wm8731audio /usr/share/sounds/alsa/Front_Center.wav
aplay -D hw:wm8904audio /usr/share/sounds/alsa/Front_Center.wav

Example Outputs

  • WM8731 codec:
amixer -D hw:wm8731audio set Master 125
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]
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
  • WM8904 codec:
amixer -D hw:wm8904audio set Headphone 63
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: 63 [100%] [6.00dB] Playback [on]
  Front Right: 63 [100%] [6.00dB] Playback [on]
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)

Set Capture Volume

To adjust the recording volume, use:

  • WM8731 codec:
amixer -D hw:wm8731audio set 'Capture' 23
  • WM8904 codec:
amixer -D hw:wm8904audio set 'Capture' 31

Record and Playback Audio

To record 10 seconds of audio and play it back:

arecord -D sysdefault:CARD=<soundcard> -f cd -d 10 test.wav
aplay test.wav

Example Outputs

  • WM8731 codec:
arecord  -D sysdefault:CARD=wm8731audio -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
aplay -D sysdefault:CARD=wm8731audio test.wav                                                                                                                                                                                   
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
  • WM8904 codec:
arecord  -D sysdefault:CARD=wm8904audio -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
aplay -D hw:wm8904audio test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

Advanced Controls

Running amixer without parameters will show all available controls.

For example:

  • WM8731 codec:
amixer -D hw:wm8731audio
Simple mixer control 'Master',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 119 [94%] [-2.00dB]
  Front Right: Playback 119 [94%] [-2.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]
...
  • WM8904 codec:
amixer -D hw:wm8904audio
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: 63 [100%] [6.00dB] Playback [on]
  Front Right: 63 [100%] [6.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]
...

Get and Set Control Values

Use the following amixer commands to check and adjust mixer controls (from amixer --help):

amixer -D hw:wm8904audio sset sID P      # Set contents for one mixer simple control
amixer -D hw:wm8904audio sget sID        # Get contents for one mixer simple control

Example: Checking Capture Volume

  • WM8731 codec:
amixer -D hw:wm8731audio sget 'Capture'                                                                                                                                                                                         
Simple mixer control 'Capture',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 31
  Front Left: Capture 23 [74%] [0.00dB]
  Front Right: Capture 23 [74%] [0.00dB]
  • WM8904 codec:
amixer -D hw:wm8904audio sget 'Capture'                                                                                                                                                                                         
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 31
  Front Left: Capture 31 [100%] [on]
  Front Right: Capture 31 [100%] [on]

Example: Setting Capture Volume to 81%

  • WM8731 codec:
amixer -D hw:wm8731audio 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]
  • WM8904 codec:
amixer -D hw:wm8904audio 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]

Headphone DAC Gain (WM8731) and Output Control (WM8904)

For WM8731, the HP DAC gain is set using 'Capture' (range 0 - 118 for 0-100%).

For WM8904, the Headphone and Line Output volume can be controlled with:

amixer -D hw:wm8904audio sset 'Headphone' 63  # 100% volume
amixer -D hw:wm8904audio sset 'Line Output' 57  # 90% volume

Example output:

amixer -D hw:wm8904audio sget 'Headphone'                                                                                                                                                                                       
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: 63 [100%] [6.00dB] Playback [on]
  Front Right: 63 [100%] [6.00dB] Playback [on]

Save / Restore System's Audio Settings

The alsactl command can be used to save and restore all ALSA mixer settings. This works for any supported audio codec, including WM8731 and WM8904.

To save the current ALSA configuration:

alsactl --no-ucm store -f 123.conf wm8731audio       # For WM8731
alsactl --no-ucm store -f 123.conf wm8904audio       # For WM8904

To restore a previously saved configuration:

alsactl --no-ucm restore -f 123.conf wm8731audio     # For WM8731
alsactl --no-ucm restore -f 123.conf wm8904audio     # For WM8904

This allows audio settings to remain persistent across reboots or resets.

Options

  store     <card>   Save current driver setup for one or all sound cards
                     to a configuration file.
  restore   <card>   Load the saved driver setup from a configuration file.