Audio test

From Variscite Wiki
DART-6UL/VAR-SOM-MX7 - Audio Record/Play

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 [wm8731audio    ]: wm8731-audio - wm8731-audio
                      wm8731-audio
  • WM8904 codec:
 0 [wm8904audio    ]: simple-card - wm8904-audio
                      wm8904-audio

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
    wm8731-audio, 
    Default Audio Device
  • WM8904 codec:
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=wm8904audio
    wm8904-audio, 308a0000.sai-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 set Master 127       # For WM8731
# amixer set Headphone 63     # For WM8904

For WM8731, also enable the output mixer:

# amixer set 'Output Mixer HiFi' on

Play Audio

To play a sample audio file:

# aplay /usr/share/sounds/alsa/Front_Center.wav

Example Outputs

  • WM8731 codec:
# amixer 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 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 set 'Capture' 22
  • WM8904 codec:
# amixer set 'Capture' 31

Record and Playback Audio

To record 10 seconds of audio and play it back:

# arecord -f cd -d 10 test.wav
# aplay test.wav

Example Outputs

  • WM8731 codec:
# arecord -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
# aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
  • WM8904 codec:
# arecord -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
# aplay 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
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 '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]
...
  • WM8904 codec:
# amixer
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 '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]
...

Get and Set Control Values

Use the following commands to check and adjust mixer controls:

amixer   sset sID P      # Set contents for one mixer simple control
amixer   sget sID        # Get contents for one mixer simple control

Example: Checking Capture Volume

  • WM8731 codec:
# 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]
  • WM8904 codec:
# amixer 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 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 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 sset 'Headphone' 63  # 100% volume
# amixer sset 'Line Output' 57  # 90% volume

Example output:

# amixer 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 store -f 123.conf

To restore a previously saved configuration:

# alsactl restore -f 123.conf

This allows that audio settings 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.