mrcrowbar.sound module

class mrcrowbar.sound.AudioInterpolation(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

LINEAR = 1

Perform sharp linear interpolation between samples. This is the algorithm used by most early DSPs, such as the one in the original Sound Blaster, and has a pleasing brightness and crispness to it.

NONE = 0

Perform no audio interpolation and let PortAudio sort it out. (Sounds like CUBIC)

STEP = 2

Perform sharp step interpolation between samples. I’m sure if you go nasty enough, you could find a DSP that sounds like this. This sounds like LINEAR, except with more distortion.

mrcrowbar.sound.mix_linear(a, b, alpha)
mrcrowbar.sound.mix_step(a, b, alpha)
mrcrowbar.sound.normalise_audio(source, format_type, field_size, signedness, endian, start=None, end=None, length=None)[source]
mrcrowbar.sound.normalise_audio_iter(source, format_type, field_size, signedness, endian, start=None, end=None, length=None, overlap=0, chunk_size=8192)[source]
mrcrowbar.sound.play_pcm(source, channels, sample_rate, format_type, field_size, signedness, endian, start=None, end=None, length=None, interpolation=AudioInterpolation.LINEAR)[source]

Play back a byte string as PCM audio.

source

The byte string to play.

channels

Number of audio channels.

sample_rate

Audio sample rate in Hz.

format_type

Type of sample encoding; either int or float.

field_size

Size of each sample, in bytes.

signedness

Signedness of each sample; either ‘signed’ or ‘unsigned’.

endian

Endianness of each sample; either ‘big’, ‘little’ or None.

start

Start offset to read from (default: start).

end

End offset to stop reading at (default: end).

length

Length to read in (optional replacement for end).

interpolation

Interpolation algorithm to use for upsampling. Defaults to AudioInterpolation.LINEAR.

mrcrowbar.sound.resample_audio_iter(source, format_type, field_size, signedness, endian, channels, sample_rate, start=None, end=None, length=None, interpolation=AudioInterpolation.LINEAR, output_rate=44100)[source]