audiodelays – Support for audio delay effects

The audiodelays module contains classes to provide access to audio delay effects.

Available on these boards
  • 0xCB Gemini
  • 0xCB Helios
  • 42. Keebs Frood
  • 8086 RP2040 Interfacer
  • 8086 USB Interposer
  • Adafruit Feather RP2040
  • Adafruit Feather RP2040 Adalogger
  • Adafruit Feather RP2040 CAN
  • Adafruit Feather RP2040 DVI
  • Adafruit Feather RP2040 Prop-Maker
  • Adafruit Feather RP2040 RFM
  • Adafruit Feather RP2040 Scorpio
  • Adafruit Feather RP2040 ThinkInk
  • Adafruit Feather RP2040 USB Host
  • Adafruit Feather RP2350
  • Adafruit Feather RP2350 Adalogger
  • Adafruit Floppsy RP2040
  • Adafruit Fruit Jam
  • Adafruit ItsyBitsy RP2040
  • Adafruit KB2040
  • Adafruit Macropad RP2040
  • Adafruit Metro RP2040
  • Adafruit Metro RP2350
  • Adafruit QT Py RP2040
  • Adafruit QT2040 Trinkey
  • Adafruit Tinychad RP2350
  • Archi RP2040
  • Arduino Nano RP2040 Connect
  • BBQ20KBD
  • BLOK
  • Bradán Lane STUDIO Explorer Badge
  • COSMO-Pico
  • Challenger NB RP2040 WiFi
  • Challenger RP2040 LTE
  • Challenger RP2040 LoRa
  • Challenger RP2040 SD/RTC
  • Challenger RP2040 SubGHz
  • Challenger RP2040 WiFi
  • Challenger RP2040 WiFi/BLE
  • Challenger+ RP2350 BConnect
  • Challenger+ RP2350 WiFi6/BLE5
  • Cytron EDU PICO 2
  • Cytron EDU PICO W
  • Cytron IRIV IO Controller
  • Cytron MOTION 2350 Pro
  • Cytron Maker Nano RP2040
  • Cytron Maker Pi RP2040
  • Cytron Maker Uno RP2040
  • Datanoise PicoADK
  • Datanoise PicoADK V2
  • E-Fidget
  • ELECFREAKS PICO:ED
  • Electrolama minik
  • EncoderPad RP2040
  • Fig Pi
  • HEIA-FR Picomo V2
  • HEIA-FR Picomo V3
  • HXR.DK SAO Digital Multimeter
  • Hack Club Sprig
  • LILYGO T-DISPLAY
  • Maple Computing Elite-Pi
  • Melopero Shake RP2040
  • Music Thing Modular Workshop Computer
  • NXP Semiconductors FRDM-MCXN947
  • NXP Semiconductors MIMXRT1170-EVK
  • Noise Nugget 2040
  • Nordic Semiconductor nRF5340 DK
  • Oak Dev Tech BREAD2040
  • Oak Dev Tech Cast-Away RP2040
  • Oak Dev Tech RPGA Feather
  • Orpheus Pico
  • PCBCupid Glyph Mini 2040
  • POSIX/Native Boards Native simulator - native_sim
  • PROVES Kit v4
  • Pimoroni Badger 2040
  • Pimoroni Badger 2040 W
  • Pimoroni Badger 2350
  • Pimoroni Explorer
  • Pimoroni Inky Frame 5.7
  • Pimoroni Inky Frame 7.3
  • Pimoroni Interstate 75
  • Pimoroni Keybow 2040
  • Pimoroni Motor 2040
  • Pimoroni PGA2040
  • Pimoroni PGA2350
  • Pimoroni Pico DV Base W
  • Pimoroni Pico LiPo (16MB)
  • Pimoroni Pico LiPo (4MB)
  • Pimoroni Pico Plus 2
  • Pimoroni Pico Plus 2 W
  • Pimoroni Pico dv Base
  • Pimoroni PicoSystem
  • Pimoroni Plasma 2040
  • Pimoroni Plasma 2040W
  • Pimoroni Plasma 2350
  • Pimoroni Plasma 2350W
  • Pimoroni Servo 2040
  • Pimoroni Tiny 2040 (2MB)
  • Pimoroni Tiny 2040 (8MB)
  • Pimoroni Tiny 2350
  • Pimoroni Tiny FX
  • PyKey 18 Numpad
  • PyKey 44 Ergo
  • PyKey 60
  • PyKey 87 TKL
  • RF.Guru RP2040
  • RP2.65-F
  • RP2040 Stamp
  • RP2350 Stamp
  • RP2350 Stamp XL
  • Raspberry Breadstick
  • Raspberry Pi Pico
  • Raspberry Pi Pico 2
  • Raspberry Pi Pico 2 W
  • Raspberry Pi Pico W
  • Seeeduino XIAO RP2040
  • Seeeduino XIAO RP2350
  • Silicognition LLC RP2040-Shim
  • SparkFun MicroMod RP2040 Processor
  • SparkFun Pro Micro RP2040
  • SparkFun Pro Micro RP2350
  • SparkFun Thing Plus - RP2040
  • SparkFun Thing Plus RP2350
  • Studiolab Pico Expander
  • TinyCircuits Thumby
  • TinyCircuits Thumby Color
  • VCC-GND Studio YD RP2040
  • W5100S-EVB-Pico
  • W5100S-EVB-Pico2
  • W5500-EVB-Pico
  • W5500-EVB-Pico2
  • WK-50 Trackball Keyboard
  • Waveshare RP2040-GEEK
  • Waveshare RP2040-LCD-0.96
  • Waveshare RP2040-LCD-1.28
  • Waveshare RP2040-One
  • Waveshare RP2040-PiZero
  • Waveshare RP2040-Plus (16MB)
  • Waveshare RP2040-Plus (4MB)
  • Waveshare RP2040-TOUCH-LCD-1.28
  • Waveshare RP2040-Tiny
  • Waveshare RP2040-Zero
  • 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
  • WeAct Studio Pico
  • WeAct Studio Pico 16MB
  • WeAct Studio RP2350B Core
  • WisdPi Ardu2040M
  • WisdPi Tiny RP2040
  • nullbits Bit-C PRO
  • splitkb.com Liatris
  • takayoshiotake Octave RP2040
  • uGame22

