SPKitWaveShaper
User's Guide
SPKitWaveShaper is a waveshaping (a.k.a. non-linear distortion) class.
SPKitWaveShaper is connected to its input with either the
setInputAndBuffer(SPKitProcessor* ip, SPKitProcessor* bufInput)
or
setInputAndBuffer(SPKitProcessor* ip, SPKitReader* bufInput)
function,
where ip is the signal input
and bufInput is a pointer to an instance of
either an
SPKitProcessor
or an
SPKitReader
that supplies a transfer function
used by the waveshaping algorithm.
The
bufInput
object
will typically supply a short signal containing sweep
starting from a sample value of -1.0 and ending up at a value of 1.0.
SPKitWaveShaper reads signal from bufInput
at initialization time
and stores it in a lookup table.
Defaulf lookup table size is 1024 samples.
It can be changed either by using a constructor
that accepts a table size as a parameter
or by specifying an SPKitReader as the bufInput parameter for
the setInputAndBuffer() initialization function.
In the latter can, lookup table size is retrieved from the
file size of the SPKitReader object.
The bufInput signal must be monophonic.
SPKitWaveShaper processes the input signal
by matching the input sample values with
the values stored in the lookup table.
By default,
the input samples are expected to be normalized between
-1 and 1, like a regular SPKit audio signal.
There, input sample are converted to indeces for
the lookup table so that an input sample value of -1.0
is taken to be the index of the first item
and a value of 1.0 is taken to be the index of the last item.
The setInputSignalRange() function can be used to
choose alternative values for minimum and maxmimum
signal limits, instead of the default -1 and 1.
Linear interpolation is used to smooth out
the output signal.
For a more detailed description of waveshaping,
see Dodge & Jerse(1985:128-149).
Programmer's Reference
Defined in <spkit/waveshap.h>
Inherits from SPKitProcessor
SPKitWaveShaper
defines a
setInputAndBuffer(SPKitProcessor* ip,
SPKitReader* bufInput)
function for initializing and connecting the object to its input
and to a SPKitReader object which
supplies a transformation table.
SPKitWaveShaper also overrides
getSample().
Public Members
-
SPKitWaveShaper()
- the default constructor.
Sets size to 1024.
-
SPKitWaveShaper(SPKitInt bufSize)
- an alternative constructor.
Sets size to bufSize.
- SPKitError
setInputAndBuffer(SPKitProcessor* ip,
SPKitProcessor* bufInput)
- connect an input to the object and initialize it.
The function initializes the transfer function storage
buffer
by reading it from bufInput.
Calls
SPKitProcessor::setInput().
- SPKitError
setInputAndBuffer(SPKitProcessor* ip,
SPKitReader* bufInput)
- connect an input to the object and initialize it.
The function initializes the transfer function storage
buffer
by reading it from bufInput.
Calls
SPKitProcessor::setInput().
- void
setInputSignalRange(SPKitFloat
min, SPKitFloat max)
- set input signal range to min..max.
Input samples are scaled to
buffer
indeces according to the input
signal range.
Sets
lowLimit
to
min
and
highLimit
to
max.
- int getSample(SPKitSample& outputSample,
SPKitProcessor* caller)
- retrieve a processed audio sample
getSample() requests a sample from its input and
calculates a new value from a lookup table
using linear interpolation.
The lookup table is stored in buffer.
The result is stored in outputSample.
The function returns 0 when its input
runs out of samples, 1 otherwise.
Protected Members
- SPKitInt size
- size of buffer
- SPKitInt halfSize
- half the size of buffer (Obsolete!)
- SPKitSample* buffer
- buffer containing the waveshaping transfer function lookup table
- SPKitSample maxValue
- value of the last item stored in buffer
- SPKitSample minValue
- value of the first item stored in buffer
- SPKitSample lowLimit
- minimum input signal value
- SPKitSample inputRange
- range between minimum and maximum input signal values.
- SPKitSample inputScale
- a scaling factor (= 1/inputRange).