Linux Audio record play: Difference between revisions

From Variscite Wiki
No edit summary
No edit summary
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{PageHeader|DART-Mx8M - Audio Record/Play}} {{DocImage|category1=Yocto|category2=DART-MX8M}} __toc__
<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_DART-MX8M as default
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release|RELEASE_SUMO_V1.0_DART-MX8M}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#vardefine:SUPPORT_WM8904_DRC | <!--
-->    {{#switch:{{#var:HARDWARE_NAME}} | <!--
-->      DART-MX8M-PLUS = {{#ifexpr: {{#var:YOCTO_VERSION}} > 3.2 | yes | no }} | <!--
-->      {{#ifexpr: {{#var:YOCTO_VERSION}} > 3.0 | yes | no }}  <!--
-->    }} <!--
--> }} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} Audio Record/Play}} {{DocImage|category1=Yocto|category2={{#var:HARDWARE_NAME}}}} __toc__
= Get information on the Sound Cards =
= Get information on the Sound Cards =
Installed devices:
Installed devices:
<pre>
<pre>
root@imx8m-var-dart:~# cat /proc/asound/cards
# cat /proc/asound/cards
  0 [imxwm8904     ]: imx-wm8904 - imx-wm8904
  0 [wm8904audio     ]: wm8904-audio - wm8904-audio
                       imx-wm8904
                       wm8904-audio
</pre>
</pre>
List device names for playback:
List device names for playback:
<pre>
<pre>
root@imx6ul-var-dart:~# aplay -L
# aplay -L
null
null
     Discard all samples (playback) or generate zero samples (capture)
     Discard all samples (playback) or generate zero samples (capture)
pulse
pulse
     PulseAudio Sound Server
     PulseAudio Sound Server
sysdefault:CARD=imxwm8904
sysdefault:CARD=wm8904audio
     imx-wm8904,  
     wm8904-audio,  
     Default Audio Device
     Default Audio Device
</pre>
</pre>
Line 30: Line 40:
Example:
Example:
<pre>
<pre>
root@imx8m-var-dart:~# amixer set set Headphone 35
# amixer set set Headphone 35
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone',0
   Capabilities: volume pswitch
   Capabilities: volume pswitch
Line 39: Line 49:
   Front Right: 35 [56%] [-22.00dB] Playback [on]
   Front Right: 35 [56%] [-22.00dB] Playback [on]


root@imx8m-var-dart:~# aplay /usr/share/sounds/alsa/Front_Center.wav
# 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
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
</pre>
</pre>
Line 66: Line 76:
Example:
Example:
<pre>
<pre>
root@imx8m-var-dart:~# amixer set set Headphone 35
# amixer set set Headphone 35
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone',0
   Capabilities: volume pswitch
   Capabilities: volume pswitch
Line 74: Line 84:
   Front Left: 35 [56%] [-22.00dB] Playback [on]
   Front Left: 35 [56%] [-22.00dB] Playback [on]
   Front Right: 35 [56%] [-22.00dB] Playback [on]
   Front Right: 35 [56%] [-22.00dB] Playback [on]
root@imx8m-var-dart:~# amixer set 'Capture Input' ADC                                                                                                                                                        
# amixer set 'Capture Input' ADC
Simple mixer control 'Capture Input',0
Simple mixer control 'Capture Input',0
   Capabilities: enum
   Capabilities: enum
   Items: 'ADC' 'DMIC'
   Items: 'ADC' 'DMIC'
   Item0: 'ADC'
   Item0: 'ADC'
root@imx8m-var-dart:~# amixer set 'DMIC Mux' DMIC2
# amixer set 'DMIC Mux' DMIC2
Simple mixer control 'DMIC Mux',0
Simple mixer control 'DMIC Mux',0
   Capabilities: enum
   Capabilities: enum
   Items: 'DMIC1' 'DMIC2'
   Items: 'DMIC1' 'DMIC2'
   Item0: 'DMIC2'
   Item0: 'DMIC2'
root@imx6ul-var-dart:~# arecord -f cd -d 10 test.wav
# arecord -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
root@imx6ul-var-dart:~# aplay test.wav
# aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
</pre>
</pre>
Line 113: Line 123:
Example:
Example:
<pre>
<pre>
root@imx8m-var-dart:~# amixer set set Headphone 35
# amixer set set Headphone 35
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone',0
   Capabilities: volume pswitch
   Capabilities: volume pswitch
Line 121: Line 131:
   Front Left: 35 [56%] [-22.00dB] Playback [on]
   Front Left: 35 [56%] [-22.00dB] Playback [on]
   Front Right: 35 [56%] [-22.00dB] Playback [on]
   Front Right: 35 [56%] [-22.00dB] Playback [on]
root@imx8m-var-dart:~# amixer set 'Capture Input' DMIC                                                                                                                                                        
# amixer set 'Capture Input' DMIC
Simple mixer control 'Capture Input',0
Simple mixer control 'Capture Input',0
   Capabilities: enum
   Capabilities: enum
   Items: 'ADC' 'DMIC'
   Items: 'ADC' 'DMIC'
   Item0: 'DMIC'
   Item0: 'DMIC'
root@imx8m-var-dart:~# amixer set 'DMIC Mux' DMIC1
# amixer set 'DMIC Mux' DMIC1
Simple mixer control 'DMIC Mux',0
Simple mixer control 'DMIC Mux',0
   Capabilities: enum
   Capabilities: enum
   Items: 'DMIC1' 'DMIC2'
   Items: 'DMIC1' 'DMIC2'
   Item0: 'DMIC1'
   Item0: 'DMIC1'
root@imx6ul-var-dart:~# arecord -f cd -d 10 test.wav
# arecord -f cd -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
root@imx6ul-var-dart:~# aplay test.wav
# aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
</pre>
</pre>
Line 141: Line 151:
For example:
For example:
<pre>
<pre>
root@imx8m-var-dart:~# amixer
# amixer
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone',0
   Capabilities: volume pswitch
   Capabilities: volume pswitch
Line 162: Line 172:
   Front Left: 57 [90%] [0.00dB] Playback [on]
   Front Left: 57 [90%] [0.00dB] Playback [on]
   Front Right: 57 [90%] [0.00dB] Playback [on]
   Front Right: 57 [90%] [0.00dB] Playback [on]
Simple mixer control 'Line Output ZC',0        
Simple mixer control 'Line Output ZC',0
   Capabilities: pswitch                        
   Capabilities: pswitch
   Playback channels: Front Left - Front Right  
   Playback channels: Front Left - Front Right
   Mono:                                        
   Mono:
   Front Left: Playback [on]                    
   Front Left: Playback [on]
   Front Right: Playback [on]                  
   Front Right: Playback [on]
Simple mixer control 'Capture',0              
Simple mixer control 'Capture',0
   Capabilities: cvolume cswitch              
   Capabilities: cvolume cswitch
   Capture channels: Front Left - Front Right
   Capture channels: Front Left - Front Right
   Limits: Capture 0 - 31                    
   Limits: Capture 0 - 31
   Front Left: Capture 24 [77%] [on]          
   Front Left: Capture 24 [77%] [on]
   Front Right: Capture 24 [77%] [on]        
   Front Right: Capture 24 [77%] [on]
Simple mixer control 'Capture Input',0      
Simple mixer control 'Capture Input',0
   Capabilities: enum                        
   Capabilities: enum
   Items: 'ADC' 'DMIC'                        
   Items: 'ADC' 'DMIC'
   Item0: 'DMIC'
   Item0: 'DMIC'
...                          
...
</pre>
</pre>
Options:
Options:
Line 188: Line 198:
For example:
For example:
<pre>
<pre>
root@imx8m-var-dart:~# amixer sget 'Capture'                                                                                        
# amixer sget 'Capture'
Simple mixer control 'Capture',0
Simple mixer control 'Capture',0
   Capabilities: cvolume cswitch
   Capabilities: cvolume cswitch
Line 195: Line 205:
   Front Left: Capture 24 [77%] [on]
   Front Left: Capture 24 [77%] [on]
   Front Right: Capture 24 [77%] [on]
   Front Right: Capture 24 [77%] [on]
  root@imx8m-var-dart:~# amixer sset 'Capture' 25                                                                                    
# amixer sset 'Capture' 25
Simple mixer control 'Capture',0
Simple mixer control 'Capture',0
   Capabilities: cvolume cswitch
   Capabilities: cvolume cswitch
Line 205: Line 215:
Capture  currently now set to 81%.
Capture  currently now set to 81%.


= Save / restore system's audio settings =
{{#ifeq: {{#var:SUPPORT_WM8904_DRC}} | yes |
== 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 [https://statics.cirrus.com/pubs/appNote/WAN0215.pdf 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:
 
  amixer set 'DRC' on
 
To select the DRM mode, run:
 
  amixer set 'DRC Mode' 'tradition'
 
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/{{#var:DEFAULT_DTB}} under kernel source tree:
<pre>
wm8904: codec@1a {
...
num-drc-cfgs = <5>; /* must match the number of items in the following 2 lists */
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>;
...
};
</pre>
| }}
 
= Save/restore system's audio settings =
alsactl store stores all alsamixer settings into a file<br>
alsactl store stores all alsamixer settings into a file<br>
alsctl
alsctl

Revision as of 14:38, 10 October 2021

DART-MX8M Audio Record/Play

Get information on the Sound Cards

Installed devices:

# cat /proc/asound/cards
 0 [wm8904audio      ]: wm8904-audio - wm8904-audio
                      wm8904-audio

List device names for playback:

# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
sysdefault:CARD=wm8904audio
    wm8904-audio, 
    Default Audio Device

Audio Playback

Set PCM volume (main volume of audio codec), range :0-63

# amixer set Headphone 35

Play audio:

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

Example:

# amixer set 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 /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

# amixer set Headphone 35

Set capture input source to ADC

# amixer set 'Capture Input' ADC

Set DMIC Mux to DMIC2

# amixer set 'DMIC Mux' DMIC2

Record CD quality audio for 10 seconds into file test.wav

# arecord -f cd -d 10 test.wav

Play the recorded file

# aplay test.wav 

Example:

# amixer set 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 set 'Capture Input' ADC
Simple mixer control 'Capture Input',0
  Capabilities: enum
  Items: 'ADC' 'DMIC'
  Item0: 'ADC'
# amixer set 'DMIC Mux' DMIC2
Simple mixer control 'DMIC Mux',0
  Capabilities: enum
  Items: 'DMIC1' 'DMIC2'
  Item0: 'DMIC2'
# 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

Audio Record and Play, DMIC

Set Headphones volume, range :0-63

# amixer set Headphone 35

Set capture input source to DMIC

# amixer set 'Capture Input' DMIC

Set DMIC Mux to DMIC1

# amixer set 'DMIC Mux' DMIC1

Record CD quality audio for 10 seconds into file test.wav

# arecord -f cd -d 10 test.wav

Play the recorded file

# aplay test.wav 

Example:

# amixer set 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 set 'Capture Input' DMIC
Simple mixer control 'Capture Input',0
  Capabilities: enum
  Items: 'ADC' 'DMIC'
  Item0: 'DMIC'
# amixer set 'DMIC Mux' DMIC1
Simple mixer control 'DMIC Mux',0
  Capabilities: enum
  Items: 'DMIC1' 'DMIC2'
  Item0: 'DMIC1'
# 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

amixer without a parameter will show all available controls. For example:

# 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: 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   sset sID P      set contents for one mixer simple control
amixer   sget sID        get contents for one mixer simple control

For example:

# amixer 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 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%.


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