blob: ec70437977da3c42f7cdff9efcd353097d01ffba [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{sunaudiodev} ---
Fred Drake7b8b1251999-04-22 21:19:53 +00002 Access to Sun audio hardware}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{builtin}{sunaudiodev}
5 \platform{SunOS}
Fred Drake295da241998-08-10 19:42:37 +00006\modulesynopsis{Access to Sun audio hardware.}
Fred Drakeb91e9341998-07-23 17:59:49 +00007
Fred Drake83c1a391998-02-19 18:59:48 +00008
Fred Drake295da241998-08-10 19:42:37 +00009This module allows you to access the Sun audio interface. The Sun
Fred Drake83c1a391998-02-19 18:59:48 +000010audio hardware is capable of recording and playing back audio data
Fred Drakefc576191998-04-04 07:15:02 +000011in u-LAW\index{u-LAW} format with a sample rate of 8K per second. A
12full description can be found in the \manpage{audio}{7I} manual page.
Fred Drake83c1a391998-02-19 18:59:48 +000013
Fred Drake7a65a261999-06-27 14:53:11 +000014The module
15\refmodule[sunaudiodev-constants]{SUNAUDIODEV}\refstmodindex{SUNAUDIODEV}
16defines constants which may be used with this module.
17
18This module defines the following variables and functions:
Fred Drake83c1a391998-02-19 18:59:48 +000019
Fred Drake83c1a391998-02-19 18:59:48 +000020\begin{excdesc}{error}
21This exception is raised on all errors. The argument is a string
22describing what went wrong.
23\end{excdesc}
24
25\begin{funcdesc}{open}{mode}
Barry Warsaw4a1cdd71998-10-31 23:19:00 +000026This function opens the audio device and returns a Sun audio device
Fred Drake83c1a391998-02-19 18:59:48 +000027object. This object can then be used to do I/O on. The \var{mode} parameter
28is one of \code{'r'} for record-only access, \code{'w'} for play-only
29access, \code{'rw'} for both and \code{'control'} for access to the
30control device. Since only one process is allowed to have the recorder
31or player open at the same time it is a good idea to open the device
Fred Drakefc576191998-04-04 07:15:02 +000032only for the activity needed. See \manpage{audio}{7I} for details.
Barry Warsaw4a1cdd71998-10-31 23:19:00 +000033
34As per the manpage, this module first looks in the environment
35variable \code{AUDIODEV} for the base audio device filename. If not
36found, it falls back to \file{/dev/audio}. The control device is
37calculated by appending ``ctl'' to the base audio device.
Fred Drake83c1a391998-02-19 18:59:48 +000038\end{funcdesc}
39
Fred Drakefc576191998-04-04 07:15:02 +000040
Fred Drake7a65a261999-06-27 14:53:11 +000041\subsection{Audio Device Objects \label{audio-device-objects}}
Fred Drake83c1a391998-02-19 18:59:48 +000042
Fred Drakefc576191998-04-04 07:15:02 +000043The audio device objects are returned by \function{open()} define the
Fred Drake83c1a391998-02-19 18:59:48 +000044following methods (except \code{control} objects which only provide
Barry Warsaw4a1cdd71998-10-31 23:19:00 +000045\method{getinfo()}, \method{setinfo()}, \method{fileno()}, and
46\method{drain()}):
Fred Drake83c1a391998-02-19 18:59:48 +000047
Fred Drakefc576191998-04-04 07:15:02 +000048\begin{methoddesc}[audio device]{close}{}
Fred Drake83c1a391998-02-19 18:59:48 +000049This method explicitly closes the device. It is useful in situations
50where deleting the object does not immediately close it since there
51are other references to it. A closed device should not be used again.
Fred Drakefc576191998-04-04 07:15:02 +000052\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000053
Barry Warsaw4a1cdd71998-10-31 23:19:00 +000054\begin{methoddesc}[audio device]{fileno}{}
55Returns the file descriptor associated with the device. This can be
56used to set up \code{SIGPOLL} notification, as described below.
Fred Drakecab91ef1998-11-02 17:23:25 +000057\end{methoddesc}
Barry Warsaw4a1cdd71998-10-31 23:19:00 +000058
Fred Drakefc576191998-04-04 07:15:02 +000059\begin{methoddesc}[audio device]{drain}{}
Fred Drake83c1a391998-02-19 18:59:48 +000060This method waits until all pending output is processed and then returns.
61Calling this method is often not necessary: destroying the object will
62automatically close the audio device and this will do an implicit drain.
Fred Drakefc576191998-04-04 07:15:02 +000063\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000064
Fred Drakefc576191998-04-04 07:15:02 +000065\begin{methoddesc}[audio device]{flush}{}
Fred Drake83c1a391998-02-19 18:59:48 +000066This method discards all pending output. It can be used avoid the
67slow response to a user's stop request (due to buffering of up to one
68second of sound).
Fred Drakefc576191998-04-04 07:15:02 +000069\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000070
Fred Drakefc576191998-04-04 07:15:02 +000071\begin{methoddesc}[audio device]{getinfo}{}
Fred Drake83c1a391998-02-19 18:59:48 +000072This method retrieves status information like input and output volume,
73etc. and returns it in the form of
74an audio status object. This object has no methods but it contains a
75number of attributes describing the current device status. The names
76and meanings of the attributes are described in
Fred Drakea4966641999-04-23 22:22:27 +000077\code{<sun/audioio.h>} and in the \manpage{audio}{7I}
Fred Drakefc576191998-04-04 07:15:02 +000078manual page. Member names
Fred Drakea4966641999-04-23 22:22:27 +000079are slightly different from their C counterparts: a status object is
Fred Drakefc576191998-04-04 07:15:02 +000080only a single structure. Members of the \cdata{play} substructure have
81\samp{o_} prepended to their name and members of the \cdata{record}
Fred Drakea4966641999-04-23 22:22:27 +000082structure have \samp{i_}. So, the C member \cdata{play.sample_rate} is
Fred Drakefc576191998-04-04 07:15:02 +000083accessed as \member{o_sample_rate}, \cdata{record.gain} as \member{i_gain}
84and \cdata{monitor_gain} plainly as \member{monitor_gain}.
85\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000086
Fred Drakefc576191998-04-04 07:15:02 +000087\begin{methoddesc}[audio device]{ibufcount}{}
Fred Drake83c1a391998-02-19 18:59:48 +000088This method returns the number of samples that are buffered on the
Fred Drakefc576191998-04-04 07:15:02 +000089recording side, i.e.\ the program will not block on a
90\function{read()} call of so many samples.
91\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000092
Fred Drakefc576191998-04-04 07:15:02 +000093\begin{methoddesc}[audio device]{obufcount}{}
Fred Drake83c1a391998-02-19 18:59:48 +000094This method returns the number of samples buffered on the playback
95side. Unfortunately, this number cannot be used to determine a number
96of samples that can be written without blocking since the kernel
97output queue length seems to be variable.
Fred Drakefc576191998-04-04 07:15:02 +000098\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +000099
Fred Drakefc576191998-04-04 07:15:02 +0000100\begin{methoddesc}[audio device]{read}{size}
Fred Drake83c1a391998-02-19 18:59:48 +0000101This method reads \var{size} samples from the audio input and returns
Fred Drake21237741998-04-03 07:06:01 +0000102them as a Python string. The function blocks until enough data is available.
Fred Drakefc576191998-04-04 07:15:02 +0000103\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +0000104
Fred Drakefc576191998-04-04 07:15:02 +0000105\begin{methoddesc}[audio device]{setinfo}{status}
Fred Drake83c1a391998-02-19 18:59:48 +0000106This method sets the audio device status parameters. The \var{status}
107parameter is an device status object as returned by \function{getinfo()} and
108possibly modified by the program.
Fred Drakefc576191998-04-04 07:15:02 +0000109\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +0000110
Fred Drakefc576191998-04-04 07:15:02 +0000111\begin{methoddesc}[audio device]{write}{samples}
Fred Drake21237741998-04-03 07:06:01 +0000112Write is passed a Python string containing audio samples to be played.
Fred Drake83c1a391998-02-19 18:59:48 +0000113If there is enough buffer space free it will immediately return,
114otherwise it will block.
Fred Drakefc576191998-04-04 07:15:02 +0000115\end{methoddesc}
Fred Drake83c1a391998-02-19 18:59:48 +0000116
Barry Warsaw4a1cdd71998-10-31 23:19:00 +0000117The audio device supports asynchronous notification of various events,
Fred Drake7a65a261999-06-27 14:53:11 +0000118through the SIGPOLL signal. Here's an example of how you might enable
Barry Warsaw4a1cdd71998-10-31 23:19:00 +0000119this in Python:
120
121\begin{verbatim}
122def handle_sigpoll(signum, frame):
123 print 'I got a SIGPOLL update'
Fred Drake7b8b1251999-04-22 21:19:53 +0000124
Barry Warsaw4a1cdd71998-10-31 23:19:00 +0000125import fcntl, signal, STROPTS
126
127signal.signal(signal.SIGPOLL, handle_sigpoll)
128fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG)
129\end{verbatim}
Fred Drake7a65a261999-06-27 14:53:11 +0000130
131
132\section{\module{SUNAUDIODEV} ---
133 Constants used with \module{sunaudiodev}}
134
135\declaremodule[sunaudiodev-constants]{standard}{SUNAUDIODEV}
136 \platform{SunOS}
137\modulesynopsis{Constants for use with \refmodule{sunaudiodev}.}
138
139
140This is a companion module to
141\refmodule{sunaudiodev}\refbimodindex{sunaudiodev} which defines
142useful symbolic constants like \constant{MIN_GAIN},
143\constant{MAX_GAIN}, \constant{SPEAKER}, etc. The names of the
144constants are the same names as used in the C include file
145\code{<sun/audioio.h>}, with the leading string \samp{AUDIO_}
146stripped.