pyglet.media.synthesis¶

class
ADSREnvelope
(attack, decay, release, sustain_amplitude=0.5)¶ A four part Attack, Decay, Suspend, Release envelope.
This is a four part ADSR envelope. The attack, decay, and release parameters should be provided in seconds. For example, a value of 0.1 would be 100ms. The sustain_amplitude parameter affects the sustain volume. This defaults to a value of 0.5, but can be provided on a scale from 0.0 to 1.0.
Parameters:  attack (float) – The attack time, in seconds.
 decay (float) – The decay time, in seconds.
 release (float) – The release time, in seconds.
 sustain_amplitude (float) – The sustain amplitude (volume), from 0.0 to 1.0.

get_generator
(sample_rate, duration)¶

class
Digitar
(duration, frequency=440, decay=0.996, **kwargs)¶ A guitarlike waveform.
A guitarlike waveform, based on the KarplusStrong algorithm. The sound is similar to a plucked guitar string. The resulting sound decays over time, and so the actual length will vary depending on the frequency. Lower frequencies require a longer length parameter to prevent cutting off abruptly.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 frequency (int) – The frequency, in Hz of the waveform you wish to produce.
 decay (float) – The decay rate of the effect. Defaults to 0.996.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

class
Envelope
¶ Base class for SynthesisSource amplitude envelopes.

get_generator
(sample_rate, duration)¶


class
FM
(duration, carrier=440, modulator=440, mod_index=1, **kwargs)¶ A simple FM waveform.
This is a simplistic frequency modulated waveform, based on the concepts by John Chowning. Basic sine waves are used for both frequency carrier and modulator inputs, of which the frequencies can be provided. The modulation index, or amplitude, can also be adjusted.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 carrier (int) – The carrier frequency, in Hz.
 modulator (int) – The modulator frequency, in Hz.
 mod_index (int) – The modulation index.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

class
FlatEnvelope
(amplitude=0.5)¶ A flat envelope, providing basic amplitude setting.
Parameters: amplitude (float) – The amplitude (volume) of the wave, from 0.0 to 1.0. Values outside of this range will be clamped. 
get_generator
(sample_rate, duration)¶


class
LinearDecayEnvelope
(peak=1.0)¶ A linearly decaying envelope.
This envelope linearly decays the amplitude from the peak value to 0, over the length of the waveform.
Parameters: peak (float) – The Initial peak value of the envelope, from 0.0 to 1.0. Values outside of this range will be clamped. 
get_generator
(sample_rate, duration)¶


class
Sawtooth
(duration, frequency=440, **kwargs)¶ A sawtooth waveform.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 frequency (int) – The frequency, in Hz of the waveform you wish to produce.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

class
Silence
(duration, sample_rate=44800, sample_size=16, envelope=None)¶ A silent waveform.

class
Sine
(duration, frequency=440, **kwargs)¶ A sinusoid (sine) waveform.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 frequency (int) – The frequency, in Hz of the waveform you wish to produce.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

class
Square
(duration, frequency=440, **kwargs)¶ A square (pulse) waveform.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 frequency (int) – The frequency, in Hz of the waveform you wish to produce.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

class
SynthesisSource
(duration, sample_rate=44800, sample_size=16, envelope=None)¶ Base class for synthesized waveforms.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

get_audio_data
(num_bytes, compensation_time=0.0)¶ Return num_bytes bytes of audio data.

save
(filename)¶ Save the audio to disk as a standard RIFF Wave.
A standard RIFF wave header will be added to the raw PCM audio data when it is saved to disk.
Parameters: filename (str) – The file name to save as.

seek
(timestamp)¶ Seek to given timestamp.
Parameters: timestamp (float) – Time where to seek in the source. The timestamp
will be clamped to the duration of the source.

class
TremoloEnvelope
(depth, rate, amplitude=0.5)¶ A tremolo envelope, for modulation amplitude.
A tremolo envelope that modulates the amplitude of the waveform with a sinusoidal pattern. The depth and rate of modulation can be specified. Depth is calculated as a percentage of the maximum amplitude. For example: a depth of 0.2 and amplitude of 0.5 will fluctuate the amplitude between 0.4 an 0.5.
Parameters:  depth (float) – The amount of fluctuation, from 0.0 to 1.0.
 rate (float) – The fluctuation frequency, in seconds.
 amplitude (float) – The peak amplitude (volume), from 0.0 to 1.0.

get_generator
(sample_rate, duration)¶

class
Triangle
(duration, frequency=440, **kwargs)¶ A triangle waveform.
Parameters:  duration (float) – The length, in seconds, of audio that you wish to generate.
 frequency (int) – The frequency, in Hz of the waveform you wish to produce.
 sample_rate (int) – Audio samples per second. (CD quality is 44100).
 sample_size (int) – The bit precision. Must be either 8 or 16.

class
WhiteNoise
(duration, sample_rate=44800, sample_size=16, envelope=None)¶ A white noise, random waveform.