Skip to main content
Skip table of contents

GranularSynthesisWaveRAM

Overview

Synchronous Granular Synthesis Module Wave RAM

Discussion

This module implements (synchronous) granular synthesis functionality. The module reads data directly from the embedded wave file and performs granular synthesis.

At instantiation time the output block size and sample rate has to be specified.

The input pin fRatio is a floating-point number and specifies the step size between samples as they are played back. Internally, fRatio is smoothed on a block by block basis using the .smoothingTime variable.

If "playDir" parameter has been selected to "backward" or, if fRatio has a negative value [range 0..-1] and "playDir" parameter has been selected to "auto", the WAV file is played back in backward direction,

The module has input pin named filePos that specifies the starting position of the grains at audio rate. Values in the input pin ranges between 0 and 1, and the actual offset in the file is determined be multiplying it with the file length. The starting offset of each grain is determined internally and the value at that offset is read from filePos.

The module has input pin named panMod that specifies the panning coefficients of the grains at audio rate. Values in the input pin ranges between 0 and 1, the specified value is considered as panning coefficient for left channel. 1-coeff is considered as the panning for right channel.

This module uses 16-bit WAV samples and 16-bit internal math for speed.

Type Definition

CODE
typedef struct _ModuleGranularSynthesisWaveRAM
{
    ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
    INT32 grainSize;                              // Sets the length of each grain, denoted in milliseconds
    INT32 grainDensity;                           // Sets the number of grain samples per second
    INT32 playDir;                                // Playback direction, 0=Forward, 1=Backward, 2=Auto (derived from fRatio input pin)
    FLOAT32 gain;                                 // The peak level of the window
    INT32 smoothingTime;                          // Time constant of the pitch smoothing process
    INT32 windowLength;                           // Number of coefficients for current window
    INT32 waveLength;                             // Number of samples in currently loaded file
    INT32 maxGrainSize;                           // Maximum grain size in ms
    INT32 maxDensity;                             // Max density in grains per sec
    FLOAT32 normRate;                             // Rate of data used to compute the ratio for normalized players
    FLOAT32 maxRate;                              // Highest allowed rate of playback that can be specified
    UINT32 pinID;                                 // Specifies which control pins are available
    INT32 maxOverlapGrains;                       // Number of max. overlapping grains per maxGrainSize
    INT32 grainSizeSamples;                       // Length of each grain in samples
    INT32 interonsetTime;                         // Time between temporally adjacent grain onsets
    FLOAT32 waveRatio;                            // Sample ratio of the wave samples
    FLOAT32 windowRatio;                          // Sample ratio of the window coefficients
    INT32 waveSampleRate;                         // Actual sample rate of the wave file.
    INT32 waveNumChannels;                        // Number of channels in the wave file.
    FLOAT32 scaleFactor;                          // Scale factor for playback rate
    FLOAT32 smoothingCoeff;                       // Smoothing (pitch) coefficient
    INT32 grainIndex;                             // Current used vector index
    INT32 interonsetCnt;                          // Current interonset counter
    FLOAT32 smoothedFRatio;                       // Current (smoothed) rate at which audio is read from the input buffer
    FLOAT32* waveBuffer;                          // Data transferred from PC to target DSP via this buffer
    FLOAT32* window;                              // Window coefficients
    FLOAT32* window_coeffs;                       // Window coefficients
    INT32* GrainWavIndex;                         // Curr wave index of the intermediate vector element
    FLOAT32* GrainWavIndexF;                      // Curr wave index fract of the intermediate vector element
    FLOAT32* GrainWavFStep;                       // Curr wave step size of the intermediate vector element
    INT32* GrainEnvIndex;                         // Curr envelope index of the intermediate vector element
    FLOAT32* GrainEnvIndexF;                      // Curr envelope index fract of the intermediate vector element
    FLOAT32* GrainEnvFStep;                       // Curr envelope step size of the intermediate vector element
    INT32* GrainOffset;                           // Curr grain offset of the intermediate vector element
    FLOAT32* GrainPanCoeff;                       // Curr panning coefficient of the intermediate vector element
    INT32* GrainStatus;                           // Curr status ("active"/"inactive") of the intermediate vector element
} ModuleGranularSynthesisWaveRAMClass;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

grainSize

int

parameter

0

100

1:100

msec

grainDensity

int

parameter

0

10

1:100

playDir

int

parameter

0

0

0:2

gain

float

parameter

0

1

0:1

smoothingTime

int

parameter

0

100

0:1000

msec

windowLength

int

const

0

32

Unrestricted

waveLength

int

derived

0

8976

Unrestricted

maxGrainSize

int

const

1

100

0:100

msec

maxDensity

int

const

1

100

0:100

grains per sec

normRate

float

const

1

1

Unrestricted

maxRate

float

const

1

5

Unrestricted

pinID

uint

const

1

1

Unrestricted

maxOverlapGrains

int

const

1

10

Unrestricted

grainSizeSamples

int

derived

1

4800

Unrestricted

interonsetTime

int

derived

1

4800

Unrestricted

waveRatio

float

derived

1

1

Unrestricted

windowRatio

float

derived

1

1

Unrestricted

waveSampleRate

int

derived

1

48000

Unrestricted

waveNumChannels

int

derived

1

1

Unrestricted

scaleFactor

float

derived

1

1

Unrestricted

smoothingCoeff

float

derived

1

0.05194

Unrestricted

grainIndex

int

state

1

0

Unrestricted

interonsetCnt

int

state

1

0

Unrestricted

smoothedFRatio

float

state

1

1

Unrestricted

waveBuffer

float*

parameter

1

[8979 x 1]

Unrestricted

window

float*

parameter

1

[35 x 1]

Unrestricted

window_coeffs

float*

parameter

0

[32 x 1]

Unrestricted

GrainWavIndex

int*

state

1

[1 x 10]

Unrestricted

GrainWavIndexF

float*

state

1

[1 x 10]

Unrestricted

GrainWavFStep

float*

state

1

[1 x 10]

Unrestricted

GrainEnvIndex

int*

state

1

[1 x 10]

Unrestricted

GrainEnvIndexF

float*

state

1

[1 x 10]

Unrestricted

GrainEnvFStep

float*

state

1

[1 x 10]

Unrestricted

GrainOffset

int*

state

1

[1 x 10]

Unrestricted

GrainPanCoeff

float*

state

1

[1 x 10]

Unrestricted

GrainStatus

int*

state

1

[1 x 10]

Unrestricted

Pins

Input Pins

Name: fRatio

Description: Specifies playback ratio

Data type: float

Channel range: 1

Block size range: 1

Sample rate range: Unrestricted

Complex support: Real

Name: filePos

Description: Start point of the grain, located relative within the samples between 0(start)..1(end)

Data type: float

Channel range: 1

Block size range: 256

Sample rate range: Unrestricted

Complex support: Real

Name: panMod

Description: Controls panning for each grain; relative distribution between 0(max left)..1(max right)

Data type: float

Channel range: 1

Block size range: 256

Sample rate range: Unrestricted

Complex support: Real

Output Pins

Name: audio

Description: Output data

Data type: float

Scratch Pins

Channel count: 1

Block size: 256

Sample rate: 48000

Channel count: 1

Block size: 256

Sample rate: 48000

Channel count: 1

Block size: 256

Sample rate: 48000

MATLAB Usage

File Name: granular_synthesis_wave_ram_module.m

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.