audiotools.replaygain — the ReplayGain Calculation Module

The audiotools.replaygain module contains the ReplayGain class for calculating the ReplayGain gain and peak values for a set of PCM data, and the ReplayGainReader class for applying those gains to a audiotools.PCMReader stream.

ReplayGain Objects

class audiotools.replaygain.ReplayGain(sample_rate)

This class performs ReplayGain calculation for a stream of the given sample_rate. Raises ValueError if the sample rate is not supported.

ReplayGain.sample_rate

The sample rate given when the object was initialized.

ReplayGain.update(framelist)

Given a pcm.FrameList object, updates the current gain values with its data.

ReplayGain.title_gain()

Returns the gain value of the current title as a positive or negative floating point value. May raise ValueError if not enough samples have been submitted for processing.

ReplayGain.title_peak()

Returns the peak value of the title as a floating point value between 0.0 and 1.0.

ReplayGain.album_gain()

Returns the gain value of the entire album as a positive or negative floating point value. May raise ValueError if not enough samples have been submitted for processing.

ReplayGain.album_peak()

Returns the peak value of the entire album as a floating point value between 0.0 and 1.0.

ReplayGain.next_title()

Indicates the current track is finished and resets the stream to process the next track. This method should be called after ReplayGain.title_gain() and ReplayGain.title_peak() have been used to extract the title’s gain values, but before data has been submitted for the next title or ReplayGain.album_gain() ReplayGain.album_peak() have been called to get the entire album’s gain values.

ReplayGainReader Objects

class audiotools.replaygain.ReplayGainReader(pcmreader, gain, peak)

This class wraps around an existing PCMReader object. It takes floating point gain and peak values and modifies the pcmreader’s output as necessary to match those values. This has the effect of raising or lowering a stream’s sound volume to ReplayGain’s reference value.