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