Before you can write to or read from an audio device, you must call three methods in the correct order:
The audio device objects returned by open() define the following methods:
) |
) |
size) |
data) |
data) |
The following methods each map to exactly one
ioctl() system call. The correspondence is obvious: for
example, setfmt() corresponds to the SNDCTL_DSP_SETFMT
ioctl, and sync() to SNDCTL_DSP_SYNC
(this can be useful
when consulting the OSS documentation). If the underlying
ioctl() fails, they all raise IOError.
) |
) |
Format | Description |
---|---|
AFMT_MU_LAW | a logarithmic encoding (used by Sun .au files and
/dev/audio) |
AFMT_A_LAW | a logarithmic encoding |
AFMT_IMA_ADPCM | a 4:1 compressed format defined by the Interactive Multimedia Association |
AFMT_U8 | Unsigned, 8-bit audio |
AFMT_S16_LE | Signed, 16-bit audio, little-endian byte order (as used by Intel processors) |
AFMT_S16_BE | Signed, 16-bit audio, big-endian byte order (as used by 68k, PowerPC, Sparc) |
AFMT_S8 | Signed, 8 bit audio |
AFMT_U16_LE | Unsigned, 16-bit little-endian audio |
AFMT_U16_BE | Unsigned, 16-bit big-endian audio |
format) |
nchannels) |
samplerate) |
Rate | Description |
---|---|
8000 | default rate for /dev/audio |
11025 | speech recording |
22050 | |
44100 | CD quality audio (at 16 bits/sample and 2 channels) |
96000 | DVD quality audio (at 24 bits/sample) |
) |
) |
) |
The following convenience methods combine several ioctls, or one ioctl and some simple calculations.
format, nchannels, samplerate [, strict=False]) |
Set the key audio sampling parameters--sample format, number of channels, and sampling rate--in one method call. format, nchannels, and samplerate should be as specified in the setfmt(), channels(), and speed() methods. If strict is true, setparameters() checks to see if each parameter was actually set to the requested value, and raises OSSAudioError if not. Returns a tuple (format, nchannels, samplerate) indicating the parameter values that were actually set by the device driver (i.e., the same as the return values of setfmt(), channels(), and speed()).
For example,
(fmt, channels, rate) = dsp.setparameters(fmt, channels, rate)
fmt = dsp.setfmt(fmt) channels = dsp.channels(channels) rate = dsp.rate(channels)
) |
) |
) |
See About this document... for information on suggesting changes.