cpython/Doc/lib/libsunaudio.tex

147 lines
5.7 KiB
TeX
Raw Normal View History

\section{\module{sunaudiodev} ---
Access to Sun audio hardware}
1999-03-02 16:37:17 +00:00
\declaremodule{builtin}{sunaudiodev}
\platform{SunOS}
\modulesynopsis{Access to Sun audio hardware.}
1998-02-19 18:59:48 +00:00
This module allows you to access the Sun audio interface. The Sun
1998-02-19 18:59:48 +00:00
audio hardware is capable of recording and playing back audio data
in u-LAW\index{u-LAW} format with a sample rate of 8K per second. A
full description can be found in the \manpage{audio}{7I} manual page.
1998-02-19 18:59:48 +00:00
The module
\refmodule[sunaudiodev-constants]{SUNAUDIODEV}\refstmodindex{SUNAUDIODEV}
defines constants which may be used with this module.
This module defines the following variables and functions:
1998-02-19 18:59:48 +00:00
\begin{excdesc}{error}
This exception is raised on all errors. The argument is a string
describing what went wrong.
\end{excdesc}
\begin{funcdesc}{open}{mode}
This function opens the audio device and returns a Sun audio device
1998-02-19 18:59:48 +00:00
object. This object can then be used to do I/O on. The \var{mode} parameter
is one of \code{'r'} for record-only access, \code{'w'} for play-only
access, \code{'rw'} for both and \code{'control'} for access to the
control device. Since only one process is allowed to have the recorder
or player open at the same time it is a good idea to open the device
only for the activity needed. See \manpage{audio}{7I} for details.
As per the manpage, this module first looks in the environment
variable \code{AUDIODEV} for the base audio device filename. If not
found, it falls back to \file{/dev/audio}. The control device is
calculated by appending ``ctl'' to the base audio device.
1998-02-19 18:59:48 +00:00
\end{funcdesc}
\subsection{Audio Device Objects \label{audio-device-objects}}
1998-02-19 18:59:48 +00:00
The audio device objects are returned by \function{open()} define the
1998-02-19 18:59:48 +00:00
following methods (except \code{control} objects which only provide
\method{getinfo()}, \method{setinfo()}, \method{fileno()}, and
\method{drain()}):
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{close}{}
1998-02-19 18:59:48 +00:00
This method explicitly closes the device. It is useful in situations
where deleting the object does not immediately close it since there
are other references to it. A closed device should not be used again.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{fileno}{}
Returns the file descriptor associated with the device. This can be
used to set up \code{SIGPOLL} notification, as described below.
1998-11-02 17:23:25 +00:00
\end{methoddesc}
\begin{methoddesc}[audio device]{drain}{}
1998-02-19 18:59:48 +00:00
This method waits until all pending output is processed and then returns.
Calling this method is often not necessary: destroying the object will
automatically close the audio device and this will do an implicit drain.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{flush}{}
1998-02-19 18:59:48 +00:00
This method discards all pending output. It can be used avoid the
slow response to a user's stop request (due to buffering of up to one
second of sound).
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{getinfo}{}
1998-02-19 18:59:48 +00:00
This method retrieves status information like input and output volume,
etc. and returns it in the form of
an audio status object. This object has no methods but it contains a
number of attributes describing the current device status. The names
and meanings of the attributes are described in
1999-04-23 22:22:27 +00:00
\code{<sun/audioio.h>} and in the \manpage{audio}{7I}
manual page. Member names
1999-04-23 22:22:27 +00:00
are slightly different from their C counterparts: a status object is
only a single structure. Members of the \cdata{play} substructure have
\samp{o_} prepended to their name and members of the \cdata{record}
1999-04-23 22:22:27 +00:00
structure have \samp{i_}. So, the C member \cdata{play.sample_rate} is
accessed as \member{o_sample_rate}, \cdata{record.gain} as \member{i_gain}
and \cdata{monitor_gain} plainly as \member{monitor_gain}.
\end{methoddesc}
\begin{methoddesc}[audio device]{ibufcount}{}
1998-02-19 18:59:48 +00:00
This method returns the number of samples that are buffered on the
recording side, i.e.\ the program will not block on a
\function{read()} call of so many samples.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{obufcount}{}
1998-02-19 18:59:48 +00:00
This method returns the number of samples buffered on the playback
side. Unfortunately, this number cannot be used to determine a number
of samples that can be written without blocking since the kernel
output queue length seems to be variable.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{read}{size}
1998-02-19 18:59:48 +00:00
This method reads \var{size} samples from the audio input and returns
1998-04-03 07:06:01 +00:00
them as a Python string. The function blocks until enough data is available.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{setinfo}{status}
1998-02-19 18:59:48 +00:00
This method sets the audio device status parameters. The \var{status}
parameter is an device status object as returned by \function{getinfo()} and
possibly modified by the program.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
\begin{methoddesc}[audio device]{write}{samples}
1998-04-03 07:06:01 +00:00
Write is passed a Python string containing audio samples to be played.
1998-02-19 18:59:48 +00:00
If there is enough buffer space free it will immediately return,
otherwise it will block.
\end{methoddesc}
1998-02-19 18:59:48 +00:00
The audio device supports asynchronous notification of various events,
through the SIGPOLL signal. Here's an example of how you might enable
this in Python:
\begin{verbatim}
def handle_sigpoll(signum, frame):
print 'I got a SIGPOLL update'
import fcntl, signal, STROPTS
signal.signal(signal.SIGPOLL, handle_sigpoll)
fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG)
\end{verbatim}
\section{\module{SUNAUDIODEV} ---
Constants used with \module{sunaudiodev}}
\declaremodule[sunaudiodev-constants]{standard}{SUNAUDIODEV}
\platform{SunOS}
\modulesynopsis{Constants for use with \refmodule{sunaudiodev}.}
This is a companion module to
\refmodule{sunaudiodev}\refbimodindex{sunaudiodev} which defines
useful symbolic constants like \constant{MIN_GAIN},
\constant{MAX_GAIN}, \constant{SPEAKER}, etc. The names of the
constants are the same names as used in the C include file
\code{<sun/audioio.h>}, with the leading string \samp{AUDIO_}
stripped.