blob: cc7c1edd7b523325b98b1e121a72717bb069958f [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{sunaudiodev} ---
2 Access to Sun audio hardware.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{sunaudiodev}
4
Fred Drake295da241998-08-10 19:42:37 +00005\modulesynopsis{Access to Sun audio hardware.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Fred Drake83c1a391998-02-19 18:59:48 +00007
Fred Drake295da241998-08-10 19:42:37 +00008This module allows you to access the Sun audio interface. The Sun
Fred Drake83c1a391998-02-19 18:59:48 +00009audio hardware is capable of recording and playing back audio data
Fred Drakefc576191998-04-04 07:15:02 +000010in u-LAW\index{u-LAW} format with a sample rate of 8K per second. A
11full description can be found in the \manpage{audio}{7I} manual page.
Fred Drake83c1a391998-02-19 18:59:48 +000012
13The module defines the following variables and functions:
14
Fred Drake83c1a391998-02-19 18:59:48 +000015\begin{excdesc}{error}
16This exception is raised on all errors. The argument is a string
17describing what went wrong.
18\end{excdesc}
19
20\begin{funcdesc}{open}{mode}
21This function opens the audio device and returns a sun audio device
22object. This object can then be used to do I/O on. The \var{mode} parameter
23is one of \code{'r'} for record-only access, \code{'w'} for play-only
24access, \code{'rw'} for both and \code{'control'} for access to the
25control device. Since only one process is allowed to have the recorder
26or player open at the same time it is a good idea to open the device
Fred Drakefc576191998-04-04 07:15:02 +000027only for the activity needed. See \manpage{audio}{7I} for details.
Fred Drake83c1a391998-02-19 18:59:48 +000028\end{funcdesc}
29
Fred Drakefc576191998-04-04 07:15:02 +000030
Fred Drake83c1a391998-02-19 18:59:48 +000031\subsection{Audio Device Objects}
Fred Drakefc576191998-04-04 07:15:02 +000032\label{audio-device-objects}
Fred Drake83c1a391998-02-19 18:59:48 +000033
Fred Drakefc576191998-04-04 07:15:02 +000034The audio device objects are returned by \function{open()} define the
Fred Drake83c1a391998-02-19 18:59:48 +000035following methods (except \code{control} objects which only provide
Fred Drakefc576191998-04-04 07:15:02 +000036\method{getinfo()}, \method{setinfo()} and \method{drain()}):
Fred Drake83c1a391998-02-19 18:59:48 +000037
Fred Drakefc576191998-04-04 07:15:02 +000038\begin{methoddesc}[audio device]{close}{}
Fred Drake83c1a391998-02-19 18:59:48 +000039This method explicitly closes the device. It is useful in situations
40where deleting the object does not immediately close it since there
41are other references to it. A closed device should not be used again.
Fred Drakefc576191998-04-04 07:15:02 +000042\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000043
Fred Drakefc576191998-04-04 07:15:02 +000044\begin{methoddesc}[audio device]{drain}{}
Fred Drake83c1a391998-02-19 18:59:48 +000045This method waits until all pending output is processed and then returns.
46Calling this method is often not necessary: destroying the object will
47automatically close the audio device and this will do an implicit drain.
Fred Drakefc576191998-04-04 07:15:02 +000048\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000049
Fred Drakefc576191998-04-04 07:15:02 +000050\begin{methoddesc}[audio device]{flush}{}
Fred Drake83c1a391998-02-19 18:59:48 +000051This method discards all pending output. It can be used avoid the
52slow response to a user's stop request (due to buffering of up to one
53second of sound).
Fred Drakefc576191998-04-04 07:15:02 +000054\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000055
Fred Drakefc576191998-04-04 07:15:02 +000056\begin{methoddesc}[audio device]{getinfo}{}
Fred Drake83c1a391998-02-19 18:59:48 +000057This method retrieves status information like input and output volume,
58etc. and returns it in the form of
59an audio status object. This object has no methods but it contains a
60number of attributes describing the current device status. The names
61and meanings of the attributes are described in
Fred Drakefc576191998-04-04 07:15:02 +000062\file{/usr/include/sun/audioio.h} and in the \manpage{audio}{7I}
63manual page. Member names
64are slightly different from their \C{} counterparts: a status object is
65only a single structure. Members of the \cdata{play} substructure have
66\samp{o_} prepended to their name and members of the \cdata{record}
67structure have \samp{i_}. So, the \C{} member \cdata{play.sample_rate} is
68accessed as \member{o_sample_rate}, \cdata{record.gain} as \member{i_gain}
69and \cdata{monitor_gain} plainly as \member{monitor_gain}.
70\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000071
Fred Drakefc576191998-04-04 07:15:02 +000072\begin{methoddesc}[audio device]{ibufcount}{}
Fred Drake83c1a391998-02-19 18:59:48 +000073This method returns the number of samples that are buffered on the
Fred Drakefc576191998-04-04 07:15:02 +000074recording side, i.e.\ the program will not block on a
75\function{read()} call of so many samples.
76\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000077
Fred Drakefc576191998-04-04 07:15:02 +000078\begin{methoddesc}[audio device]{obufcount}{}
Fred Drake83c1a391998-02-19 18:59:48 +000079This method returns the number of samples buffered on the playback
80side. Unfortunately, this number cannot be used to determine a number
81of samples that can be written without blocking since the kernel
82output queue length seems to be variable.
Fred Drakefc576191998-04-04 07:15:02 +000083\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000084
Fred Drakefc576191998-04-04 07:15:02 +000085\begin{methoddesc}[audio device]{read}{size}
Fred Drake83c1a391998-02-19 18:59:48 +000086This method reads \var{size} samples from the audio input and returns
Fred Drake21237741998-04-03 07:06:01 +000087them as a Python string. The function blocks until enough data is available.
Fred Drakefc576191998-04-04 07:15:02 +000088\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000089
Fred Drakefc576191998-04-04 07:15:02 +000090\begin{methoddesc}[audio device]{setinfo}{status}
Fred Drake83c1a391998-02-19 18:59:48 +000091This method sets the audio device status parameters. The \var{status}
92parameter is an device status object as returned by \function{getinfo()} and
93possibly modified by the program.
Fred Drakefc576191998-04-04 07:15:02 +000094\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000095
Fred Drakefc576191998-04-04 07:15:02 +000096\begin{methoddesc}[audio device]{write}{samples}
Fred Drake21237741998-04-03 07:06:01 +000097Write is passed a Python string containing audio samples to be played.
Fred Drake83c1a391998-02-19 18:59:48 +000098If there is enough buffer space free it will immediately return,
99otherwise it will block.
Fred Drakefc576191998-04-04 07:15:02 +0000100\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +0000101
Fred Drakefc576191998-04-04 07:15:02 +0000102There is a companion module,
103\module{SUNAUDIODEV}\refstmodindex{SUNAUDIODEV}, which defines useful
Fred Drake83c1a391998-02-19 18:59:48 +0000104symbolic constants like \constant{MIN_GAIN}, \constant{MAX_GAIN},
Fred Drakefc576191998-04-04 07:15:02 +0000105\constant{SPEAKER}, etc. The names of the constants are the same names
106as used in the \C{} include file \code{<sun/audioio.h>}, with the
107leading string \samp{AUDIO_} stripped.
Fred Drake83c1a391998-02-19 18:59:48 +0000108
109Useability of the control device is limited at the moment, since there
110is no way to use the ``wait for something to happen'' feature the
111device provides.