14.11.2 Mixer Device Objects

File-like interface

close( )
This method closes the open mixer device file. Any further attempts to use the mixer after this file is closed will raise an IOError.

fileno( )
Returns the file handle number of the open mixer device file.

Mixer interface

controls( )
This method returns a bitmask specifying the available mixer controls (``Control'' being a specific mixable ``channel'', such as SOUND_MIXER_PCM or SOUND_MIXER_SYNTH). This bitmask indicates a subset of all available mixer channels--the SOUND_MIXER_* constants defined at module level. To determine if, for example, the current mixer object supports a PCM mixer, use the following Python code:

mixer=ossaudiodev.openmixer()
if mixer.channels() & (1 << ossaudiodev.SOUND_MIXER_PCM):
	# PCM is supported
	<code>

For most purposes, the SOUND_MIXER_VOLUME (Master volume) and SOUND_MIXER_PCM channels should suffice--but code that uses the mixer should be flexible when it comes to choosing sound channels. On the Gravis Ultrasound, for example, SOUND_MIXER_VOLUME does not exist.

stereocontrols( )
Returns a bitmask indicating stereo mixer channels. If a bit is set, the corresponding channel is stereo; if it is unset, the channel is either monophonic or not supported by the mixer (use in combination with channels() to determine which).

See the code example for the channels() function for an example of getting data from a bitmask.

reccontrols( )
Returns a bitmask specifying the mixer controls that may be used to record. See the code example for controls() for an example of reading from a bitmask.

get( channel)
Returns the volume of a given mixer channel. The returned volume is a 2-tuple (left_volume,right_volume). Volumes are specified as numbers from 0 (silent) to 100 (full volume). If the channel is monophonic, a 2-tuple is still returned, but both channel volumes are the same.

If an unknown channel is specified, error is raised.

set( channel, (left, right))
Sets the volume for a given mixer channel to (left,right). left and right must be ints and between 0 (silent) and 100 (full volume). On success, the new volume is returned as a 2-tuple. Note that this may not be exactly the same as the volume specified, because of the limited resolution of some soundcard's mixers.

Raises IOError if an invalid mixer channel was specified; TypeError if the argument format was incorrect, and error if the specified volumes were out-of-range.

get_recsrc( )
This method returns a bitmask indicating which channel or channels are currently being used as a recording source.

set_recsrc( bitmask)
Call this function to specify a recording source. Returns a bitmask indicating the new recording source (or sources) if successful; raises IOError if an invalid source was specified. To set the current recording source to the microphone input:

mixer.setrecsrc (1 << ossaudiodev.SOUND_MIXER_MIC)

See About this document... for information on suggesting changes.