Development Environment: ubuntu12.04 Development Board: ok6410, linux3.0
Alsamixer is one of the Alsa tools for Linux audio architecture. It is used to configure various audio parameters.
Alsamixer is based on the graphic interface under the text. You can easily set the desired volume and switch a switch by using the upper and lower keys on the keyboard, left and right keys, and so on, on the ubuntu12.04 system configuration interface, the operation is very simple. Here we use the line-in function of ubuntu12.04 (to implement the stereo function ):
Audio playback output channel settings:
Audio input device channel settings:
I tested the line-in function of ubuntu12.04, so I chose line as the audio input channel.
Amixer is the alsamixer text mode, that is, the command line mode. You need to use the amixer command to configure the various options of your sound card, you may directly modify the Linux kernel audio driver source code to meet your needs. For example, if you choose whether the audio input channel is mic input or line input, you need to modify the wm9714 register, however, amixer can modify the register value of the audio chip from the application layer and decide to use mic input or line input. This greatly simplifies the difficulty of code modification. After all, it is easier to directly modify Linux kernel ALSA.
To use amixer, you must first understand the parameters you want to set before you can understand how to configure the corresponding values. In general, compared with alsamixer, it is a bit cumbersome. The following describes the specific usage:
1. First, let's take a look at what commands are supported by amixer and what functions are available.
#Amixer -- Help
Usage: amixer <Options> [command]
Available options:
-H, -- help this help
-C, -- card n select the card
-D, -- Device N select the device, default 'default'
-D, -- debug mode
-N, -- nocheck do not perform range checking
-V, -- version print version of this program
-Q, -- quiet Be quiet
-I, -- inactive show also inactive controls
-A, -- Abstract l select distinct action level (none or basic)
-S, -- stdin read and execute commands from stdin sequentially
Available commands:
Scontrols show all mixer simple controls
Scontents show contents of all mixer simple controls (default command)
Sset Sid p set contents for one mixer simple control
Sget Sid get contents for one mixer simple control
ControlsShow all controls for given card
ContentsShow contents of all controls for given card
Cset CID p set control contents for one control
Cget CID get control contents for one control
2. Check that your audio system (different audio drivers correspond to different content and operation interfaces) provides interfaces for you to operate.
You can run the following command to determine the number of interfaces provided in the driver:
Amixer Contents
View, such:
[Root @ forlinx6410] #./amixer controls
Numid = 49, iface = mixer, name = 'headphone mixer aux playback volume'
Numid = 43, iface = mixer, name = 'headphone mixer beep playback volume'
Numid = 32, iface = mixer, name = 'headphone playback ZC switch'
Numid = 4, iface = mixer, name = 'headphone playback switch'
Numid = 3, iface = mixer, name = 'headphone playback volume'
Numid = 6, iface = mixer, name = 'PCM playback volume'
Numid = 5, iface = mixer, name = 'line in volume'
××××××××××××××××××××××××××××××××××××××××××× ××××××××
For all configuration valuesAmixer ContentsPrint:
[Root @ forlinx6410] #./amixer Contents
Numid = 49, iface = mixer, name = 'headphone mixer aux playback volume'
; Type = integer, access = RW --- r --, values = 1, min = 0, max = 7, step = 0
: Values = 5
| Dbscale-min =-15.00db, step = 3.00db, mute = 0
Numid = 43, iface = mixer, name = 'headphone mixer beep playback volume'
; Type = integer, access = RW --- r --, values = 1, min = 0, max = 7, step = 0
: Values = 5
| Dbscale-min =-15.00db, step = 3.00db, mute = 0
Numid = 32, iface = mixer, name = 'headphone playback ZC switch'
; Type = Boolean, access = RW ------, values = 2
: Values = Off, off
...
3. Understand how to set a parameter
To sum up, you must first use get commands to understand the interfaces, and then use the set commands to set the values you want to set.
To set a certain volume, for example, to set the line-in input above, 'Line in volume 'is displayed in controls:
Numid = 5, iface = mixer, name = 'line in volume'
Then, you can first look at the current value:
[Root @ forlinx6410] #./amixer cget numid = 5, iface = mixer, name = 'line in volume'
Numid = 5, iface = mixer, name = 'line in volume'
; Type = integer, access = RW --- r --, values = 2, min = 0, max = 31, step = 0
: Values = 23,23
| Dbscale-min =-34.50db, step = 1.50db, mute = 0
The maximum volume is 31. If you want to set it to 25, use cset to set it:
#Amixer cset numid = 5, iface = mixer, name = 'line in volume '25
[Root @ forlinx6410] # ../amixer cset numid = 5, iface = mixer, name = 'line in volume '25
Numid = 5, iface = mixer, name = 'line in volume'
; Type = integer, access = RW --- r --, values = 2, min = 0, max = 31, step = 0
: Values = 25, 25
| Dbscale-min =-34.50db, step = 1.50db, mute = 0
[Note]:
The cget/cset commands described above:
Controls show all controls for given card
Contents show contents of all controls for given card
Cset CID p set control contents for one control
Cget CID get control contents for one control
Similarly, there is another set of sget/sset commands to implement simple parameter settings. Generally, scontrols and scontents can be used to meet your needs.
Scontrols show all mixer simple controls
Scontents show contents of all mixer simple controls (default command)
Sset Sid p set contents for one mixer simple control
Sget Sid get contents for one mixer simple control
This is also the same practice, for example:
[Root @ forlinx6410] #./amixer scontrols
Simple mixer control 'headphone', 0
Simple mixer control 'headphone mixer aux ', 0
Simple mixer control 'headphone mixer beep ', 0
Simple mixer control 'headphone playback zc', 0
Simple mixer control 'tone', 0
Simple mixer control 'tone cut-off', 0
Simple mixer control 'bass ', 0
Simple mixer control 'bass control', 0
Simple mixer control 'bass cut-off', 0
Simple mixer control 'PCM ', 0
Simple mixer control 'sidetone MUX ', 0
Simple mixer control 'line in', 0 ----------- (here is the parameter for setting the line-in volume, which is the same as the line-in volume setting above)
Simple mixer control 'mic 1', 0
Simple mixer control 'mic 1 prestamp', 0
Simple mixer control 'mic 2', 0
Simple mixer control 'mic 2 prestamp', 0
Simple mixer control 'mic A source', 0
Simple mixer control 'mic B source', 0
...
Simple mixer control 'left capture source', 0 (this is important. Select the left audio source input)
Simple mixer control 'right capture source', 0 (right audio source input)
...
Likewise,Amixer scontentsTo view all the current values, which are not listed here.
In addition, to view or configure sget, for example:
[Root @ forlinx6410] #./amixer sget 'left capture source', 0
Simple mixer control 'left capture source', 0
Capabilities: Enum
Items: 'mic 1' 'mic 2' line ''' mono in ''headphone ''' speaker ''mono out''' ZH'
Item0: 'mic 1'
If you want to modify the corresponding settings, use amixer sset. The specific usage is as follows:
Amixer sset Sid (control string) P (A value supported)
The SID is the string next to the simple mixer control, for example, 'left capture source,
[Root @ forlinx6410] #./amixer sset 'left capture source', 0 line
Simple mixer control 'left capture source', 0
Capabilities: Enum
Items: 'mic 1' 'mic 2' line ''' mono in ''headphone ''' speaker ''mono out''' ZH'
Item0: 'line'
Then, set the right-channel Input Source to line-in:
[Root @ forlinx6410] #./amixer sset 'right capture source', 0 line
Simple mixer control 'right capture source', 0
Capabilities: Enum
Items: 'mic 1' 'mic 2' line ''' mono in ''headphone ''' speaker ''mono out''' ZH'
Item0: 'line'
In this way, your device can use the line-in function for recording.
Run the following command:
[Root @ forlinx6410] #./Arecord-f CD-C 1-t wav my-file.wav.
Recording wave 'my-file.wav ': signed 16 Bit little endian, rate 44100Hz, Mono
Start line-in recording.-C 1 indicates single-channel recording and 2 indicates stereo recording.
Play the recorded audio file:
. [Root @ forlinx6410] #./aplay my-file.wav
Playing wave 'my-file.wav ': signed 16 Bit little endian, rate 44100Hz, Mono
OK. The sound is very clear.
How can we use the tool provided by ALSA to easily control the sound card parameters? In addition, ALSA can simulate the OSS audio architecture, currently, the OSS architecture is used for playing and recording qtopia sound in the Linux System of the ok6410 Development Board. Therefore, the OSS configuration is checked in the Kernel configuration of the Development Board.