Linux Audio record play: Difference between revisions

From Variscite Wiki
(Created page with "{{PageHeader|DART-Mx8M - Audio Record/Play}} {{DocImage|category1=Yocto|category2=DART-MX8M}} __toc__ = Get information on the Sound Cards = Installed devices: <pre> root@imx8...")
 
No edit summary
Line 22: Line 22:
Set PCM volume (main volume of audio codec), range :0-63
Set PCM volume (main volume of audio codec), range :0-63
<pre>
<pre>
# amixer set Headphone 30
# amixer set Headphone 35
</pre>
Play audio:
Play audio:
<pre>
<pre>
Line 29: Line 30:
Example:
Example:
<pre>
<pre>
root@imx8m-var-dart:~# amixer set set Headphone 30
root@imx8m-var-dart:~# amixer set set Headphone 35
Simple mixer control 'Headphone',0
Simple mixer control 'Headphone',0
   Capabilities: volume pswitch
   Capabilities: volume pswitch
Line 35: Line 36:
   Capture channels: Front Left - Front Right
   Capture channels: Front Left - Front Right
   Limits: 0 - 63
   Limits: 0 - 63
   Front Left: 30 [48%] [-27.00dB] Playback [on]
   Front Left: 35 [56%] [-22.00dB] Playback [on]
   Front Right: 30 [48%] [-27.00dB] Playback [on]
   Front Right: 35 [56%] [-22.00dB] Playback [on]


root@imx8m-var-dart:~# aplay /usr/share/sounds/alsa/Front_Center.wav
root@imx8m-var-dart:~# aplay /usr/share/sounds/alsa/Front_Center.wav
Line 43: Line 44:


= Audio Record and Play, Line-in Jack=
= Audio Record and Play, Line-in Jack=
Set PCM volume (main volume of audio codec), range :0-63
<pre>
# amixer set Headphone 35
</pre>
Set capture input source to ADC
<pre>
# amixer set 'Capture Input' ADC
</pre>
Set DMIC Mux to DMIC2
<pre>
# amixer set 'DMIC Mux' DMIC2
</pre>
Record CD quality audio for 10 seconds into file test.wav
<pre>
# arecord -f cd -d 10 test.wav
</pre>
Play the recorded file
<pre>
# aplay test.wav
</pre>
Example:
<pre>
root@imx8m-var-dart:~# 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]
root@imx8m-var-dart:~# amixer set 'Capture Input' ADC                                                                                                                                                       
Simple mixer control 'Capture Input',0
  Capabilities: enum
  Items: 'ADC' 'DMIC'
  Item0: 'ADC'
root@imx8m-var-dart:~# amixer set 'DMIC Mux' DMIC2
Simple mixer control 'DMIC Mux',0
  Capabilities: enum
  Items: 'DMIC1' 'DMIC2'
  Item0: 'DMIC2'
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
</pre>
= Audio Record and Play, DMIC =
Set Headphones volume, range :0-63
<pre>
# amixer set Headphone 35
</pre>
Set capture input source to DMIC
<pre>
# amixer set 'Capture Input' DMIC
</pre>
Set DMIC Mux to DMIC1
<pre>
# amixer set 'DMIC Mux' DMIC1
</pre>
Record CD quality audio for 10 seconds into file test.wav
<pre>
<pre>
# amixer set 'Capture' 22
# arecord -f cd -d 10 test.wav
# arecord -f cd -d 10 test.wav
</pre>
Play the recorded file
<pre>
# aplay test.wav  
# aplay test.wav  
</pre>
</pre>
Example:
Example:
<pre>
<pre>
root@imx8m-var-dart:~# 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]
root@imx8m-var-dart:~# amixer set 'Capture Input' DMIC                                                                                                                                                       
Simple mixer control 'Capture Input',0
  Capabilities: enum
  Items: 'ADC' 'DMIC'
  Item0: 'DMIC'
root@imx8m-var-dart:~# amixer set 'DMIC Mux' DMIC1
Simple mixer control 'DMIC Mux',0
  Capabilities: enum
  Items: 'DMIC1' 'DMIC2'
  Item0: 'DMIC1'
