4.3 Mixer Objects

Mixer objects provides access to the ALSA mixer API.

class Mixer( [control], [id], [cardname])
control - specifies which control to manipulate using this mixer object. The list of available controls can be found with the alsaaudio.mixers function. The default value is 'Master' - other common controls include 'Master Mono', 'PCM', 'Line', etc.

id - the id of the mixer control. Default is 0

cardname - specifies which card should be used (this is only relevant if you have more than one sound card). Omit to use the default sound card

Mixer objects have the following methods:

cardname( )
Return the name of the sound card used by this Mixer object

mixer( )
Return the name of the specific mixer controlled by this object, For example 'Master' or 'PCM'

mixerid( )
Return the ID of the ALSA mixer controlled by this object.

switchcap( )
Returns a list of the switches which are defined by this specific mixer. Possible values in this list are:

Switch Description
'Mute' This mixer can be muted
'Joined Mute' This mixer can mute all channels at the same time
'Playback Mute' This mixer can mute the playback output
'Joined Playback Mute' Mute playback for all channels at the same time
'Capture Mute' Mute sound capture
'Joined Capture Mute' Mute sound capture for all channels at a time
'Capture Exclusive' Not quite sure what this is

To manipulate these swithes use the setrec or setmute methods

volumecap( )
Returns a list of the volume control capabilities of this mixer. Possible values in the list are:

Capability Description
'Volume' This mixer can control volume
'Joined Volume' This mixer can control volume for all channels at the same time
'Playback Volume' This mixer can manipulate the playback volume
'Joined Playback Volume' Manipulate playback volumne for all channels at the same time
'Capture Volume' Manipulate sound capture volume
'Joined Capture Volume' Manipulate sound capture volume for all channels at a time

getvolume( [direction])
Returns a list with the current volume settings for each channel. The list elements are integer percentages.

The optional direction argument can be either 'playback' or 'capture', which is relevant if the mixer can control both playback and capture volume. The default value is 'playback' if the mixer has this capability, otherwise 'capture'

getmute( )
Return a list indicating the current mute setting for each channel. 0 means not muted, 1 means muted.

This method will fail if the mixer has no playback switch capabilities.

getrec( )
Return a list indicating the current record mute setting for each channel. 0 means not recording, 1 means not recording.

This method will fail if the mixer has no capture switch capabilities.

setvolume( volume,[channel],[direction])
Change the current volume settings for this mixer. The volume argument controls the new volume setting as an integer percentage.

If the optional argument channel is present, the volume is set only for this channel. This assumes that the mixer can control the volume for the channels independently.

The optional direction argument can be either 'playback' or 'capture' is relevant if the mixer has independent playback and capture volume capabilities, and controls which of the volumes if changed. The default is 'playback' if the mixer has this capability, otherwise 'capture'.

setmute( mute, [channel])
Sets the mute flag to a new value. The mute argument is either 0 for not muted, or 1 for muted.

The optional channel argument controls which channel is muted. The default is to set the mute flag for all channels.

This method will fail if the mixer has no playback mute capabilities

setrec( capture,[channel])
Sets the capture mute flag to a new value. The capture argument is either 0 for no capture, or 1 for capture.

The optional channel argument controls which channel is changed. The default is to set the capture flag for all channels.

This method will fail if the mixer has no capture switch capabilities

A Note on the ALSA Mixer API

The ALSA mixer API is extremely complicated - and hardly documented at all. alsaaudio implements a much simplified way to access this API. In designing the API I've had to make some choices which may limit what can and cannot be controlled through the API. However, If I had chosen to implement the full API, I would have reexposed the horrible complexity/documentation ratio of the underlying API. At least the alsaaudio API is easy to understand and use.

If my design choises prevents you from doing something that the underlying API would have allowed, please let me know, so I can incorporate these need into future versions.

If the current state of affairs annoy you, the best you can do is to write a HOWTO on the API and make this available on the net. Until somebody does this, the availability of ALSA mixer capable devices will stay quite limited.

Unfortunately, I'm not able to create such a HOWTO myself, since I only understand half of the API, and that which I do understand has come from a painful trial and error process.