class audiodelays.Chorus(max_delay_ms: int = 50, delay_ms: synthio.BlockInput = 50.0, voices: 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)

An Chorus effect

Create a Chorus effect by playing the current sample along with one or more samples

(the voices) from the delay buffer. The voices played are evenly spaced across the delay buffer. So for 2 voices you would hear the current sample and the one delay milliseconds back. The delay timing of the chorus can be changed at runtime with the delay_ms parameter but the delay can never exceed the max_delay_ms parameter. The maximum delay you can set is limited by available memory.

Parameters:
  • max_delay_ms (int) – The maximum time the chorus can be in milliseconds

  • delay_ms (synthio.BlockInput) – The current time of the chorus delay in milliseconds. Must be less the max_delay_ms.

  • voices (synthio.BlockInput) – The number of voices playing split evenly over the delay buffer.

  • mix (synthio.BlockInput) – How much of the wet audio to include along with the original signal.

  • 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 an chorus to a synth:

import time
import board
import audiobusio
import synthio
import audiodelays

audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
chorus = audiodelays.Chorus(max_delay_ms=50, delay_ms=5, buffer_size=1024, channel_count=1, sample_rate=44100)
chorus.play(synth)
audio.play(chorus)

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

Deinitialises the Chorus.

__enter__() Chorus

No-op used by Context Managers.

__exit__() None

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

delay_ms: synthio.BlockInput

The current time of the chorus delay in milliseconds. Must be less the max_delay_ms.

voices: synthio.BlockInput

The number of voices playing split evenly over the delay buffer.

mix: synthio.BlockInput

The rate the echo 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) Chorus

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.

Returns:

The effect object itself. Can be used for chaining, ie: audio.play(effect.play(sample)).

Return type:

Chorus

stop() None

Stops playback of the sample.

class audiodelays.Echo(max_delay_ms: int = 500, delay_ms: synthio.BlockInput = 250.0, decay: synthio.BlockInput = 0.7, mix: synthio.BlockInput = 0.25, buffer_size: int = 512, sample_rate: int = 8000, bits_per_sample: int = 16, samples_signed: bool = True, channel_count: int = 1)

An Echo effect

Create a Echo effect where you hear the original sample play back, at a lesser volume after

a set number of millisecond delay. The delay timing of the echo can be changed at runtime with the delay_ms parameter but the delay can never exceed the max_delay_ms parameter. The maximum delay you can set is limited by available memory.

Each time the echo plays back the volume is reduced by the decay setting (echo * decay).

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:
  • max_delay_ms (int) – The maximum time the echo can be in milliseconds

  • delay_ms (synthio.BlockInput) – The current time of the echo delay in milliseconds. Must be less the max_delay_ms

  • decay (synthio.BlockInput) – The rate the echo fades. 0.0 = instant; 1.0 = never.

  • 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)

  • freq_shift (bool) – Do echos change frequency as the echo delay changes

Playing adding an echo to a synth:

import time
import board
import audiobusio
import synthio
import audiodelays

audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
echo = audiodelays.Echo(max_delay_ms=1000, delay_ms=850, decay=0.65, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7, freq_shift=False)
echo.play(synth)
audio.play(echo)

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

Deinitialises the Echo.

__enter__() Echo

No-op used by Context Managers.

__exit__() None

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

delay_ms: synthio.BlockInput

Delay of the echo in milliseconds. (read-only)

decay: synthio.BlockInput

The rate the echo fades between 0 and 1 where 0 is instant and 1 is never.

mix: synthio.BlockInput

The rate the echo mix between 0 and 1 where 0 is only sample, 0.5 is an equal mix of the sample and the effect and 1 is all effect.

