blob: c43d6111fdd71550038c0228722324a0c8331890 [file] [log] [blame]
Fred Drakefc576191998-04-04 07:15:02 +00001\section{Built-in Module \module{sunaudiodev}}
Fred Drake83c1a391998-02-19 18:59:48 +00002\label{module-sunaudiodev}
3\bimodindex{sunaudiodev}
4
5This module allows you to access the sun audio interface. The sun
6audio hardware is capable of recording and playing back audio data
Fred Drakefc576191998-04-04 07:15:02 +00007in u-LAW\index{u-LAW} format with a sample rate of 8K per second. A
8full description can be found in the \manpage{audio}{7I} manual page.
Fred Drake83c1a391998-02-19 18:59:48 +00009
10The module defines the following variables and functions:
11
Fred Drake83c1a391998-02-19 18:59:48 +000012\begin{excdesc}{error}
13This exception is raised on all errors. The argument is a string
14describing what went wrong.
15\end{excdesc}
16
17\begin{funcdesc}{open}{mode}
18This function opens the audio device and returns a sun audio device
19object. This object can then be used to do I/O on. The \var{mode} parameter
20is one of \code{'r'} for record-only access, \code{'w'} for play-only
21access, \code{'rw'} for both and \code{'control'} for access to the
22control device. Since only one process is allowed to have the recorder
23or player open at the same time it is a good idea to open the device
Fred Drakefc576191998-04-04 07:15:02 +000024only for the activity needed. See \manpage{audio}{7I} for details.
Fred Drake83c1a391998-02-19 18:59:48 +000025\end{funcdesc}
26
Fred Drakefc576191998-04-04 07:15:02 +000027
Fred Drake83c1a391998-02-19 18:59:48 +000028\subsection{Audio Device Objects}
Fred Drakefc576191998-04-04 07:15:02 +000029\label{audio-device-objects}
Fred Drake83c1a391998-02-19 18:59:48 +000030
Fred Drakefc576191998-04-04 07:15:02 +000031The audio device objects are returned by \function{open()} define the
Fred Drake83c1a391998-02-19 18:59:48 +000032following methods (except \code{control} objects which only provide
Fred Drakefc576191998-04-04 07:15:02 +000033\method{getinfo()}, \method{setinfo()} and \method{drain()}):
Fred Drake83c1a391998-02-19 18:59:48 +000034
Fred Drakefc576191998-04-04 07:15:02 +000035\begin{methoddesc}[audio device]{close}{}
Fred Drake83c1a391998-02-19 18:59:48 +000036This method explicitly closes the device. It is useful in situations
37where deleting the object does not immediately close it since there
38are other references to it. A closed device should not be used again.
Fred Drakefc576191998-04-04 07:15:02 +000039\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000040
Fred Drakefc576191998-04-04 07:15:02 +000041\begin{methoddesc}[audio device]{drain}{}
Fred Drake83c1a391998-02-19 18:59:48 +000042This method waits until all pending output is processed and then returns.
43Calling this method is often not necessary: destroying the object will
44automatically close the audio device and this will do an implicit drain.
Fred Drakefc576191998-04-04 07:15:02 +000045\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000046
Fred Drakefc576191998-04-04 07:15:02 +000047\begin{methoddesc}[audio device]{flush}{}
Fred Drake83c1a391998-02-19 18:59:48 +000048This method discards all pending output. It can be used avoid the
49slow response to a user's stop request (due to buffering of up to one
50second of sound).
Fred Drakefc576191998-04-04 07:15:02 +000051\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000052
Fred Drakefc576191998-04-04 07:15:02 +000053\begin{methoddesc}[audio device]{getinfo}{}
Fred Drake83c1a391998-02-19 18:59:48 +000054This method retrieves status information like input and output volume,
55etc. and returns it in the form of
56an audio status object. This object has no methods but it contains a
57number of attributes describing the current device status. The names
58and meanings of the attributes are described in
Fred Drakefc576191998-04-04 07:15:02 +000059\file{/usr/include/sun/audioio.h} and in the \manpage{audio}{7I}
60manual page. Member names
61are slightly different from their \C{} counterparts: a status object is
62only a single structure. Members of the \cdata{play} substructure have
63\samp{o_} prepended to their name and members of the \cdata{record}
64structure have \samp{i_}. So, the \C{} member \cdata{play.sample_rate} is
65accessed as \member{o_sample_rate}, \cdata{record.gain} as \member{i_gain}
66and \cdata{monitor_gain} plainly as \member{monitor_gain}.
67\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000068
Fred Drakefc576191998-04-04 07:15:02 +000069\begin{methoddesc}[audio device]{ibufcount}{}
Fred Drake83c1a391998-02-19 18:59:48 +000070This method returns the number of samples that are buffered on the
Fred Drakefc576191998-04-04 07:15:02 +000071recording side, i.e.\ the program will not block on a
72\function{read()} call of so many samples.
73\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000074
Fred Drakefc576191998-04-04 07:15:02 +000075\begin{methoddesc}[audio device]{obufcount}{}
Fred Drake83c1a391998-02-19 18:59:48 +000076This method returns the number of samples buffered on the playback
77side. Unfortunately, this number cannot be used to determine a number
78of samples that can be written without blocking since the kernel
79output queue length seems to be variable.
Fred Drakefc576191998-04-04 07:15:02 +000080\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000081
Fred Drakefc576191998-04-04 07:15:02 +000082\begin{methoddesc}[audio device]{read}{size}
Fred Drake83c1a391998-02-19 18:59:48 +000083This method reads \var{size} samples from the audio input and returns
Fred Drake21237741998-04-03 07:06:01 +000084them as a Python string. The function blocks until enough data is available.
Fred Drakefc576191998-04-04 07:15:02 +000085\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000086
Fred Drakefc576191998-04-04 07:15:02 +000087\begin{methoddesc}[audio device]{setinfo}{status}
Fred Drake83c1a391998-02-19 18:59:48 +000088This method sets the audio device status parameters. The \var{status}
89parameter is an device status object as returned by \function{getinfo()} and
90possibly modified by the program.
Fred Drakefc576191998-04-04 07:15:02 +000091\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000092
Fred Drakefc576191998-04-04 07:15:02 +000093\begin{methoddesc}[audio device]{write}{samples}
Fred Drake21237741998-04-03 07:06:01 +000094Write is passed a Python string containing audio samples to be played.
Fred Drake83c1a391998-02-19 18:59:48 +000095If there is enough buffer space free it will immediately return,
96otherwise it will block.
Fred Drakefc576191998-04-04 07:15:02 +000097\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000098
Fred Drakefc576191998-04-04 07:15:02 +000099There is a companion module,
100\module{SUNAUDIODEV}\refstmodindex{SUNAUDIODEV}, which defines useful
Fred Drake83c1a391998-02-19 18:59:48 +0000101symbolic constants like \constant{MIN_GAIN}, \constant{MAX_GAIN},
Fred Drakefc576191998-04-04 07:15:02 +0000102\constant{SPEAKER}, etc. The names of the constants are the same names
103as used in the \C{} include file \code{<sun/audioio.h>}, with the
104leading string \samp{AUDIO_} stripped.
Fred Drake83c1a391998-02-19 18:59:48 +0000105
106Useability of the control device is limited at the moment, since there
107is no way to use the ``wait for something to happen'' feature the
108device provides.