1 \section{\module{sunaudiodev
} ---
2 Access to Sun audio hardware.
}
4 \declaremodule{builtin
}{sunaudiodev
}
6 \modulesynopsis{Access to Sun audio hardware.
}
9 This module allows you to access the Sun audio interface. The Sun
10 audio hardware is capable of recording and playing back audio data
11 in u-LAW
\index{u-LAW
} format with a sample rate of
8K per second. A
12 full description can be found in the
\manpage{audio
}{7I
} manual page.
14 The module defines the following variables and functions:
16 \begin{excdesc
}{error
}
17 This exception is raised on all errors. The argument is a string
18 describing what went wrong.
21 \begin{funcdesc
}{open
}{mode
}
22 This function opens the audio device and returns a Sun audio device
23 object. This object can then be used to do I/O on. The
\var{mode
} parameter
24 is one of
\code{'r'
} for record-only access,
\code{'w'
} for play-only
25 access,
\code{'rw'
} for both and
\code{'control'
} for access to the
26 control device. Since only one process is allowed to have the recorder
27 or player open at the same time it is a good idea to open the device
28 only for the activity needed. See
\manpage{audio
}{7I
} for details.
30 As per the manpage, this module first looks in the environment
31 variable
\code{AUDIODEV
} for the base audio device filename. If not
32 found, it falls back to
\file{/dev/audio
}. The control device is
33 calculated by appending ``ctl'' to the base audio device.
37 \subsection{Audio Device Objects
}
38 \label{audio-device-objects
}
40 The audio device objects are returned by
\function{open()
} define the
41 following methods (except
\code{control
} objects which only provide
42 \method{getinfo()
},
\method{setinfo()
},
\method{fileno()
}, and
45 \begin{methoddesc
}[audio device
]{close
}{}
46 This method explicitly closes the device. It is useful in situations
47 where deleting the object does not immediately close it since there
48 are other references to it. A closed device should not be used again.
51 \begin{methoddesc
}[audio device
]{fileno
}{}
52 Returns the file descriptor associated with the device. This can be
53 used to set up
\code{SIGPOLL
} notification, as described below.
56 \begin{methoddesc
}[audio device
]{drain
}{}
57 This method waits until all pending output is processed and then returns.
58 Calling this method is often not necessary: destroying the object will
59 automatically close the audio device and this will do an implicit drain.
62 \begin{methoddesc
}[audio device
]{flush
}{}
63 This method discards all pending output. It can be used avoid the
64 slow response to a user's stop request (due to buffering of up to one
68 \begin{methoddesc
}[audio device
]{getinfo
}{}
69 This method retrieves status information like input and output volume,
70 etc. and returns it in the form of
71 an audio status object. This object has no methods but it contains a
72 number of attributes describing the current device status. The names
73 and meanings of the attributes are described in
74 \file{/usr/include/sun/audioio.h
} and in the
\manpage{audio
}{7I
}
75 manual page. Member names
76 are slightly different from their
\C{} counterparts: a status object is
77 only a single structure. Members of the
\cdata{play
} substructure have
78 \samp{o_
} prepended to their name and members of the
\cdata{record
}
79 structure have
\samp{i_
}. So, the
\C{} member
\cdata{play.sample_rate
} is
80 accessed as
\member{o_sample_rate
},
\cdata{record.gain
} as
\member{i_gain
}
81 and
\cdata{monitor_gain
} plainly as
\member{monitor_gain
}.
84 \begin{methoddesc
}[audio device
]{ibufcount
}{}
85 This method returns the number of samples that are buffered on the
86 recording side, i.e.\ the program will not block on a
87 \function{read()
} call of so many samples.
90 \begin{methoddesc
}[audio device
]{obufcount
}{}
91 This method returns the number of samples buffered on the playback
92 side. Unfortunately, this number cannot be used to determine a number
93 of samples that can be written without blocking since the kernel
94 output queue length seems to be variable.
97 \begin{methoddesc
}[audio device
]{read
}{size
}
98 This method reads
\var{size
} samples from the audio input and returns
99 them as a Python string. The function blocks until enough data is available.
102 \begin{methoddesc
}[audio device
]{setinfo
}{status
}
103 This method sets the audio device status parameters. The
\var{status
}
104 parameter is an device status object as returned by
\function{getinfo()
} and
105 possibly modified by the program.
108 \begin{methoddesc
}[audio device
]{write
}{samples
}
109 Write is passed a Python string containing audio samples to be played.
110 If there is enough buffer space free it will immediately return,
111 otherwise it will block.
114 There is a companion module,
115 \module{SUNAUDIODEV
}\refstmodindex{SUNAUDIODEV
}, which defines useful
116 symbolic constants like
\constant{MIN_GAIN
},
\constant{MAX_GAIN
},
117 \constant{SPEAKER
}, etc. The names of the constants are the same names
118 as used in the
\C{} include file
\code{<sun/audioio.h>
}, with the
119 leading string
\samp{AUDIO_
} stripped.
121 The audio device supports asynchronous notification of various events,
122 through the SIGPOLL signal. Here's an example of how you might enable
126 def handle_sigpoll(signum, frame):
127 print 'I got a SIGPOLL update'
129 import fcntl, signal, STROPTS
131 signal.signal(signal.SIGPOLL, handle_sigpoll)
132 fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG)