Fred Drake | 83c1a39 | 1998-02-19 18:59:48 +0000 | [diff] [blame^] | 1 | \section{Built-in Module \sectcode{sunaudiodev}} |
| 2 | \label{module-sunaudiodev} |
| 3 | \bimodindex{sunaudiodev} |
| 4 | |
| 5 | This module allows you to access the sun audio interface. The sun |
| 6 | audio hardware is capable of recording and playing back audio data |
| 7 | in U-LAW format with a sample rate of 8K per second. A full |
| 8 | description can be gotten with \samp{man audio}. |
| 9 | |
| 10 | The module defines the following variables and functions: |
| 11 | |
| 12 | \setindexsubitem{(in module sunaudiodev)} |
| 13 | \begin{excdesc}{error} |
| 14 | This exception is raised on all errors. The argument is a string |
| 15 | describing what went wrong. |
| 16 | \end{excdesc} |
| 17 | |
| 18 | \begin{funcdesc}{open}{mode} |
| 19 | This function opens the audio device and returns a sun audio device |
| 20 | object. This object can then be used to do I/O on. The \var{mode} parameter |
| 21 | is one of \code{'r'} for record-only access, \code{'w'} for play-only |
| 22 | access, \code{'rw'} for both and \code{'control'} for access to the |
| 23 | control device. Since only one process is allowed to have the recorder |
| 24 | or player open at the same time it is a good idea to open the device |
| 25 | only for the activity needed. See the audio manpage for details. |
| 26 | \end{funcdesc} |
| 27 | |
| 28 | \subsection{Audio Device Objects} |
| 29 | |
| 30 | The audio device objects are returned by \code{open} define the |
| 31 | following methods (except \code{control} objects which only provide |
| 32 | getinfo, setinfo and drain): |
| 33 | |
| 34 | \setindexsubitem{(audio device method)} |
| 35 | |
| 36 | \begin{funcdesc}{close}{} |
| 37 | This method explicitly closes the device. It is useful in situations |
| 38 | where deleting the object does not immediately close it since there |
| 39 | are other references to it. A closed device should not be used again. |
| 40 | \end{funcdesc} |
| 41 | |
| 42 | \begin{funcdesc}{drain}{} |
| 43 | This method waits until all pending output is processed and then returns. |
| 44 | Calling this method is often not necessary: destroying the object will |
| 45 | automatically close the audio device and this will do an implicit drain. |
| 46 | \end{funcdesc} |
| 47 | |
| 48 | \begin{funcdesc}{flush}{} |
| 49 | This method discards all pending output. It can be used avoid the |
| 50 | slow response to a user's stop request (due to buffering of up to one |
| 51 | second of sound). |
| 52 | \end{funcdesc} |
| 53 | |
| 54 | \begin{funcdesc}{getinfo}{} |
| 55 | This method retrieves status information like input and output volume, |
| 56 | etc. and returns it in the form of |
| 57 | an audio status object. This object has no methods but it contains a |
| 58 | number of attributes describing the current device status. The names |
| 59 | and meanings of the attributes are described in |
| 60 | \file{/usr/include/sun/audioio.h} and in the audio man page. Member names |
| 61 | are slightly different from their C counterparts: a status object is |
| 62 | only a single structure. Members of the \code{play} substructure have |
| 63 | \samp{o_} prepended to their name and members of the \code{record} |
| 64 | structure have \samp{i_}. So, the C member \code{play.sample_rate} is |
| 65 | accessed as \code{o_sample_rate}, \code{record.gain} as \code{i_gain} |
| 66 | and \code{monitor_gain} plainly as \code{monitor_gain}. |
| 67 | \end{funcdesc} |
| 68 | |
| 69 | \begin{funcdesc}{ibufcount}{} |
| 70 | This method returns the number of samples that are buffered on the |
| 71 | recording side, i.e. |
| 72 | the program will not block on a \function{read()} call of so many samples. |
| 73 | \end{funcdesc} |
| 74 | |
| 75 | \begin{funcdesc}{obufcount}{} |
| 76 | This method returns the number of samples buffered on the playback |
| 77 | side. Unfortunately, this number cannot be used to determine a number |
| 78 | of samples that can be written without blocking since the kernel |
| 79 | output queue length seems to be variable. |
| 80 | \end{funcdesc} |
| 81 | |
| 82 | \begin{funcdesc}{read}{size} |
| 83 | This method reads \var{size} samples from the audio input and returns |
| 84 | them as a python string. The function blocks until enough data is available. |
| 85 | \end{funcdesc} |
| 86 | |
| 87 | \begin{funcdesc}{setinfo}{status} |
| 88 | This method sets the audio device status parameters. The \var{status} |
| 89 | parameter is an device status object as returned by \function{getinfo()} and |
| 90 | possibly modified by the program. |
| 91 | \end{funcdesc} |
| 92 | |
| 93 | \begin{funcdesc}{write}{samples} |
| 94 | Write is passed a python string containing audio samples to be played. |
| 95 | If there is enough buffer space free it will immediately return, |
| 96 | otherwise it will block. |
| 97 | \end{funcdesc} |
| 98 | |
| 99 | There is a companion module, \module{SUNAUDIODEV}, which defines useful |
| 100 | symbolic constants like \constant{MIN_GAIN}, \constant{MAX_GAIN}, |
| 101 | \constant{SPEAKER}, etc. The names of |
| 102 | the constants are the same names as used in the \C{} include file |
| 103 | \code{<sun/audioio.h>}, with the leading string \samp{AUDIO_} |
| 104 | stripped. |
| 105 | \refstmodindex{SUNAUDIODEV} |
| 106 | |
| 107 | Useability of the control device is limited at the moment, since there |
| 108 | is no way to use the ``wait for something to happen'' feature the |
| 109 | device provides. |