In this lesson, you will learn how to construct a functional granular synthesis engine within MetaSounds to dynamically slice and re-sequence audio buffers.
At its core, granular synthesis works by breaking a sound source into tiny "grains" (usually 10ms to 100ms in length) and playing them back at different positions, densities, and pitches. In MetaSounds, we achieve this by controlling the Play Position of an Wave Player node through a high-frequency trigger system.
Constructing the Grain Engine
To build this, you need a Trigger Repeat node. This node acts as the heartbeat of your engine, firing a signal at a defined frequency (e.g., 50Hz). Each time this trigger fires, it executes two main tasks:
- Randomize Position: Connect a
Random Floatnode to theSeekinput of yourWave Player. By constraining the range of this float to a subset of your audio file’s duration, you force the player to "jump" to a new playback point every time a grain is triggered. - Envelope Shaping: If you simply jump playback positions, you will hear harsh "clicks" at the grain boundaries. You must multiply your audio output by a
Gainnode driven by anEnvelope(typically a Hanning or Gaussian window shape).
// Logic flow for a single grain trigger
[Trigger Repeat (Interval: 20ms)]
--> [Random Float (Min: 0.0, Max: FileDuration)]
--> [Wave Player (Seek)]
--> [Envelope Node (Triggered by same repeat)]
--> [Audio Output]
Dynamic Control via MetaSound Inputs
To make this engine "real-time," promote your Wave Player parameters and your Trigger Repeat interval to MetaSound Inputs. By creating Float inputs for GrainDensity and PositionJitter, you allow Blueprints to communicate with the MetaSound at runtime.
When you adjust a slider in your UI (using the MVVM patterns we studied previously), you are essentially piping a value into the Trigger Repeat interval. This creates a direct, tangible link between the player's interaction and the granular texture, allowing you to morph soundscapes by shifting the speed of grain generation or the spread of the playback window.
Key Takeaway: Granular synthesis in MetaSounds is achieved by driving a Wave Player’s seek position with high-frequency triggers while simultaneously applying amplitude envelopes to prevent audible clicks at grain boundaries.