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