# Build a time-stretch or tempo tool

> Change a recording's speed without changing its pitch, or its pitch without changing its speed: the three ways to build it, which Maru building blocks to start from, and what each one sounds like at the extremes.

Canonical: https://maru.audio/help/build-a-time-stretch-tool
Documentation index: https://maru.audio/help/llms.txt

Slowing a solo down to learn it, fitting a loop to a new tempo, stretching a
note into a drone, retuning a sample without the chipmunk effect: all of these
separate a recording's **time** from its **pitch**. A tape machine cannot; it
speeds both up together. This guide explains how to build a tool that can, and
what is ready in Maru today.

## Products you can build

- **A practice player.** Slow a song to 50 to 75 percent at the same pitch,
  loop a bar, and mute the part you are playing with
  [stem separation](https://maru.audio/help/split-a-song-into-stems.md).
- **A loop fitter.** Stretch a loop to the session tempo, using a beat grid from
  [beat tracking](https://maru.audio/help/follow-the-beat.md) to place the bar lines.
- **A sampler that keeps length.** Play a sample across the keyboard without the
  high notes getting shorter.
- **Ambient stretch.** Stretch a few seconds into minutes, or freeze a moment
  and let it evolve.
- **Vocal retune.** Move a phrase up or down while keeping its timing and
  voice character.

## Three ways to build it

| Method | How it works | Sounds best on | Artefacts at the extremes |
| --- | --- | --- | --- |
| **Granular** | Play many short, overlapping grains; move through the recording at one speed and play each grain at another | Textures, pads, ambient stretch, freezes | Smeared transients, a "cloudy" sound |
| **Overlap-add with alignment (WSOLA)** | Cut overlapping chunks and slide each one slightly so its waveform lines up with the last before joining | Speech, solo instruments, practice tools | Stutters on drums, doubling on chords |
| **Phase vocoder** | Analyse short FFT frames, keep each frequency's magnitude and advance its phase at the new rate | Mixes, chords, larger tempo changes | A phasey, distant sound; softened attacks |

Commercial stretchers combine these: they detect transients and keep them
intact, and stretch only the sound between them.

## What Maru has today

- **Granular stretch.** [Granular](https://maru.audio/modules/granular) scans through a recording
  at an adjustable speed while each grain plays at its own pitch. A scan speed
  below 1 slows the material down at the same pitch, 0 freezes it, and a
  negative speed runs it backwards. This is the fastest way to a stretch product
  and works well for textures. [Granular synthesis](https://maru.audio/learn/granular-synthesis.md)
  in Learn explains grains.
- **Pitch without time.** `@maruaudio/dsp` includes delay-based and
  pitch-synchronous pitch shifters, including one with formant control for
  voices. Use them for retuning without changing length.
- **The parts for the other two methods.** Fractional delays for overlap-add,
  and a real FFT for a phase vocoder.

What is missing is a dedicated, transient-aware time-stretch building block for
speech and full mixes. A shared stretch leaf is planned; until then, build on
the granular engine or assemble overlap-add from the parts above.

## Design choices

- **Stretch a loaded clip, not live input.** Slowing down live audio means
  falling further behind it. Load the recording into a resource and stretch
  from there.
- **Keep transients.** Detect onsets and play them without stretching, then
  stretch the gaps; drums survive far better.
- **Stereo stays together.** Make the same stretching decisions for both
  channels, or the image wanders.
- **Show the ratio honestly.** Beyond about half or double speed, every method
  colours the sound. Say so in the interface rather than hiding it.

## Ask your agent

```text
Read the Maru Help article "Build a time-stretch or tempo tool". Then read
Granular's source with `maru module files granular` and `maru module read
granular src/shared/granular-bank.ts`, especially its scan speed. Build a
practice player that loads a song, plays it from 50 to 100 percent speed at the
same pitch, and loops a section I mark.
```

Developers can find the building blocks in the [DSP library](https://maru.audio/docs/dsp.md).
