Skip to content

PeriodicFunctionGenTable

Discussion

Creates a general purpose function generator for use in the Audio Weaver environment by reading samples from a table. This module has a single channel output pin with controllable frequency. The output of the module changes instantly (no smoothing applied) when the frequency is updated. This module can generate sine, square, triangular and sawtooth waveforms with control variables.

At instantiation time you specify the total number of samples (TABLESIZE). By increasing the wavetable size, the precision of the linear interpolation becomes greater and will result in a closer fit to the idealised, intended curve. Naturally, larger wavetable sizes result in greater memory requirements.

FunctionType = 0 --> Sine wave

FunctionType = 1 --> Square wave

FunctionType = 2 --> Triangle wave

FunctionType = 3 --> Sawtooth wave

Module Pack

Standard

ClassID

classID = 249

Type Definition

typedef struct _ModulePeriodicFunctionGenTable
{
ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
INT32 functionType;                           // Type of the wave form to be generated on output
FLOAT32 freq;                                 // Frequency of the function generator output wave.
FLOAT32 amplitude;                            // Amplitude in linear units.
FLOAT32 offset;                               // Starting phase of the function generator output wave.
INT32 blockSize;                              // Block size
INT32 sampleRate;                             // Sample rate
INT32 tableSize;                              // Table size in samples
INT32 tableSizeI;                             // Table size value in fixed point format Q20.12
FLOAT32 scaleFRatio;                          // Scale factor for playback rate
FLOAT32 scalePhi;                             // Scale factor for target phi
INT32 fIndex;                                 // Current sample index in the wave table
INT32 stateHeap;                              // Heap in which to allocate memory
INT32 NCOFracBits;                            // Number of least-significant bits for the *fractional* part of the NCO word (word size: 32)
INT32 NCOIntBits;                             // Number of most-significant bits for the *integer* part of the NCO word (word size: 32). By default: 20 bits
FLOAT32 formatF;                              // Integer value of left-shift by NCOFracBits. Determines the precision of the linear interpolation.
FLOAT32 formatI;                              // Integer value of left-shift by NCOIntBits. Determines the maximum playback rate and the maximum size of a wave file in samples.
INT32 targetFRatio;                           // Instantaneous sample to sample phase increment.
INT32 updateActive;                           // Specifies whether the table is updating (=1) or fixed (=0)
INT32* table;                                 // Packed 16 bit sample buffer table
} ModulePeriodicFunctionGenTableClass;

Variables

Properties

Name Type Usage isHidden Default Value Range Units
functionType int parameter 0 0 0:3
freq float parameter 0 1000 0.01:23760 Hz
amplitude float parameter 0 1 0:2 linear
offset float parameter 0 0 0:359 degrees
blockSize int const 0 48 Unrestricted
sampleRate int const 0 48000 Unrestricted
tableSize int const 0 256 Unrestricted
tableSizeI int const 0 1048576 Unrestricted
scaleFRatio float derived 0 0.005333 Unrestricted
scalePhi float derived 0 0.7111 Unrestricted
fIndex int state 0 0 Unrestricted
stateHeap int const 1 561 Unrestricted
NCOFracBits int const 1 12 Unrestricted
NCOIntBits int const 1 20 Unrestricted
formatF float const 1 4096 Unrestricted
formatI float const 1 524300 Unrestricted
targetFRatio int derived 1 21845 Unrestricted
updateActive int state 1 0 0:1
table int* state 1 [129 x 1] Unrestricted

Pins

Output Pins

Name out
Description audio output
Data Type float

Matlab Usage

File Name: periodic_function_gen_table_module.m 
 M=periodic_function_gen_table_module(NAME, MODUS, BLOCKSIZE, SR, TABLESIZE, MEMHEAP) 
 Creates a general purpose function generator for use in the Audio Weaver  
 environment by reading samples from a table. This module has a single channel  
 output pin with controllable frequency. The output of the module changes  
 instantly (no smoothing applied) when the frequency is updated. This module  
 can generate sine, square, triangular and sawtooth wave with control variables. 

 Arguments: 
    NAME           - name of the module. 
    BLOCKSIZE      - number of samples per output channel.   
    SR             - sample rate of the output signal, in Hz.   
    TABLESIZE      - number of samples in wave table. By default, TABLESIZE = 256. 
    MEMHEAP        - specifies the memory heap to use to allocate the main 
                     state buffer. This is a string and follows the memory allocation 
                     enumeration in Framework.h. Allowable values are: 
                     'AWE_HEAP_FAST' - always use internal DM memory. 
                     'AWE_HEAP_FASTB' - always use internal PM memory. 
                     'AWE_HEAP_SLOW' - always use external memory. 
                     'AWE_HEAP_FAST2SLOW' - use internal memory. If this fails 
                     then use external memory (the default). 
                     'AWE_HEAP_FASTB2SLOW' - use internal memory. If this fails 
                     then use external memory. 

 Copyright 2024.  DSP Concepts, Inc.  All Rights Reserved. 

 AudioWeaverModule [This tag makes it appear under awe_help] 

Copyright (c) 2026 DSP Concepts, Inc.