How Audacity Changes Pitch Without Changing Duration
Audacity alters an audio track's pitch without affecting its duration by utilizing advanced time-scale modification (TSM) and digital signal processing (DSP) algorithms, primarily powered by the open-source SoundTouch library. In analog audio, changing pitch inherently alters playback speed, making audio shorter when pitched up or longer when pitched down. Audacity bypasses this physical limitation by mathematically decoupling the audio's frequency information from its time domain, shifting the fundamental frequencies while reconstructing the original timing through overlapping sample grains or phase analysis.
The Problem with Traditional Resampling
When you speed up a digital audio file by resampling, you pack more waveform cycles into a shorter span of time. This increases the frequency (raising the pitch) while simultaneously reducing the playback duration. Conversely, slowing it down drops the frequency and lengthens the track. To change pitch independently, software must either shift frequencies without moving time, or resample the audio and immediately counteract the resulting length change.
The SoundTouch Engine and WSOLA
Under the hood, Audacity’s "Change Pitch" effect employs the SoundTouch library, which primarily uses a time-domain technique known as WSOLA (Waveform Similarity Overlap-Add) alongside sample-rate conversion:
- Resampling for Pitch Modification: The audio is first resampled to achieve the desired target pitch. For example, to raise the pitch by a few semitones, the algorithm effectively speeds up the playback rate of the audio data. At this intermediate stage, the pitch is correct, but the file is now too short.
- Time-Stretching via WSOLA: To restore the audio to its original duration without changing the new pitch, SoundTouch applies WSOLA. The audio stream is sliced into small overlapping fragments, called "grains," typically between 20 and 50 milliseconds long.
- Correlation Matching: The algorithm analyzes the waveform shapes at the borders of these grains. It calculates cross-correlation to find points of highest similarity between adjacent fragments.
- Overlap and Add (OLA): The grains are duplicated or spaced out (depending on whether the audio needs to be lengthened or shortened) and blended back together using crossfades. Because the fragments are aligned at points of waveform similarity, constructive and destructive phase interference is minimized.
Frequency-Domain Alternative: The Phase Vocoder
In alternative high-quality algorithms or spectral tools, Audacity relies on a Phase Vocoder based on the Short-Time Fourier Transform (STFT):
- Decomposition: The audio is converted from the time domain (amplitude over time) into the frequency domain (spectral components over time) using the Fast Fourier Transform (FFT).
- Bin Shifting: The frequencies within each spectral frame are shifted mathematically upward or downward to the targeted pitch.
- Phase Alignment: The phase values of each frequency bin must be recalculated so that when frames are placed back-to-back, the sine waves maintain continuity across boundaries.
- Synthesis: The Inverse Fast Fourier Transform (IFFT) converts the shifted spectral data back into an audible time-domain waveform with its original length preserved.
Mitigating Artifacts
Processing audio this way is computationally intensive and can introduce digital artifacts. Aggressive pitch shifting can cause "phasiness" (a hollow, robotic sound), transient smearing (softening the sharp attack of drums), or audible flutter. Audacity mitigates these issues by dynamically adjusting grain sizes and tracking transient peaks to ensure the pitch shift sounds as natural as possible across speech, instruments, and complex mixes.