freq_shift: bool

Does the echo change frequencies as the delay changes.

playing: bool

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

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

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.

Returns:

The effect object itself. Can be used for chaining, ie: audio.play(effect.play(sample)).

Return type:

Echo

stop() None

Stops playback of the sample. The echo continues playing.

class audiodelays.MultiTapDelay(max_delay_ms: int = 500, delay_ms: synthio.BlockInput = 250.0, decay: synthio.BlockInput = 0.7, mix: synthio.BlockInput = 0.25, taps: Tuple[float | Tuple[float, float], Ellipsis] | None = None, buffer_size: int = 512, sample_rate: int = 8000, bits_per_sample: int = 16, samples_signed: bool = True, channel_count: int = 1)

A delay with multiple buffer positions to create a rhythmic effect.

Create a delay effect where you hear the original sample play back at varying times, or “taps”.

These tap positions and levels can be used to create rhythmic effects. The timing of the delay can be changed at runtime with the delay_ms parameter but the delay can never exceed the max_delay_ms parameter. The maximum delay you can set is limited by available memory.

Each time the delay plays back the volume is reduced by the decay setting (delay * decay).

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:
  • max_delay_ms (int) – The maximum time the delay can be in milliseconds.

  • delay_ms (float) – The current time of the delay in milliseconds. Must be less than max_delay_ms.

  • decay (synthio.BlockInput) – The rate the delay fades. 0.0 = instant; 1.0 = never.

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

  • taps (tuple) – The positions and levels to tap into the delay buffer.

  • 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 multi-tap delay to a synth:

import time
import board
import audiobusio
import synthio
import audiodelays

audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
effect = audiodelays.MultiTapDelay(max_delay_ms=500, delay_ms=500, decay=0.65, mix=0.5, taps=((2/3, 0.7), 1), 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.05)
    synth.release(note)
    time.sleep(5)
deinit() None

Deinitialises the MultiTapDelay.

__enter__() MultiTapDelay

No-op used by Context Managers.

__exit__() None

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

delay_ms: float

Time to delay the incoming signal in milliseconds. Must be less than max_delay_ms.

decay: synthio.BlockInput

The rate the echo fades between 0 and 1 where 0 is instant and 1 is never.

mix: synthio.BlockInput

The mix of the effect between 0 and 1 where 0 is only sample, 0.5 is an equal mix of the sample and the effect and 1 is all effect.

taps: Tuple[float | int | Tuple[float | int, float | int], Ellipsis]

The position or position and level of delay taps. The position is a number from 0 (start) to 1 (end) as a relative position in the delay buffer. The level is a number from 0 (silence) to 1 (full volume). If only a float or integer is provided as an element of the tuple, the level is assumed to be 1. When retrieving the value of this property, the level will always be included.

playing: bool

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

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

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.

Returns:

The effect object itself. Can be used for chaining, ie: audio.play(effect.play(sample)).

Return type:

MultiTapDelay

stop() None

Stops playback of the sample. The echo continues playing.

class audiodelays.PitchShift(semitones: synthio.BlockInput = 0.0, mix: synthio.BlockInput = 1.0, window: int = 1024, overlap: int = 128, buffer_size: int = 512, sample_rate: int = 8000, bits_per_sample: int = 16, samples_signed: bool = True, channel_count: int = 1)

A pitch shift effect

Create a pitch shift effect where the original sample play back is altered to change the

the perceived pitch by a factor of semi-tones (1/12th of an octave). This effect will cause a slight delay in the output depending on the size of the window and overlap buffers.

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:
  • semitones (synthio.BlockInput) – The amount of pitch shifting in semitones (1/12th of an octave)

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

  • window (int) – The total size in bytes of the window buffer used alter the playback pitch

  • overlap (int) – The total size in bytes of the overlap buffer used to prevent popping in the output. If set as 0, no overlap will be used.

  • 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)

Shifting the pitch of a synth by 5 semitones:

import time
import board
import audiobusio
import synthio
import audiodelays

audio = audiobusio.I2SOut(bit_clock=board.GP0, word_select=board.GP1, data=board.GP2)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
pitch_shift = audiodelays.PitchShift(semitones=5.0, mix=0.5, window=2048, overlap=256, buffer_size=1024, channel_count=1, sample_rate=44100)
pitch_shift.play(synth)
audio.play(pitch_shift)

while True:
    for notenum in (60, 64, 67, 71):
        synth.press(notenum)
        time.sleep(0.25)
        synth.release_all()
deinit() None

Deinitialises the PitchShift.

__enter__() PitchShift

No-op used by Context Managers.

__exit__() None

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

semitones: synthio.BlockInput

The amount of pitch shifting in semitones (1/12th of an octave).

mix: synthio.BlockInput

The output 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) PitchShift

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.

Returns:

The effect object itself. Can be used for chaining, ie: audio.play(effect.play(sample)).

Return type:

PitchShift

stop() None

Stops playback of the sample.