dynamicslib
dynamicslib is a library designed to allow changing dynamic range of the input signal. To realize dynamic range control of the signal the ANSI C enviroment was used. The description of the algorithm for the dynamic range control is in the article Realization of the system for dynamic range control. This library dynamicslib uses the delaylib library to allow delaying of the input signal. The error codes of dynamicslib are the same as error codes of delaylib, so the return_error_string included from delaylib can be used.
CONTENTS
SYNOPSIS Dynamics Initialize Function Dynamics Run Function EXAMPLE
The functions of dynamicslib are defined as follows:
#include <delay.h>
int dynamics_init(
double D,/*delay time [samples]*/
int SRR,/*sampling rate reduction*/
double AT,/*attack time*/
double RT,/*release time*/
double TAV,/*averaging coefficient*/
double NT,/*noise gate threshold [dB] <0 */
double ET,/*expander threshold [dB] <0 */
double CT,/*compressor threshold [dB] <0 */
double LT,/*limiter threshold [dB] <0 */
double NR,/*noise gate ratio*/
double ER,/*expander ratio*/
double CR,/*compressor ratio*/
double LR,/*limiter ratio*/
double GF,/*gain factor [dB]*/
double hyst,
int *error_code,
struct DRCvar *var);
double *dynamics_run(
double *input_signal,
int input_length, /*if ==0 return the rest of samples in delayBuffer*/
int *output_length,
int *error_code,
struct DRCvar *var);
int dynamics_init(
double D,/*delay time [samples]*/
int SRR,/*sampling rate reduction*/
double AT,/*attack time*/
double RT,/*release time*/
double TAV,/*averaging coefficient*/
double NT,/*noise gate threshold [dB] <0 */
double ET,/*expander threshold [dB] <0 */
double CT,/*compressor threshold [dB] <0 */
double LT,/*limiter threshold [dB] <0 */
double NR,/*noise gate ratio*/
double ER,/*expander ratio*/
double CR,/*compressor ratio*/
double LR,/*limiter ratio*/
double GF,/*gain factor [dB]*/
double hyst,
int *error_code,
struct DRCvar *var);
The DRCvar structure is made to remember all parameters needed for dynamic range control, that are set in dynamics_init function, and for internal variables:
struct DRCvar{
double D,/*delay time [samples]*/
AT,/*attack time*/
RT,/*release time*/
TAV,/*averaging coefficient*/
NT,/*noise gate threshold [dB], <0 */
ET,/*expander threshold [dB] <0 */
CT,/*compressor threshold [dB] <0 */
LT,/*limiter threshold [dB] <0 */
NR,/*noise gate ratio, typically 0*/
ER,/*expander ratio, typically between 0 and 1*/
CR,/*compressor ratio, typically more than 1*/
LR,/*limiter ratio, typically infinity*/
NS,/*noise gate slope*/
ES,/*expander slope*/
CS,/*compressor slope*/
LS,/*limiter slope*/
GF,/*gain factor [dB]*/
Xpeak[2],/*peak measurement*/
Xrms[2],/*root mean square measurement*/
f[2],/*f(n)*/
g[2],/*control factor (smooth)*/
hyst;/*wide of hysteresis curve*/
minmax extr;
DelayBuffer delayBuf;
double *delayOut;/*output from delay*/
int delayOut_l;
int SRR;/*sampling rate reduction*/
int c_srr;/*count SRR*/
int at_or_rt;/*if ==0 signal is in attack, if ==1 signal is in release*/
};
Input parameters:
double D defines number of samples the input signal should be
delayed. D has to be non-real positive.
int SRR defines the sampling rate reduction. If SRR is equal to 2, every second
sample is taken. If SRR is equal to 1, no sampling rate reduction is done. SRR
has to be bigger than 0.
double AT is attack time coefficient.
double RT is release time coefficient. Summary of AT and RT has to
be
real value between 0 and 1. Both AT and RT should have positive real values.
double TAV is total average coefficient. Has to be a real number between
0 and 1.
double NT is noise gate threshold.
double ET is expander threshold.
double CT is compressor threshold.
double LT is limiter threshold. NT, ET, CT and LT should have real
negative values in [dB], and NT<ET<CT<LT.
double NR is noise gate ratio. It has to be smaller than or equal to 1/10.
double ER is expander ratio. The values have to be between 0 and 1.
double CR is compressor ratio. It has to be bigger than 1.
double LR is limiter ratio. It has to be bigger than or equal to 10. All NR,
ER, CR and LR should have positive real values.
double GF is gain factor. It has to be real number in [dB].
double hyst is half wide of the hysteresis curve. Values have to be
between 0 and 0.5.
int *error_code is return error code. If was equal to 0, no error has
fallen.
struct DRCvar *var is structure needed for saving parameters and internal
variables.
The return value is always 0.
double *dynamics_run(
double *input_signal,
int input_length, /*if ==0 return the rest of samples in delayBuffer*/
int *output_length,
int *error_code,
struct DRCvar *var);
Before using dynamics_run function, the dynamics_init function must be used to fill in parameters into DRCvar structure.
Input parameters:
double *input_signal is the input signal. This must be a simple array with real
values. The samples of the signal must be lined up so, that the first sample is
the oldest one.
int input_length is the length of the input array. If this value was equal
to 0, no samples from input are read, and the function returns the rest of the
delayed and changed samples in the buffer.
int *output_length is the length (number of samples) of the output signal.
int *error_code is the error code. If this value was zero, no error has fallen.
struct DRCvar *var saves parameters, internal variables and capacity of the
circle buffer.
On success, the delay function returns a non NULL pointer which points to a new allocated buffer, that contains the delayed output signal. On fail, the delay function returns a NULL pointer.
struct DRCvar dy;
long double audiodata[10];
long double *audioout = NULL;
long int o_l;
int err;
/*Initialize input values*/
dynamics_init(
10,/*D*/
4,/*sampling rate reduction*/
0.1,/*AT*/
0.1,/*RT*/
0.1,/*TAV*/
-70,/*NT[dB]*/
-45,/*ET[dB]*/
-25,/*CT[dB]*/
-10,/*LT[dB]*/
0.1,/*NR[0]*/
0.4,/*ER[0<R<1]*/
4,/*CR[>1]*/
10,/*LR[inf]*/
10,/*GF[dB]*/
0.01,/*hysteresis curve*/
&err,
&dy
);
audioout = dynamics_run( audiodata, 10, &o_l, &err, &dy);
/*return rest of the delayed and changed samples */
audioout = dynamics_run( audiodata, 0, &o_l, &err, &dy);