PitchShiftEffect

class PitchShiftEffect(windowSize: Int = 1024) : CustomAudioEffect

CustomAudioEffect that shifts the pitch up (or down) keeping the output buffer exactly the same size as the input, so it never breaks the audio pipeline. With pitch> 1 you get the typical "chipmunk"/squirrel voice.

Unlike a plain resample (which would change the number of samples and therefore the buffer size), this is a time-domain pitch shifter: a delay line whose read position drifts against the write position at the pitch ratio. Two read taps offset by half the window are Hann-crossfaded so the wrap-around is inaudible (the two Hann windows offset by half a period sum to 1 → constant amplitude). Because it produces one output sample per input sample, the length is preserved.

Expects 16 bit little endian PCM (the format the microphone delivers). It is designed for mono; interleaved stereo still sounds fine but bleeds slightly between channels at the tap boundary.

Constructors

Link copied to clipboard
constructor(windowSize: Int = 1024)

Properties

Link copied to clipboard

Pitch ratio. 1f keeps the original pitch, values > 1f raise it (chipmunk), values < 1f lower it. Clamped to a sane range to avoid heavy aliasing.

Functions

Link copied to clipboard
open override fun process(pcmBuffer: ByteArray): ByteArray