audiotools.pcmconverter — the PCM Conversion Module

The audiotools.pcmconverter module contains audiotools.PCMReader wrapper classes for converting streams to different sample rates, channel counts, channel assignments and so on.

These classes are combined by audiotools.PCMConverter as needed to modify a stream from one format to another.

Averager Objects

class audiotools.pcmconverter.Averager(pcmreader)

This class takes a audiotools.PCMReader-compatible object and constructs a new audiotools.PCMReader-compatible whose channels have been averaged together into a single channel.

Averager.sample_rate

The sample rate of this audio stream, in Hz, as a positive integer.

Averager.channels

The number of channels of this audio stream, which is always 1.

Averager.channel_mask

The channel mask of this audio stream, which is always 0x4.

Averager.bits_per_sample

The number of bits-per-sample in this audio stream as a positive integer.

Averager.read(pcm_frames)

Try to read a audiotools.pcm.FrameList object with the given number of PCM frames, if possible. This method is not guaranteed to read that amount of frames. It may return less, particularly at the end of an audio stream. It may even return FrameLists larger than requested. However, it must always return a non-empty FrameList until the end of the PCM stream is reached. May raise IOError if there is a problem reading the source file, or ValueError if the source file has some sort of error.

Averager.close()

Closes the audio stream. If any subprocesses were used for audio decoding, they will also be closed and waited for their process to finish. May raise a DecodingError, typically indicating that a helper subprocess used for decoding has exited with an error.

BPSConverter Objects

class audiotools.pcmconverter.BPSConveter(pcmreader, bits_per_sample)

This class takes a audiotools.PCMReader-compatible object and new bits_per_sample integer, and constructs a new audiotools.PCMReader-compatible object with that amount of bits-per-sample by truncating or extending bits to each sample as needed.

BPSConverter.sample_rate

The sample rate of this audio stream, in Hz, as a positive integer.

BPSConverter.channels

The number of channels in this audio stream as a positive integer.

BPSConverter.channel_mask

The channel mask of this audio stream as a non-negative integer.

BPSConverter.bits_per_sample

The number of bits-per-sample in this audio stream as indicated at init-time.

BPSConverter.read(pcm_frames)

Try to read a audiotools.pcm.FrameList object with the given number of PCM frames, if possible. This method is not guaranteed to read that amount of frames. It may return less, particularly at the end of an audio stream. It may even return FrameLists larger than requested. However, it must always return a non-empty FrameList until the end of the PCM stream is reached. May raise IOError if there is a problem reading the source file, or ValueError if the source file has some sort of error.

BPSConverter.close()

Closes the audio stream. If any subprocesses were used for audio decoding, they will also be closed and waited for their process to finish. May raise a DecodingError, typically indicating that a helper subprocess used for decoding has exited with an error.

Downmixer Objects

class audiotools.pcmconverter.Downmixer(pcmreader)

This class takes a audiotools.PCMReader-compatible object, presumably with more than two channels, and constructs a audiotools.PCMReader-compatible object with only two channels mixed in Dolby Pro Logic format such that a rear channel can be restored.

If the stream has fewer than 5.1 channels, those channels are padded with silence. Additional channels beyond 5.1 are ignored.

Downmixer.sample_rate

The sample rate of this audio stream, in Hz, as a positive integer.

Downmixer.channels

The number of channels in this audio stream, which is always 2.

Downmixer.channel_mask

The channel mask of this audio stream, which is always 0x3.

Downmixer.bits_per_sample

The number of bits-per-sample in this audio stream as a positive integer.

Downmixer.read(pcm_frames)

Try to read a audiotools.pcm.FrameList object with the given number of PCM frames, if possible. This method is not guaranteed to read that amount of frames. It may return less, particularly at the end of an audio stream. It may even return FrameLists larger than requested. However, it must always return a non-empty FrameList until the end of the PCM stream is reached. May raise IOError if there is a problem reading the source file, or ValueError if the source file has some sort of error.

Downmixer.close()

Closes the audio stream. If any subprocesses were used for audio decoding, they will also be closed and waited for their process to finish. May raise a DecodingError, typically indicating that a helper subprocess used for decoding has exited with an error.

Resampler Objects

class audiotools.pcmconverter.Resampler(pcmreader, sample_rate)

This class takes a audiotools.PCMReader-compatible object and new sample_rate integer, and constructs a new audiotools.PCMReader-compatible object with that sample rate.

Resampler.sample_rate

The sample rate of this audio stream, in Hz, as given at init-time.

Resampler.channels

The number of channels in this audio stream as a positive integer.

Resampler.channel_mask

The channel mask of this audio stream as a non-negative integer.

Resampler.bits_per_sample

The number of bits-per-sample in this audio stream as a positive integer.

Resampler.read(pcm_frames)

Try to read a audiotools.pcm.FrameList object with the given number of PCM frames, if possible. This method is not guaranteed to read that amount of frames. It may return less, particularly at the end of an audio stream. It may even return FrameLists larger than requested. However, it must always return a non-empty FrameList until the end of the PCM stream is reached. May raise IOError if there is a problem reading the source file, or ValueError if the source file has some sort of error.

Resampler.close()

Closes the audio stream. If any subprocesses were used for audio decoding, they will also be closed and waited for their process to finish. May raise a DecodingError, typically indicating that a helper subprocess used for decoding has exited with an error.