mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Rewrite intro paragraphs and add a "See also" box for the link to the
official OSS docs. Markup fixes: change \code{} variously to \function{}, \method{}, or \constant{} as appropriate.
This commit is contained in:
parent
074472ba98
commit
3e34f59ce2
1 changed files with 57 additions and 54 deletions
|
@ -1,26 +1,27 @@
|
||||||
\section{\module{ossaudiodev} ---
|
\section{\module{ossaudiodev} ---
|
||||||
Access to Open Sound System-compatible audio hardware}
|
Access to OSS-compatible audio devices}
|
||||||
|
|
||||||
\declaremodule{builtin}{ossaudiodev}
|
\declaremodule{builtin}{ossaudiodev}
|
||||||
\platform{OSS}
|
\platform{Linux, FreeBSD}
|
||||||
\modulesynopsis{Access to OSS-compatible audio hardware.}
|
\modulesynopsis{Access to OSS-compatible audio devices.}
|
||||||
|
|
||||||
% I know FreeBSD uses OSS -- what about Net- and Open-?
|
% XXX OSS is standard for Linux and FreeBSD -- what about NetBSD?
|
||||||
This module allows you to access the Open Sound System audio interface.
|
% OpenBSD? others?
|
||||||
The Open Sound System interface is present on Linux and FreeBSD.
|
This module allows you to access the OSS (Open Sound System) audio
|
||||||
|
interface. OSS is available for a wide range of open-source and
|
||||||
|
commercial Unices, and is the standard audio interface for Linux (up to
|
||||||
|
kernel 2.4) and FreeBSD.
|
||||||
|
|
||||||
This module provides a very "bare bones" wrapper over the IOCTLs used to
|
\begin{seealso}
|
||||||
access the audio hardware. The best---albeit rather daunting---way to
|
\seetitle[http://www.opensound.com/pguide/oss.pdf]
|
||||||
get a feel for the interface is from the Open Sound System official
|
{Open Sound System Programmer's Guide}
|
||||||
documentation:
|
{the official documentation for the OSS C API}
|
||||||
|
\seetext{The module defines a large number of constants supplied by
|
||||||
|
the OSS device driver; see \file{<sys/soundcard.h>} on either
|
||||||
|
Linux or FreeBSD for a listing .}
|
||||||
|
\end{seealso}
|
||||||
|
|
||||||
\url{http://www.opensound.com/pguide/oss.pdf}
|
\module{ossaudiodev} defines the following variables and functions:
|
||||||
|
|
||||||
The module defines a number of constants which may be used to program
|
|
||||||
the device. These constants are the same as those defined in the C
|
|
||||||
include file \code{<sys/soundcard.h>}.
|
|
||||||
|
|
||||||
\code{ossaudiodev} defines the following variables and functions:
|
|
||||||
|
|
||||||
\begin{excdesc}{error}
|
\begin{excdesc}{error}
|
||||||
This exception is raised on errors. The argument is a string describing
|
This exception is raised on errors. The argument is a string describing
|
||||||
|
@ -31,7 +32,7 @@ what went wrong.
|
||||||
This function opens the audio device and returns an OSS audio device
|
This function opens the audio device and returns an OSS audio device
|
||||||
object. This object can then be used to do I/O on. The \var{device}
|
object. This object can then be used to do I/O on. The \var{device}
|
||||||
parameter is the audio device filename to use. If it is not specified,
|
parameter is the audio device filename to use. If it is not specified,
|
||||||
this module first looks in the environment variable \code{AUDIODEV} for
|
this module first looks in the environment variable \envvar{AUDIODEV} for
|
||||||
a device to use. If not found, it falls back to \file{/dev/dsp}.
|
a device to use. If not found, it falls back to \file{/dev/dsp}.
|
||||||
|
|
||||||
The \var{mode} parameter is one of \code{'r'} for record-only access,
|
The \var{mode} parameter is one of \code{'r'} for record-only access,
|
||||||
|
@ -46,7 +47,7 @@ for reading or writing, but not both at once.
|
||||||
opens the mixer device and returns an OSS mixer device object. The
|
opens the mixer device and returns an OSS mixer device object. The
|
||||||
\var{device} parameter is the mixer device filename to use. If it is
|
\var{device} parameter is the mixer device filename to use. If it is
|
||||||
not specified, this module first looks in the environment variable
|
not specified, this module first looks in the environment variable
|
||||||
\code{MIXERDEV} for a device to use. If not found, it falls back to
|
\envvar{MIXERDEV} for a device to use. If not found, it falls back to
|
||||||
\file{/dev/mixer}. You may specify \code{'r'}, \code{'rw'} or
|
\file{/dev/mixer}. You may specify \code{'r'}, \code{'rw'} or
|
||||||
\code{'w'} for \var{mode}; the default is \code{'r'}.
|
\code{'w'} for \var{mode}; the default is \code{'r'}.
|
||||||
|
|
||||||
|
@ -59,9 +60,9 @@ Setting up the device
|
||||||
To set up the device, three functions must be called in the correct
|
To set up the device, three functions must be called in the correct
|
||||||
sequence:
|
sequence:
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item \code{setfmt()} to set the output format,
|
\item \method{setfmt()} to set the output format,
|
||||||
\item \code{channels()} to set the number of channels, and
|
\item \method{channels()} to set the number of channels, and
|
||||||
\item \code{speed()} to set the sample rate.
|
\item \method{speed()} to set the sample rate.
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
The audio device objects are returned by \function{open()} define the
|
The audio device objects are returned by \function{open()} define the
|
||||||
|
@ -86,15 +87,16 @@ Python string. The function blocks until enough data is available.
|
||||||
Writes Python string \var{data} to the audio device and returns the
|
Writes Python string \var{data} to the audio device and returns the
|
||||||
number of bytes written. If the audio device is opened in blocking
|
number of bytes written. If the audio device is opened in blocking
|
||||||
mode, the entire string is always written. If the device is opened in
|
mode, the entire string is always written. If the device is opened in
|
||||||
nonblocking mode, some data may not be written---see \code{writeall}.
|
nonblocking mode, some data may not be written---see
|
||||||
|
\method{writeall()}.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[audio device]{writeall}{data}
|
\begin{methoddesc}[audio device]{writeall}{data}
|
||||||
Writes the entire Python string \var{data} to the audio device. If the
|
Writes the entire Python string \var{data} to the audio device. If the
|
||||||
device is opened in blocking mode, behaves identially to \code{write};
|
device is opened in blocking mode, behaves identially to
|
||||||
in nonblocking mode, waits until the device becomes available before
|
\method{write()}; in nonblocking mode, waits until the device becomes
|
||||||
feeding it more data. Returns None, since the amount of data written is
|
available before feeding it more data. Returns \code{None}, since the
|
||||||
always equal to the amount of data supplied.
|
amount of data written is always equal to the amount of data supplied.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
Simple IOCTLs:
|
Simple IOCTLs:
|
||||||
|
@ -113,7 +115,7 @@ soundcard. On a typical Linux system, these formats are:
|
||||||
\begin{tableii}{l|l}{constant}{Format}{Description}
|
\begin{tableii}{l|l}{constant}{Format}{Description}
|
||||||
\lineii{AFMT_MU_LAW}
|
\lineii{AFMT_MU_LAW}
|
||||||
{a logarithmic encoding. This is the default format on
|
{a logarithmic encoding. This is the default format on
|
||||||
/dev/audio and is the format used by Sun .au files.}
|
\file{/dev/audio} and is the format used by Sun .au files.}
|
||||||
\lineii{AFMT_A_LAW}
|
\lineii{AFMT_A_LAW}
|
||||||
{a logarithmic encoding}
|
{a logarithmic encoding}
|
||||||
\lineii{AFMT_IMA_ADPCM}
|
\lineii{AFMT_IMA_ADPCM}
|
||||||
|
@ -135,16 +137,16 @@ soundcard. On a typical Linux system, these formats are:
|
||||||
{Signed, 16-bit big-endian audio}
|
{Signed, 16-bit big-endian audio}
|
||||||
\end{tableii}
|
\end{tableii}
|
||||||
Most systems support only a subset of these formats. Many devices only
|
Most systems support only a subset of these formats. Many devices only
|
||||||
support \code{AFMT_U8}; the most common format used today is
|
support \constant{AFMT_U8}; the most common format used today is
|
||||||
\code{AFMT_S16_LE}.
|
\constant{AFMT_S16_LE}.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[audio device]{setfmt}{format}
|
\begin{methoddesc}[audio device]{setfmt}{format}
|
||||||
Used to set the current audio format to \var{format}---see
|
Used to set the current audio format to \var{format}---see
|
||||||
\code{getfmts} for a list. May also be used to return the current audio
|
\method{getfmts()} for a list. May also be used to return the current
|
||||||
format---do this by passing an ``audio format'' of \code{AFMT_QUERY}.
|
audio format---do this by passing an ``audio format'' of
|
||||||
Returns the audio format that the device was set to, which may not be
|
\constant{AFMT_QUERY}. Returns the audio format that the device was set
|
||||||
the requested format.
|
to, which may not be the requested format.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[audio device]{channels}{num_channels}
|
\begin{methoddesc}[audio device]{channels}{num_channels}
|
||||||
|
@ -170,20 +172,20 @@ sample rates. Common rates are:
|
||||||
Waits until the sound device has played every byte in its buffer and
|
Waits until the sound device has played every byte in its buffer and
|
||||||
returns. This also occurs when the sound device is closed. The OSS
|
returns. This also occurs when the sound device is closed. The OSS
|
||||||
documentation recommends simply closing and re-opening the device rather
|
documentation recommends simply closing and re-opening the device rather
|
||||||
than using \code{sync}.
|
than using \method{sync()}.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[audio device]{reset}
|
\begin{methoddesc}[audio device]{reset}
|
||||||
Immediately stops and playing or recording and returns the device to a
|
Immediately stops and playing or recording and returns the device to a
|
||||||
state where it can accept commands. The OSS documentation recommends
|
state where it can accept commands. The OSS documentation recommends
|
||||||
closing and re-opening the device after calling \code{reset}.
|
closing and re-opening the device after calling \method{reset()}.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[audio device]{post}
|
\begin{methoddesc}[audio device]{post}
|
||||||
To be used like a lightweight \code{sync}, the \code{post} IOCTL informs
|
To be used like a lightweight \method{sync()}, the \method{post()}
|
||||||
the audio device that there is a likely to be a pause in the audio
|
IOCTL informs the audio device that there is a likely to be a pause in
|
||||||
output---i.e., after playing a spot sound effect, before waiting for
|
the audio output---i.e., after playing a spot sound effect, before
|
||||||
user input, or before doing disk IO.
|
waiting for user input, or before doing disk I/O.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
Convenience methods
|
Convenience methods
|
||||||
|
@ -191,10 +193,11 @@ Convenience methods
|
||||||
\begin{methoddesc}[audio device]{setparameters}{samplerate,num_channels,format,emulate}
|
\begin{methoddesc}[audio device]{setparameters}{samplerate,num_channels,format,emulate}
|
||||||
Initialise the sound device in one method. \var{samplerate},
|
Initialise the sound device in one method. \var{samplerate},
|
||||||
\var{channels} and \var{format} should be as specified in the
|
\var{channels} and \var{format} should be as specified in the
|
||||||
\code{speed}, \code{channels} and \code{setfmt} methods. If
|
\method{speed()}, \method{channels()} and \method{setfmt()}
|
||||||
\var{emulate} is true, attempt to find the closest matching format
|
methods. If \var{emulate} is true, attempt to find the closest matching
|
||||||
instead, otherwise raise ValueError if the device does not support the
|
format instead, otherwise raise ValueError if the device does not
|
||||||
format. The default is to raise ValueError on unsupported formats.
|
support the format. The default is to raise ValueError on unsupported
|
||||||
|
formats.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[audio device]{bufsize}{}
|
\begin{methoddesc}[audio device]{bufsize}{}
|
||||||
|
@ -229,9 +232,9 @@ Mixer interface
|
||||||
\begin{methoddesc}[mixer device]{controls}{}
|
\begin{methoddesc}[mixer device]{controls}{}
|
||||||
This method returns a bitmask specifying the available mixer controls
|
This method returns a bitmask specifying the available mixer controls
|
||||||
(``Control'' being a specific mixable ``channel'', such as
|
(``Control'' being a specific mixable ``channel'', such as
|
||||||
\code{SOUND_MIXER_PCM} or \code{SOUND_MIXER_SYNTH}). This
|
\constant{SOUND_MIXER_PCM} or \constant{SOUND_MIXER_SYNTH}). This
|
||||||
bitmask indicates a subset of all available mixer channels---the
|
bitmask indicates a subset of all available mixer channels---the
|
||||||
\code{SOUND_MIXER_*} constants defined at module level. To determine if,
|
\constant{SOUND_MIXER_*} constants defined at module level. To determine if,
|
||||||
for example, the current mixer object supports a PCM mixer, use the
|
for example, the current mixer object supports a PCM mixer, use the
|
||||||
following Python code:
|
following Python code:
|
||||||
|
|
||||||
|
@ -242,10 +245,10 @@ if mixer.channels() & (1 << ossaudiodev.SOUND_MIXER_PCM):
|
||||||
<code>
|
<code>
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
For most purposes, the \code{SOUND_MIXER_VOLUME} (Master volume) and
|
For most purposes, the \constant{SOUND_MIXER_VOLUME} (Master volume) and
|
||||||
\code{SOUND_MIXER_PCM} channels should suffice---but code that uses the
|
\constant{SOUND_MIXER_PCM} channels should suffice---but code that uses the
|
||||||
mixer should be flexible when it comes to choosing sound channels. On
|
mixer should be flexible when it comes to choosing sound channels. On
|
||||||
the Gravis Ultrasound, for example, \code{SOUND_MIXER_VOLUME} does not
|
the Gravis Ultrasound, for example, \constant{SOUND_MIXER_VOLUME} does not
|
||||||
exist.
|
exist.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
|
@ -253,21 +256,21 @@ exist.
|
||||||
Returns a bitmask indicating stereo mixer channels. If a bit is set,
|
Returns a bitmask indicating stereo mixer channels. If a bit is set,
|
||||||
the corresponding channel is stereo; if it is unset, the channel is
|
the corresponding channel is stereo; if it is unset, the channel is
|
||||||
either monophonic or not supported by the mixer (use in combination with
|
either monophonic or not supported by the mixer (use in combination with
|
||||||
\function{channels} to determine which).
|
\method{channels()} to determine which).
|
||||||
|
|
||||||
See the code example for the \function{channels} function for an example
|
See the code example for the \method{channels()} function for an example
|
||||||
of getting data from a bitmask.
|
of getting data from a bitmask.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[mixer device]{reccontrols}{}
|
\begin{methoddesc}[mixer device]{reccontrols}{}
|
||||||
Returns a bitmask specifying the mixer controls that may be used to
|
Returns a bitmask specifying the mixer controls that may be used to
|
||||||
record. See the code example for \function{controls} for an example of
|
record. See the code example for \method{controls()} for an example of
|
||||||
reading from a bitmask.
|
reading from a bitmask.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[mixer device]{get}{channel}
|
\begin{methoddesc}[mixer device]{get}{channel}
|
||||||
Returns the volume of a given mixer channel. The returned volume is a
|
Returns the volume of a given mixer channel. The returned volume is a
|
||||||
2-tuple of \code{left volume, right volume}. Volumes are specified as
|
2-tuple \code{(left_volume,right_volume)}. Volumes are specified as
|
||||||
numbers from 0 (silent) to 100 (full volume). If the channel is
|
numbers from 0 (silent) to 100 (full volume). If the channel is
|
||||||
monophonic, a 2-tuple is still returned, but both channel volumes are
|
monophonic, a 2-tuple is still returned, but both channel volumes are
|
||||||
the same.
|
the same.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue