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