SPKitDynamicsProcessor
User's Guide
SPKitDynamicsProcessor a base class of
SPKit dynamics processing classes.
These include
SPKitCompressor,
SPKitGate
and
SPKitLimiter.
SPKitDynamicsProcessor implements
a setInputAndEstimationTime(SPKitProcessor* ip, SPKitFloat et)
initialization function,
which is used by the derived classes.
Estimation time (et)
is used for setting the time (in seconds),
that the object will use for
estimating the maximum level of the input signal
(i.e. "attack" and "decay" time).
A usable value is 0.05 (50 milliseconds).
SPKitDynamicsProcessor also implements
setThreshold(SPKitFloat value)
and getTreshold() functions
for setting and retrieving a threshold amplitude value.
The threshold is used by the derived classes.
Notes:
- SPKitDynamicsProcessor stores audio samples
in an internal buffer.
The buffer is filled by reading several samples
in a loop from its input.
This will cause unexpected results
if the input is a multiplexer object
(SPKitMux).
- SPKitDynamicsProcessor is an abstract class
Programmer's Reference
Defined in <spkit/dynamics.h>
Inherits from SPKitProcessor
SPKitDynamicsProcessor
defines a
setInputAndEstimationTime()
function
for initialization
and overrides
getSample().
A derived class must implement a
scaleBuffer()
function for scaling the sample data
stored in the object's sampleBuffer.
Public Members
- SPKitError setInputAndEstimationTime(SPKitProcessor* ip, SPKitFloat et)
- connect an input to the object and initialize it.
Sets inputBufSize
to et * inputSamplingRate * inputChannelCount,
bufSize to 1.5 * inputBufSize
and allocates space for bufSize samples for
sampleBuffer.
Calls
SPKitProcessor::setInput().
- SPKitFloat getThreshold()
- return threshold
- int getSample(SPKitSample& outputSample)
- retrieve a processed audio sample.
Calls scaleBuffer().
Updates
absMax1,
absMax2,
writeIndex,
readIndex,
processIndex,
endOfInput
and
firstTime.
On the first call, getSample() fills
sampleBuffer
and calls scaleBuffer()
to process the first portion of the input signal.
The first processed sample is stored in
outputSample.
On subsequent calls, getSample() first
retrieves all processed samples from
sampleBuffer
and - when needed - refills the buffer
with the amount of
inputBufSize
samples.
getSample() calculates the absolute maximum
amplitude of the input signal on each refill operation,
and stores the value in absMax2.
The previous value of absMax2 is stored in
absMax1 before the refill.
Before calling scaleBuffer(),
getSample() sets
writeIndex
to indicate the first sample index
and
processIndex
to indicate the first sample index to be scaled.
The function returns 0 when all its inputs
run out of samples, 1 otherwise.
- void setThreshold(SPKitFloat value)
- set threshold to value
Protected Members
- void scaleBuffer()
- This is a pure virtual function which the derived classes
have to override.
A derived class typically interpolates
the sample values
stored in
sampleBuffer
and delimited by
writeIndex
and
processIndex.
absMax1
and
absMax2
may are used as reference amplitude values
for the first and last sample respectively.
The variables may also be checked against
threshold
to determine, whether the buffer should
be scaled or not.
See the source code of
SPKitLimiter and SPKitCompressor
for example implementations.
Note:
scaleBuffer() should not modify
any member variables inherited from
SPKitDynamicsProcessor.
- SPKitSample* sampleBuffer
- storage area for audio samples.
- SPKitInt bufSize
- size of sampleBuffer in samples
- SPKitInt halfInputBufSize
- bufSize / 2
- SPKitInt inputBufSize
- amount of samples that the object will request
from its input to refill
sampleBuffer
- SPKitInt readIndex
- index in sampleBuffer where the next input sample will be strored
- SPKitInt writeIndex
- index in sampleBuffer where the next output sample will be
retrieved from.
Also the index of the first sample which should be processed
by scaleBuffer()
- SPKitInt processIndex
- index in sampleBuffer of the last sample that should be processed
by scaleBuffer()
- SPKitFloat threshold
- an amplitude threshold value which
scaleBuffer() may use to determine,
if sampleBuffer must be processed or not.
Initially 0.7.
- SPKitFloat absMax1
- absolute maximum amplitude of the previous sample buffer
- SPKitFloat absMax2
- absolute maximum amplitude of the current sample buffer
- SPKitInt endOfInput
- Initially 0. Set to 1 when input runs out of samples.
Used to clean up sampleBuffer.
- SPKitInt firstTime
- Initially 1. Set to 0, when
sampleBuffer
is filled for the first time.