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