root@imx6ul-var-dart:~# arecord -f cd -d 10 test.wav
root@imx6ul-var-dart:~# 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
Line 60: Line 141:
For example:
For example:
<pre>
<pre>
root@imx6ul-var-dart:~# amixer
root@imx8m-var-dart:~# amixer
Simple mixer control 'Master',0
Simple mixer control 'Headphone',0
   Capabilities: pvolume
   Capabilities: volume pswitch
   Playback channels: Front Left - Front Right
   Playback channels: Front Left - Front Right
   Limits: Playback 0 - 127
   Capture channels: Front Left - Front Right
   Mono:
   Limits: 0 - 63
   Front Left: Playback 125 [98%] [4.00dB]
   Front Left: 35 [56%] [-22.00dB] Playback [on]
   Front Right: Playback 125 [98%] [4.00dB]
   Front Right: 35 [56%] [-22.00dB] Playback [on]
Simple mixer control 'Master Playback ZC',0
Simple mixer control 'Headphone ZC',0
   Capabilities: pswitch
   Capabilities: pswitch
   Playback channels: Front Left - Front Right
   Playback channels: Front Left - Front Right
   Mono:
   Mono:
   Front Left: Playback [off]
   Front Left: Playback [on]
   Front Right: Playback [off]
   Front Right: Playback [on]
Simple mixer control 'Sidetone',0
Simple mixer control 'Line Output',0
  Capabilities: pvolume pvolume-joined
   Capabilities: volume pswitch
  Playback channels: Mono
   Playback channels: Front Left - Front Right
  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
   Capture channels: Front Left - Front Right
   Limits: Capture 0 - 31
   Limits: 0 - 63
   Front Left: Capture 31 [100%] [12.00dB]
   Front Left: 57 [90%] [0.00dB] Playback [on]
   Front Right: Capture 31 [100%] [12.00dB]
   Front Right: 57 [90%] [0.00dB] Playback [on]
Simple mixer control 'ADC High Pass Filter',0
Simple mixer control 'Line Output ZC',0        
   Capabilities: pswitch pswitch-joined
   Capabilities: pswitch                        
   Playback channels: Mono
   Playback channels: Front Left - Front Right 
   Mono: Playback [on]
  Mono:                                       
Simple mixer control 'Input Mux',0
   Front Left: Playback [on]                    
   Capabilities: enum
   Front Right: Playback [on]                  
  Items: 'Line In' 'Mic'
Simple mixer control 'Capture',0              
  Item0: 'Line In'
   Capabilities: cvolume cswitch             
Simple mixer control 'Output Mixer HiFi',0
   Capture channels: Front Left - Front Right 
  Capabilities: pswitch pswitch-joined
   Limits: Capture 0 - 31                     
  Playback channels: Mono
   Front Left: Capture 24 [77%] [on]         
  Mono: Playback [on]
   Front Right: Capture 24 [77%] [on]        
Simple mixer control 'Output Mixer Line Bypass',0
Simple mixer control 'Capture Input',0      
   Capabilities: pswitch pswitch-joined
   Capabilities: enum                         
   Playback channels: Mono
   Items: 'ADC' 'DMIC'                       
   Mono: Playback [off]
   Item0: 'DMIC'
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]
</pre>
</pre>
Options:
Options:
Line 132: Line 188:
For example:
For example:
<pre>
<pre>
root@imx6ul-var-dart:~# amixer sget 'Capture'                                                                                         
root@imx8m-var-dart:~# amixer sget 'Capture'                                                                                         
Simple mixer control 'Capture',0
Simple mixer control 'Capture',0
   Capabilities: cvolume
   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 31 [100%] [12.00dB]
   Front Left: Capture 24 [77%] [on]
   Front Right: Capture 31 [100%] [12.00dB]
   Front Right: Capture 24 [77%] [on]
</pre>
   root@imx8m-var-dart:~# amixer sset 'Capture' 25                                                                                       
HP DAC is a headphones DAC gain currently set to 60%.
The optional values are 0-118 equal to 0%-100%.
<pre>
   root@imx6ul-var-dart:~# amixer sset 'Capture' 25                                                                                       
Simple mixer control 'Capture',0
Simple mixer control 'Capture',0
   Capabilities: cvolume
   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 25 [81%] [3.00dB]
   Front Left: Capture 25 [81%] [on]
   Front Right: Capture 25 [81%] [3.00dB]
   Front Right: Capture 25 [81%] [on]
</pre>
</pre>
Capture  currently now set to 81%.
Capture  currently now set to 81%.

Revision as of 14:57, 9 July 2018

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 35

Play audio:

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

Example:

root@imx8m-var-dart:~# 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]

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

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:

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

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:

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

root@imx8m-var-dart:~# 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]
  root@imx8m-var-dart:~# 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