audiofilters – Support for audio filter effects

The audiofilters module contains classes to provide access to audio filter effects.

Available on these boards
  • Adafruit Feather RP2350
  • Adafruit Metro RP2350
  • Challenger+ RP2350 BConnect
  • Challenger+ RP2350 WiFi6/BLE5
  • Cytron IRIV IO Controller
  • Cytron MOTION 2350 Pro
  • Datanoise PicoADK V2
  • Music Thing Modular Workshop Computer
  • Pimoroni PGA2350
  • Pimoroni Pico Plus 2
  • Pimoroni Pico Plus 2 W
  • Pimoroni Plasma 2350
  • Pimoroni Plasma 2350W
  • Pimoroni Tiny 2350
  • RP2350 Stamp
  • RP2350 Stamp XL
  • Raspberry Pi Pico 2
  • Raspberry Pi Pico 2 W
  • Seeeduino XIAO RP2350
  • SparkFun Pro Micro RP2350
  • SparkFun Thing Plus RP2350
  • W5100S-EVB-Pico2
  • Waveshare RP2350-GEEK
  • Waveshare RP2350-LCD-0.96
  • Waveshare RP2350-LCD-1.28
  • Waveshare RP2350-One
  • Waveshare RP2350-Plus
  • Waveshare RP2350-TOUCH-LCD-1.28
  • Waveshare RP2350-Tiny
  • Waveshare RP2350-Zero

class audiofilters.DistortionMode

The method of distortion used by the audiofilters.Distortion effect.

CLIP: DistortionMode

Digital distortion effect which cuts off peaks at the top and bottom of the waveform.

LOFI: DistortionMode

Low-resolution digital distortion effect (bit depth reduction). You can use it to emulate the sound of early digital audio devices.

OVERDRIVE: DistortionMode

Emulates the warm distortion produced by a field effect transistor, which is commonly used in solid-state musical instrument amplifiers. The audiofilters.Distortion.drive property has no effect in this mode.

WAVESHAPE: DistortionMode

Waveshaper distortions are used mainly by electronic musicians to achieve an extra-abrasive sound.

class audiofilters.Distortion(drive: synthio.BlockInput = 0.0, pre_gain: synthio.BlockInput = 0.0, post_gain: synthio.BlockInput = 0.0, mode: DistortionMode = DistortionMode.CLIP, soft_clip: bool = False, mix: synthio.BlockInput = 1.0, buffer_size: int = 512, sample_rate: int = 8000, bits_per_sample: int = 16, samples_signed: bool = True, channel_count: int = 1)

A Distortion effect

Create a Distortion effect where the original sample is manipulated to create a distorted

sound according to the DistortionMode.

The mix parameter allows you to change how much of the unchanged sample passes through to the output to how much of the effect audio you hear as the output.

Parameters:
  • drive (synthio.BlockInput) – Distortion power. Value can range from 0.0 to 1.0.

  • pre_gain (synthio.BlockInput) – Increases or decreases the volume before the effect, in decibels. Value can range from -60 to 60.

  • post_gain (synthio.BlockInput) – Increases or decreases the volume after the effect, in decibels. Value can range from -80 to 24.

  • mode (DistortionMode) – Distortion type.

  • soft_clip (bool) – Whether or not to soft clip (True) or hard clip (False) the output.

  • mix (synthio.BlockInput) – The mix as a ratio of the sample (0.0) to the effect (1.0).

  • buffer_size (int) – The total size in bytes of each of the two playback buffers to use

  • sample_rate (int) – The sample rate to be used

  • channel_count (int) – The number of channels the source samples contain. 1 = mono; 2 = stereo.

  • bits_per_sample (int) – The bits per sample of the effect

  • samples_signed (bool) – Effect is signed (True) or unsigned (False)

Playing adding a distortion to a synth:

import time
import board
import audiobusio
import synthio
import audiofilters

audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
effect = audiofilters.Distortion(drive=0.5, mix=1.0, buffer_size=1024, channel_count=1, sample_rate=44100)
effect.play(synth)
audio.play(effect)

note = synthio.Note(261)
while True:
    synth.press(note)
    time.sleep(0.25)
    synth.release(note)
    time.sleep(5)
deinit() None

Deinitialises the Distortion.

__enter__() Distortion

No-op used by Context Managers.

__exit__() None

Automatically deinitializes when exiting a context. See Lifetime and ContextManagers for more info.

drive: synthio.BlockInput

Distortion power. Value can range from 0.0 to 1.0.

pre_gain: synthio.BlockInput

Increases or decreases the volume before the effect, in decibels. Value can range from -60 to 60.

post_gain: synthio.BlockInput

Increases or decreases the volume after the effect, in decibels. Value can range from -80 to 24.

mode: DistortionMode

Distortion type.

soft_clip: bool

Whether or not to soft clip (True) or hard clip (False) the output.

mix: synthio.BlockInput

The rate the filtered signal mix between 0 and 1 where 0 is only sample and 1 is all effect.

playing: bool

True when the effect is playing a sample. (read-only)

play(sample: circuitpython_typing.AudioSample, *, loop: bool = False) None

Plays the sample once when loop=False and continuously when loop=True. Does not block. Use playing to block.

The sample must match the encoding settings given in the constructor.

stop() None

Stops playback of the sample.

class audiofilters.Filter(filter: synthio.Biquad | Tuple[synthio.Biquad] | None = None, mix: synthio.BlockInput = 1.0, buffer_size: int = 512, sample_rate: int = 8000, bits_per_sample: int = 16, samples_signed: bool = True, channel_count: int = 1)

A Filter effect

Create a Filter effect where the original sample is processed through a biquad filter

created by a synthio.Synthesizer object. This can be used to generate a low-pass, high-pass, or band-pass filter.

The mix parameter allows you to change how much of the unchanged sample passes through to the output to how much of the effect audio you hear as the output.

Parameters:
  • filter (Optional[synthio.Biquad|Tuple[synthio.Biquad]]) – A normalized biquad filter object or tuple of normalized biquad filter objects. The sample is processed sequentially by each filter to produce the output samples.

  • mix (synthio.BlockInput) – The mix as a ratio of the sample (0.0) to the effect (1.0).

  • buffer_size (int) – The total size in bytes of each of the two playback buffers to use

  • sample_rate (int) – The sample rate to be used

  • channel_count (int) – The number of channels the source samples contain. 1 = mono; 2 = stereo.

  • bits_per_sample (int) – The bits per sample of the effect

  • samples_signed (bool) – Effect is signed (True) or unsigned (False)

Playing adding a filter to a synth:

import time
import board
import audiobusio
import synthio
import audiofilters

audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
effect = audiofilters.Filter(buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0)
effect.filter = synth.low_pass_filter(frequency=2000, Q=1.25)
effect.play(synth)
audio.play(effect)

note = synthio.Note(261)
while True:
    synth.press(note)
    time.sleep(0.25)
    synth.release(note)
    time.sleep(5)
deinit() None

Deinitialises the Filter.

__enter__() Filter

No-op used by Context Managers.

__exit__() None

Automatically deinitializes when exiting a context. See Lifetime and ContextManagers for more info.

filter: synthio.Biquad | Tuple[synthio.Biquad] | None

A normalized biquad filter object or tuple of normalized biquad filter objects. The sample is processed sequentially by each filter to produce the output samples.

mix: synthio.BlockInput

The rate the filtered signal mix between 0 and 1 where 0 is only sample and 1 is all effect.

playing: bool

True when the effect is playing a sample. (read-only)

play(sample: circuitpython_typing.AudioSample, *, loop: bool = False) None

Plays the sample once when loop=False and continuously when loop=True. Does not block. Use playing to block.

The sample must match the encoding settings given in the constructor.

stop() None

Stops playback of the sample.