blob: 68d2c8bc24d23734eda08b4ebded060c7ebee954 [file] [log] [blame]
Guido van Rossumecde7811995-03-28 13:35:14 +00001\chapter{SunOS Specific Services}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00002
3The modules described in this chapter provide interfaces to features
4that are unique to the SunOS operating system (versions 4 and 5; the
Guido van Rossumecde7811995-03-28 13:35:14 +00005latter is also known as Solaris version 2).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006
Guido van Rossum470be141995-03-17 16:07:09 +00007\section{Built-in Module \sectcode{sunaudiodev}}
Fred Drake57b5e421998-02-17 22:30:13 +00008\label{module-sunaudiodev}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009\bimodindex{sunaudiodev}
10
11This module allows you to access the sun audio interface. The sun
12audio hardware is capable of recording and playing back audio data
13in U-LAW format with a sample rate of 8K per second. A full
14description can be gotten with \samp{man audio}.
15
16The module defines the following variables and functions:
17
Fred Drake19479911998-02-13 06:58:54 +000018\setindexsubitem{(in module sunaudiodev)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000019\begin{excdesc}{error}
20This exception is raised on all errors. The argument is a string
21describing what went wrong.
22\end{excdesc}
23
24\begin{funcdesc}{open}{mode}
25This function opens the audio device and returns a sun audio device
26object. This object can then be used to do I/O on. The \var{mode} parameter
27is one of \code{'r'} for record-only access, \code{'w'} for play-only
28access, \code{'rw'} for both and \code{'control'} for access to the
29control device. Since only one process is allowed to have the recorder
30or player open at the same time it is a good idea to open the device
31only for the activity needed. See the audio manpage for details.
32\end{funcdesc}
33
Guido van Rossum470be141995-03-17 16:07:09 +000034\subsection{Audio Device Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000035
36The audio device objects are returned by \code{open} define the
37following methods (except \code{control} objects which only provide
38getinfo, setinfo and drain):
39
Fred Drake19479911998-02-13 06:58:54 +000040\setindexsubitem{(audio device method)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000041
42\begin{funcdesc}{close}{}
43This method explicitly closes the device. It is useful in situations
44where deleting the object does not immediately close it since there
45are other references to it. A closed device should not be used again.
46\end{funcdesc}
47
48\begin{funcdesc}{drain}{}
49This method waits until all pending output is processed and then returns.
50Calling this method is often not necessary: destroying the object will
51automatically close the audio device and this will do an implicit drain.
52\end{funcdesc}
53
54\begin{funcdesc}{flush}{}
55This method discards all pending output. It can be used avoid the
56slow response to a user's stop request (due to buffering of up to one
57second of sound).
58\end{funcdesc}
59
60\begin{funcdesc}{getinfo}{}
61This method retrieves status information like input and output volume,
62etc. and returns it in the form of
63an audio status object. This object has no methods but it contains a
64number of attributes describing the current device status. The names
65and meanings of the attributes are described in
66\file{/usr/include/sun/audioio.h} and in the audio man page. Member names
67are slightly different from their C counterparts: a status object is
68only a single structure. Members of the \code{play} substructure have
69\samp{o_} prepended to their name and members of the \code{record}
70structure have \samp{i_}. So, the C member \code{play.sample_rate} is
71accessed as \code{o_sample_rate}, \code{record.gain} as \code{i_gain}
72and \code{monitor_gain} plainly as \code{monitor_gain}.
73\end{funcdesc}
74
75\begin{funcdesc}{ibufcount}{}
76This method returns the number of samples that are buffered on the
77recording side, i.e.
78the program will not block on a \code{read} call of so many samples.
79\end{funcdesc}
80
81\begin{funcdesc}{obufcount}{}
82This method returns the number of samples buffered on the playback
83side. Unfortunately, this number cannot be used to determine a number
84of samples that can be written without blocking since the kernel
85output queue length seems to be variable.
86\end{funcdesc}
87
88\begin{funcdesc}{read}{size}
89This method reads \var{size} samples from the audio input and returns
90them as a python string. The function blocks until enough data is available.
91\end{funcdesc}
92
93\begin{funcdesc}{setinfo}{status}
94This method sets the audio device status parameters. The \var{status}
95parameter is an device status object as returned by \code{getinfo} and
96possibly modified by the program.
97\end{funcdesc}
98
99\begin{funcdesc}{write}{samples}
100Write is passed a python string containing audio samples to be played.
Guido van Rossum96628a91995-04-10 11:34:00 +0000101If there is enough buffer space free it will immediately return,
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000102otherwise it will block.
103\end{funcdesc}
104
105There is a companion module, \code{SUNAUDIODEV}, which defines useful
106symbolic constants like \code{MIN_GAIN}, \code{MAX_GAIN},
107\code{SPEAKER}, etc. The names of
108the constants are the same names as used in the C include file
Fred Drake4f496cc1997-12-16 04:08:24 +0000109\file{<sun/audioio.h>}, with the leading string \samp{AUDIO_}
110stripped.
111\refstmodindex{SUNAUDIODEV}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000112
113Useability of the control device is limited at the moment, since there
Guido van Rossum470be141995-03-17 16:07:09 +0000114is no way to use the ``wait for something to happen'' feature the
115device provides.