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