Skip to main content
Skip table of contents

WaveShaperAtan

Overview

Wave shaper nonlinearity using either linear interpolation or math function

Discussion

The module implements arctangent wave shaping. The arctangent is a part of a family of functions called sigmoid functions. Sigmoid functions produce S-shaped curves. The amplitude transfer function of a vacuum tube generally resembles a sigmoid, so this function can be used to try to mimic a tube sound. With the arctangent function atan(kx), where k controls the amplitude of the input value and thus the amount of nonlinear processing applied. The exact equation is:

y(n) = ( 1 / (arctan(k)) ) * arctan(k*x(n))

A normalization factor has been added to retrict the output to the range of -1 to +1. With k=1 the input/output relationship is nearly linear. As k increases, the S-shaped curve emerges and adds gain.

Asymmetrical distortion can be implemented easily by using two different k-values, one for positive input samples and the other for negative ones. This asymetrical distortion is found in Class-A tube circuits. Cascading multiple stages will result in more harmonic distortion. In some amplifiers curves are also inverted in between each stage. The resulting sound is quite different than simply cascading the modules without inversion.

Optional: Wave shaper module using table lookup and linear interpolation.

Type Definition

CODE
typedef struct _ModuleWaveShaperAtan
{
    ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
    INT32 numStages;                              // The number of stages in series
    INT32 invStages;                              // Inverting or not inverting every other stage when cascaded
    FLOAT32 kPos;                                 // Defines the amount of nonlinear processing for the positive half of the input signal
    FLOAT32 kNeg;                                 // Defines the amount of nonlinear processing for the negative half of the input signal
    INT32 useTableLookup;                         // Shaping via lookup table
    FLOAT32 minX;                                 // X value corresponding to the first table entry.
    FLOAT32 maxX;                                 // X value corresponding to the last table entry.
    INT32 L;                                      // Number of entries in the table.
    FLOAT32 divisor;                              // Precomputed constant = (L-1)/(maxX-minX) to eliminate division on the target.
    INT32 tableHeap;                              // Heap in which to allocate memory.
    FLOAT32* table_atan;                          // Array of arctan table values
} ModuleWaveShaperAtanClass;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

numStages

int

parameter

0

1

1:5

invStages

int

parameter

0

0

0:1

kPos

float

parameter

0

1

0.1:5

kNeg

float

parameter

0

1

0.1:5

useTableLookup

int

parameter

0

0

0:1

minX

float

const

1

-5

Unrestricted

maxX

float

const

1

5

Unrestricted

L

int

const

1

64

2:1:8192

divisor

float

const

1

6.3

Unrestricted

tableHeap

int

const

1

2

Unrestricted

table_atan

float*

parameter

1

[64 x 1]

Unrestricted

Pins

Input Pins

Name: in

Description: Audio input

Data type: float

Channel range: Unrestricted

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

Output Pins

Name: out

Description: Audio output

Data type: float

MATLAB Usage

File Name: wave_shaper_atan_module.m

CODE
 M = wave_shaper_atan_module(NAME, MAXPREGAIN, TABLESIZE, MEMHEAP)
 Module that implements a wave shaper function deploying a 
 table lookup (linear interpolation). It additionally allows the user to 
 control the amount of nonlinear processing applied. Cascading multiple
 stages result in more harmonic distortion.
 Arguments:
   NAME        - Name of the module
   MAXPREGAIN  - Max pre gain (defines max distortion)
   TABLESIZE   - Defines the size of the look-up-table
   MEMHEAP     - Specifies the memory heap to use to allocate the table
                 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 (the default).
                 'AWE_HEAP_FAST2SLOW' - use internal memory. If this fails
                 then use external memory (the default)

JavaScript errors detected

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

If this problem persists, please contact our support.