Search guides and the APICtrl K
  1. API reference
  2. DSP

granular.h

A granular engine.

#include <sonore/granular.h>
On this page

Design notes

Grains: short windowed slices of a buffer, started on a schedule, each played at its own rate and position, overlapping into a cloud. The same machine is a texture generator, a pitch shifter, a freeze and a smear depending on four numbers -- size, density, position, pitch -- and it is the one "granular" every request means. The buffer is written live (it is a delay you can scatter; stop writing and it is a freeze) or loaded once (a sample you can stretch).

Decisions:

The scheduler is a phase accumulator at `density` grains per second, so
density is what it says and fractional densities work. `jitter` scatters
each grain's start around the position so the cloud does not buzz at
the scheduling rate -- a regular grain train IS a pulse train, and it
has that pitch.
Grains read with the cubic tap, because a grain at a pitch ratio is a
sweeping read.
Hann windows. Equal-power pan per grain across `spread`.
A grain that runs off the live write head is a grain reading the future;
the position is clamped a window behind the head, and a grain whose
pitch would carry it past the head before it ends is SHORTENED to fit.
The level is the physical sum of the grains -- no hidden normalisation,
because the overlap (density × size) is the user's texture control and a
gain that moved with it would fight the knob.

Included by dsp.h. Uses Random from random.h.

Types 1

template <int MaxGrains = 32, int BufferSamples = 192000> class GrainEngine

SIZE: BufferSamples floats -- 768 KB at the default four seconds at 48 kHz. A member of the plugin, never a local.

↑↓ to move↵ to openEvery public name in the headers, and every guide