Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 1 | \section{\module{ossaudiodev} --- |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 2 | Access to OSS-compatible audio devices} |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 3 | |
| 4 | \declaremodule{builtin}{ossaudiodev} |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 5 | \platform{Linux, FreeBSD} |
| 6 | \modulesynopsis{Access to OSS-compatible audio devices.} |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 7 | |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 8 | % XXX OSS is standard for Linux and FreeBSD -- what about NetBSD? |
| 9 | % OpenBSD? others? |
| 10 | This module allows you to access the OSS (Open Sound System) audio |
| 11 | interface. OSS is available for a wide range of open-source and |
| 12 | commercial Unices, and is the standard audio interface for Linux (up to |
| 13 | kernel 2.4) and FreeBSD. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 14 | |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 15 | \begin{seealso} |
| 16 | \seetitle[http://www.opensound.com/pguide/oss.pdf] |
| 17 | {Open Sound System Programmer's Guide} |
| 18 | {the official documentation for the OSS C API} |
| 19 | \seetext{The module defines a large number of constants supplied by |
| 20 | the OSS device driver; see \file{<sys/soundcard.h>} on either |
| 21 | Linux or FreeBSD for a listing .} |
| 22 | \end{seealso} |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 23 | |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 24 | \module{ossaudiodev} defines the following variables and functions: |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 25 | |
| 26 | \begin{excdesc}{error} |
Greg Ward | f882c77 | 2003-03-10 03:05:21 +0000 | [diff] [blame] | 27 | This exception is raised on certain errors. The argument is a string |
| 28 | describing what went wrong. |
| 29 | |
| 30 | (If \module{ossaudiodev} receives an error from a system call such as |
| 31 | \cfunction{open()}, \cfunction{write()}, or \cfunction{ioctl()}, it |
| 32 | raises \exception{IOError}. Errors detected directly by |
| 33 | \module{ossaudiodev} result in \exception{ossaudiodev.error}.) |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 34 | \end{excdesc} |
| 35 | |
| 36 | \begin{funcdesc}{open}{\optional{device, }mode} |
Greg Ward | f882c77 | 2003-03-10 03:05:21 +0000 | [diff] [blame] | 37 | Open an audio device and return an OSS audio device object. This |
| 38 | object supports many file-like methods, such as \method{read()}, |
| 39 | \method{write()}, and \method{fileno()} (although there are subtle |
| 40 | differences between conventional Unix read/write semantics and those of |
| 41 | OSS audio devices). It also supports a number of audio-specific |
| 42 | methods; see below for the complete list of methods. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 43 | |
Greg Ward | f882c77 | 2003-03-10 03:05:21 +0000 | [diff] [blame] | 44 | Note the unusual calling syntax: the \emph{first} argument is optional, |
| 45 | and the second is required. This is a historical artifact for |
| 46 | compatibility with the older \module{linuxaudiodev} module which |
| 47 | \module{ossaudiodev} supersedes. % XXX it might also be motivated |
| 48 | % by my unfounded-but-still-possibly-true belief that the default |
| 49 | % audio device varies unpredictably across operating systems. -GW |
| 50 | |
| 51 | \var{device} is the audio device filename to use. If it is not |
| 52 | specified, this module first looks in the environment variable |
| 53 | \envvar{AUDIODEV} for a device to use. If not found, it falls back to |
| 54 | \file{/dev/dsp}. |
| 55 | |
| 56 | \var{mode} is one of \code{'r'} for read-only (record) access, |
| 57 | \code{'w'} for write-only (playback) access and \code{'rw'} for both. |
| 58 | Since many soundcards only allow one process to have the recorder or |
| 59 | player open at a time it is a good idea to open the device only for the |
| 60 | activity needed. Further, some soundcards are half-duplex: they can be |
| 61 | opened for reading or writing, but not both at once. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 62 | \end{funcdesc} |
| 63 | |
Greg Ward | cd930f5 | 2003-03-10 03:18:19 +0000 | [diff] [blame] | 64 | \begin{funcdesc}{openmixer}{\optional{device}} |
Greg Ward | f882c77 | 2003-03-10 03:05:21 +0000 | [diff] [blame] | 65 | Open a mixer device and return an OSS mixer device object. |
| 66 | \var{device} is the mixer device filename to use. If it is |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 67 | not specified, this module first looks in the environment variable |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 68 | \envvar{MIXERDEV} for a device to use. If not found, it falls back to |
Greg Ward | cd930f5 | 2003-03-10 03:18:19 +0000 | [diff] [blame] | 69 | \file{/dev/mixer}. |
Greg Ward | f882c77 | 2003-03-10 03:05:21 +0000 | [diff] [blame] | 70 | |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 71 | \end{funcdesc} |
| 72 | |
| 73 | \subsection{Audio Device Objects \label{ossaudio-device-objects}} |
| 74 | |
| 75 | Setting up the device |
| 76 | |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 77 | To set up the device, three functions must be called in the correct |
| 78 | sequence: |
Greg Ward | 074472b | 2003-03-10 00:24:42 +0000 | [diff] [blame] | 79 | \begin{enumerate} |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 80 | \item \method{setfmt()} to set the output format, |
| 81 | \item \method{channels()} to set the number of channels, and |
| 82 | \item \method{speed()} to set the sample rate. |
Greg Ward | 074472b | 2003-03-10 00:24:42 +0000 | [diff] [blame] | 83 | \end{enumerate} |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 84 | |
| 85 | The audio device objects are returned by \function{open()} define the |
| 86 | following methods: |
| 87 | |
| 88 | \begin{methoddesc}[audio device]{close}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 89 | This method explicitly closes the device. It is useful in situations |
| 90 | where deleting the object does not immediately close it since there are |
| 91 | other references to it. A closed device should not be used again. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 92 | \end{methoddesc} |
| 93 | |
| 94 | \begin{methoddesc}[audio device]{fileno}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 95 | Returns the file descriptor associated with the device. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 96 | \end{methoddesc} |
| 97 | |
| 98 | \begin{methoddesc}[audio device]{read}{size} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 99 | Reads \var{size} samples from the audio input and returns them as a |
| 100 | Python string. The function blocks until enough data is available. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 101 | \end{methoddesc} |
| 102 | |
| 103 | \begin{methoddesc}[audio device]{write}{data} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 104 | Writes Python string \var{data} to the audio device and returns the |
| 105 | number of bytes written. If the audio device is opened in blocking |
| 106 | mode, the entire string is always written. If the device is opened in |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 107 | nonblocking mode, some data may not be written---see |
| 108 | \method{writeall()}. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 109 | \end{methoddesc} |
| 110 | |
| 111 | \begin{methoddesc}[audio device]{writeall}{data} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 112 | Writes the entire Python string \var{data} to the audio device. If the |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 113 | device is opened in blocking mode, behaves identially to |
| 114 | \method{write()}; in nonblocking mode, waits until the device becomes |
| 115 | available before feeding it more data. Returns \code{None}, since the |
| 116 | amount of data written is always equal to the amount of data supplied. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 117 | \end{methoddesc} |
| 118 | |
| 119 | Simple IOCTLs: |
| 120 | |
| 121 | \begin{methoddesc}[audio device]{nonblock}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 122 | Attempts to put the device into nonblocking mode. Once in nonblocking |
| 123 | mode there is no way to return to blocking mode. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 124 | |
| 125 | Raises \exception{IOError} if the IOCTL failed. |
| 126 | \end{methoddesc} |
| 127 | |
| 128 | \begin{methoddesc}[audio device]{getfmts}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 129 | Returns a bitmask of the audio output formats supported by the |
| 130 | soundcard. On a typical Linux system, these formats are: |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 131 | |
Greg Ward | 074472b | 2003-03-10 00:24:42 +0000 | [diff] [blame] | 132 | \begin{tableii}{l|l}{constant}{Format}{Description} |
| 133 | \lineii{AFMT_MU_LAW} |
| 134 | {a logarithmic encoding. This is the default format on |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 135 | \file{/dev/audio} and is the format used by Sun .au files.} |
Greg Ward | 074472b | 2003-03-10 00:24:42 +0000 | [diff] [blame] | 136 | \lineii{AFMT_A_LAW} |
| 137 | {a logarithmic encoding} |
| 138 | \lineii{AFMT_IMA_ADPCM} |
| 139 | {a 4:1 compressed format defined by the Interactive Multimedia |
| 140 | Association.} |
| 141 | \lineii{AFMT_U8} |
| 142 | {Unsigned, 8-bit audio.} |
| 143 | \lineii{AFMT_S16_LE} |
| 144 | {Unsigned, 16-bit audio, little-endian byte order (as used by |
| 145 | Intel processors)} |
| 146 | \lineii{AFMT_S16_BE} |
| 147 | {Unsigned, 16-bit audio, big-endian byte order (as used by 68k, |
| 148 | PowerPC, Sparc)} |
| 149 | \lineii{AFMT_S8} |
| 150 | {Signed, 8 bit audio.} |
| 151 | \lineii{AFMT_U16_LE} |
| 152 | {Signed, 16-bit little-endian audio} |
| 153 | \lineii{AFMT_U16_BE} |
| 154 | {Signed, 16-bit big-endian audio} |
| 155 | \end{tableii} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 156 | Most systems support only a subset of these formats. Many devices only |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 157 | support \constant{AFMT_U8}; the most common format used today is |
| 158 | \constant{AFMT_S16_LE}. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 159 | \end{methoddesc} |
| 160 | |
| 161 | \begin{methoddesc}[audio device]{setfmt}{format} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 162 | Used to set the current audio format to \var{format}---see |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 163 | \method{getfmts()} for a list. May also be used to return the current |
| 164 | audio format---do this by passing an ``audio format'' of |
| 165 | \constant{AFMT_QUERY}. Returns the audio format that the device was set |
| 166 | to, which may not be the requested format. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 167 | \end{methoddesc} |
| 168 | |
| 169 | \begin{methoddesc}[audio device]{channels}{num_channels} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 170 | Sets the number of output channels to \var{num_channels}. A value of 1 |
| 171 | indicates monophonic sound, 2 stereophonic. Some devices may have more |
| 172 | than 2 channels, and some high-end devices may not support mono. |
| 173 | Returns the number of channels the device was set to. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 174 | \end{methoddesc} |
| 175 | |
| 176 | \begin{methoddesc}[audio device]{speed}{samplerate} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 177 | Sets the samplerate to \var{samplerate} samples per second and returns |
| 178 | the rate actually set. Most sound devices don't support arbitrary |
| 179 | sample rates. Common rates are: |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 180 | |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 181 | 8000---default rate |
| 182 | 11025---speech recording |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 183 | 22050 |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 184 | 44100---Audio CD-quality (at 16 bits/sample and 2 channels) |
| 185 | 96000---DVD-quality |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 186 | \end{methoddesc} |
| 187 | |
| 188 | \begin{methoddesc}[audio device]{sync} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 189 | Waits until the sound device has played every byte in its buffer and |
| 190 | returns. This also occurs when the sound device is closed. The OSS |
| 191 | documentation recommends simply closing and re-opening the device rather |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 192 | than using \method{sync()}. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 193 | \end{methoddesc} |
| 194 | |
| 195 | \begin{methoddesc}[audio device]{reset} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 196 | Immediately stops and playing or recording and returns the device to a |
| 197 | state where it can accept commands. The OSS documentation recommends |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 198 | closing and re-opening the device after calling \method{reset()}. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 199 | \end{methoddesc} |
| 200 | |
| 201 | \begin{methoddesc}[audio device]{post} |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 202 | To be used like a lightweight \method{sync()}, the \method{post()} |
| 203 | IOCTL informs the audio device that there is a likely to be a pause in |
| 204 | the audio output---i.e., after playing a spot sound effect, before |
| 205 | waiting for user input, or before doing disk I/O. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 206 | \end{methoddesc} |
| 207 | |
| 208 | Convenience methods |
| 209 | |
| 210 | \begin{methoddesc}[audio device]{setparameters}{samplerate,num_channels,format,emulate} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 211 | Initialise the sound device in one method. \var{samplerate}, |
| 212 | \var{channels} and \var{format} should be as specified in the |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 213 | \method{speed()}, \method{channels()} and \method{setfmt()} |
| 214 | methods. If \var{emulate} is true, attempt to find the closest matching |
| 215 | format instead, otherwise raise ValueError if the device does not |
| 216 | support the format. The default is to raise ValueError on unsupported |
| 217 | formats. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 218 | \end{methoddesc} |
| 219 | |
| 220 | \begin{methoddesc}[audio device]{bufsize}{} |
| 221 | Returns the size of the hardware buffer, in samples. |
| 222 | \end{methoddesc} |
| 223 | |
| 224 | \begin{methoddesc}[audio device]{obufcount}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 225 | Returns the number of samples that are in the hardware buffer yet to be |
| 226 | played. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 227 | \end{methoddesc} |
| 228 | |
| 229 | \begin{methoddesc}[audio device]{obuffree}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 230 | Returns the number of samples that could be queued into the hardware |
| 231 | buffer to be played without blocking. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 232 | \end{methoddesc} |
| 233 | |
| 234 | \subsection{Mixer Device Objects \label{mixer-device-objects}} |
| 235 | |
| 236 | File-like interface |
| 237 | |
| 238 | \begin{methoddesc}[mixer device]{close}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 239 | This method closes the open mixer device file. Any further attempts to |
| 240 | use the mixer after this file is closed will raise an IOError. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 241 | \end{methoddesc} |
| 242 | |
| 243 | \begin{methoddesc}[mixer device]{fileno}{} |
| 244 | Returns the file handle number of the open mixer device file. |
| 245 | \end{methoddesc} |
| 246 | |
| 247 | Mixer interface |
| 248 | |
| 249 | \begin{methoddesc}[mixer device]{controls}{} |
| 250 | This method returns a bitmask specifying the available mixer controls |
| 251 | (``Control'' being a specific mixable ``channel'', such as |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 252 | \constant{SOUND_MIXER_PCM} or \constant{SOUND_MIXER_SYNTH}). This |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 253 | bitmask indicates a subset of all available mixer channels---the |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 254 | \constant{SOUND_MIXER_*} constants defined at module level. To determine if, |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 255 | for example, the current mixer object supports a PCM mixer, use the |
| 256 | following Python code: |
| 257 | |
| 258 | \begin{verbatim} |
| 259 | mixer=ossaudiodev.openmixer() |
| 260 | if mixer.channels() & (1 << ossaudiodev.SOUND_MIXER_PCM): |
| 261 | # PCM is supported |
| 262 | <code> |
| 263 | \end{verbatim} |
| 264 | |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 265 | For most purposes, the \constant{SOUND_MIXER_VOLUME} (Master volume) and |
| 266 | \constant{SOUND_MIXER_PCM} channels should suffice---but code that uses the |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 267 | mixer should be flexible when it comes to choosing sound channels. On |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 268 | the Gravis Ultrasound, for example, \constant{SOUND_MIXER_VOLUME} does not |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 269 | exist. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 270 | \end{methoddesc} |
| 271 | |
| 272 | \begin{methoddesc}[mixer device]{stereocontrols}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 273 | Returns a bitmask indicating stereo mixer channels. If a bit is set, |
| 274 | the corresponding channel is stereo; if it is unset, the channel is |
| 275 | either monophonic or not supported by the mixer (use in combination with |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 276 | \method{channels()} to determine which). |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 277 | |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 278 | See the code example for the \method{channels()} function for an example |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 279 | of getting data from a bitmask. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 280 | \end{methoddesc} |
| 281 | |
| 282 | \begin{methoddesc}[mixer device]{reccontrols}{} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 283 | Returns a bitmask specifying the mixer controls that may be used to |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 284 | record. See the code example for \method{controls()} for an example of |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 285 | reading from a bitmask. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 286 | \end{methoddesc} |
| 287 | |
| 288 | \begin{methoddesc}[mixer device]{get}{channel} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 289 | Returns the volume of a given mixer channel. The returned volume is a |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 290 | 2-tuple \code{(left_volume,right_volume)}. Volumes are specified as |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 291 | numbers from 0 (silent) to 100 (full volume). If the channel is |
| 292 | monophonic, a 2-tuple is still returned, but both channel volumes are |
| 293 | the same. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 294 | |
| 295 | If an unknown channel is specified, \exception{error} is raised. |
| 296 | \end{methoddesc} |
| 297 | |
| 298 | \begin{methoddesc}[mixer device]{set}{channel, (left, right)} |
Greg Ward | 3e34f59 | 2003-03-10 02:09:51 +0000 | [diff] [blame] | 299 | Sets the volume for a given mixer channel to \code{(left,right)}. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 300 | \code{left} and \code{right} must be ints and between 0 (silent) and 100 |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 301 | (full volume). On success, the new volume is returned as a 2-tuple. |
| 302 | Note that this may not be exactly the same as the volume specified, |
| 303 | because of the limited resolution of some soundcard's mixers. |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 304 | |
| 305 | Raises \exception{IOError} if an invalid mixer channel was specified; |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 306 | \exception{TypeError} if the argument format was incorrect, and |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 307 | \exception{error} if the specified volumes were out-of-range. |
| 308 | \end{methoddesc} |
| 309 | |
| 310 | \begin{methoddesc}[mixer device]{get_recsrc}{} |
| 311 | This method returns a bitmask indicating which channel or channels are |
| 312 | currently being used as a recording source. |
| 313 | \end{methoddesc} |
| 314 | |
| 315 | \begin{methoddesc}[mixer device]{set_recsrc}{bitmask} |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 316 | Call this function to specify a recording source. Returns a bitmask |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 317 | indicating the new recording source (or sources) if successful; raises |
Greg Ward | 33bcd98 | 2003-03-09 23:57:34 +0000 | [diff] [blame] | 318 | \exception{IOError} if an invalid source was specified. To set the current |
Greg Ward | 620e343 | 2003-03-09 23:34:52 +0000 | [diff] [blame] | 319 | recording source to the microphone input: |
| 320 | |
| 321 | \begin{verbatim} |
| 322 | mixer.setrecsrc (1 << ossaudiodev.SOUND_MIXER_MIC) |
| 323 | \end{verbatim} |
| 324 | \end{methoddesc} |
| 325 | |
| 326 | |
| 327 | |