Skip to content

Add freeze property to audiodelays.PitchShift - #11293

Open
relic-se wants to merge 1 commit into
adafruit:mainfrom
relic-se:pitchshift-freeze
Open

Add freeze property to audiodelays.PitchShift#11293
relic-se wants to merge 1 commit into
adafruit:mainfrom
relic-se:pitchshift-freeze

Conversation

@relic-se

@relic-se relic-se commented Sep 2, 2026

Copy link
Copy Markdown

This update adds the audiodelays.PitchShift.freeze flag to allow you to prevent any updates to the window and overlap buffer, holding the current sound to be repeated. As soon as freeze=True, normal operation resumes. This flag is reset whenever the audiosample buffer is reset as well.

Demonstration

# boot.py
import usb_audio
usb_audio.enable(
    sample_rate=16000,
)
# code.py
import audiodelays
import synthio
import time
import ulab.numpy as np
from usb_audio import usb_microphone

SAMPLE_SIZE = 1024
SAMPLE_VOLUME = 32767
ramp = np.linspace(-SAMPLE_VOLUME, SAMPLE_VOLUME, SAMPLE_SIZE, endpoint=False, dtype=np.int16)

synth = synthio.Synthesizer(
    channel_count=1,
    sample_rate=16000,
)

pitch_shift = audiodelays.PitchShift(
    mix=0.0,
    semitones=12.0,
    window=2048,
    overlap=512,
    channel_count=1,
    sample_rate=16000,
)

usb_microphone.play(pitch_shift.play(synth))

note = synthio.Note(
    frequency=synthio.midi_to_hz(60),  # middle C
    amplitude=0.25,
    waveform=ramp,
)

while True:
    print("press")
    synth.press(note)
    time.sleep(1)
    print("pitch_shift on")
    pitch_shift.mix = 0.5
    time.sleep(1)
    print("freeze")
    pitch_shift.freeze = True
    time.sleep(1)
    print("release")
    synth.release(note)
    time.sleep(1)
    print("unfreeze")
    pitch_shift.freeze = False
    time.sleep(1)
    print("pitch_shift off")
    pitch_shift.mix = 0.0
    time.sleep(1)

pitch-shift-freeze.mp3

@relic-se

relic-se commented Sep 2, 2026

Copy link
Copy Markdown
Author

The failing test is "test_zlib_decompress_binary_bytes" within the zephyr build. Not related to this PR from what I can tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant