Effects - Quefumas/gensound GitHub Wiki

This is a collection of Transforms available under gensound.effects and which provide various effects, whereas the Transforms Guide is dedicated to the most essential Transforms.

Downsample

This effect makes every nth sample override the following (n-1) samples. This changes the frequency content of the audio and creates a nice effect somewhat reminiscent of 8-bit music. It accepts the argument factor, equivalent to n in the description above. For example, if factor=4, it means that samples 1,2 and 3 will be set to be the same as sample 0; samples 5, 6 and 7 will be set to be the same as sample 4; etc.

from gensound import test_wav, WAV
from gensound.effects import Downsample

w = WAV(test_wav)*Downsample(factor=4)
w.play() # sounds funny

Stretch

Stretches/shrinks audio on the time scale, making it run slower/faster and with lower/higher pitch. Expects to receive exactly one of the following arguments:

  • rate - a positive number, indicating the relative rate at which the audio is to be played. For example, a rate of 1 indicates no change in speed, while a rate of 0.5 means the audio will be played twice as slow (and sounding an octave lower).
  • duration - a positive number, indicating the desired time span of the resulting audio (integer for number of samples, float for milliseconds, as usual). This allows the user to ensure the audio will fit a given time span regardless of its original duration.
from gensound import test_wav, WAV
from gensound.effects import Stretch

w = WAV(test_wav)*Stretch(rate=0.5)
w.play() # will be played at half speed

Vibrato

This effect creates periodic pitch shifts in the audio by varying the speed at which it is played. The speed changes according to a periodic function, also known as an LFO. Currently only the Sine-shaped LFO is available.

Vibrato receives two arguments:

  • frequency - this is the frequency at which the LFO operates in Hz. Typical values lie within the range of 4-10, but go ahead and try other positive numbers as well!
  • width - this measures how 'extreme' the pitch shift is. More specifically, it measures how much the pitch rises and drops, and is measured in semitones. Typical values are within the range of 0 to 1 (0 providing no effect at all), but larger values will yield hilarious results.

Example:

from gensound import test_wav, WAV, Vibrato

w = WAV(test_wav)[10e3:30e3]
w *= Vibrato(frequency=4, width=0.2)

w.play()

The arguments in the example result in a Vibrato effect which raises the pitch to be 0.2 of a semitone higher than the original, then dropping to 0.2 lower than the original, four times every second.