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