XDSP
Audio signal processing and synthesis library.
Loading...
Searching...
No Matches
xdsp::decibel Namespace Reference

Decibel conversion functions. More...

Functions

double to_linear (double db)
 Converts decibel (relative to 1.0) value to linear gain factor.
 
float to_linear (float db)
 Converts decibel (relative to 1.0) value to linear gain factor.
 
double to_linear_off (double db, double threshold)
 Converts decibel (relative to 1.0) value to linear gain factor.
If value is below given threshold, this function returns 0.
 
float to_linear_off (float db, double threshold)
 Converts decibel (relative to 1.0) value to linear gain factor.
If value is below given threshold, this function returns 0.
 
double to_db (double linear)
 Converts linear gain factor to decibel (relative to 1.0) value.
 
float to_db (float linear)
 
double apply (double lin, double gain)
 Apply a decibel gain to a linear signal.
 
float apply (float lin, float gain)
 Apply a decibel gain to a linear signal.
 
double apply_off (double lin, double gain, double threshold)
 Apply a decibel gain to a linear signal, muting if below threshold.
 
float apply (float lin, float gain, float threshold)
 

Variables

constexpr double DB_REF = 1.0
 Reference value for all decibel conversions.
 

Detailed Description

Decibel conversion functions.

Function Documentation

◆ apply() [1/3]

double xdsp::decibel::apply ( double lin,
double gain )
inline

Apply a decibel gain to a linear signal.

Parameters
linLinear signal
gain[dB] Gain
Returns
Amplified or attenuated signal

Definition at line 76 of file decibel.h.

76{ return lin * to_linear(gain); }
double to_linear(double db)
Converts decibel (relative to 1.0) value to linear gain factor.
Definition decibel.h:22

◆ apply() [2/3]

float xdsp::decibel::apply ( float lin,
float gain )
inline

Apply a decibel gain to a linear signal.

Parameters
linLinear signal
gain[dB] Gain
Returns
Amplified or attenuated signal

Definition at line 81 of file decibel.h.

81{ return lin * to_linear(gain); }

◆ apply() [3/3]

float xdsp::decibel::apply ( float lin,
float gain,
float threshold )
inline

Definition at line 99 of file decibel.h.

99 {
100 return lin * to_linear_off(gain, threshold);
101}
double to_linear_off(double db, double threshold)
Converts decibel (relative to 1.0) value to linear gain factor. If value is below given threshold,...
Definition decibel.h:37

◆ apply_off()

double xdsp::decibel::apply_off ( double lin,
double gain,
double threshold )
inline

Apply a decibel gain to a linear signal, muting if below threshold.

Parameters
lin
gain
threshold[dB] Off-threshold. Gains below this value will mute the input.
Returns
Amplified or attenuated signal. Zero if gain is below threshold.

Definition at line 92 of file decibel.h.

92 {
93 return lin * to_linear_off(gain, threshold);
94}

◆ to_db() [1/2]

double xdsp::decibel::to_db ( double linear)
inline

Converts linear gain factor to decibel (relative to 1.0) value.

Parameters
[1]Linear gain factor
Returns
[dB] Decibel value

Definition at line 62 of file decibel.h.

62{ return 20.0 * log10(linear); }

◆ to_db() [2/2]

float xdsp::decibel::to_db ( float linear)
inline

Definition at line 67 of file decibel.h.

67{ return 20.0f * log10f(linear); }

◆ to_linear() [1/2]

double xdsp::decibel::to_linear ( double db)
inline

Converts decibel (relative to 1.0) value to linear gain factor.

Parameters
db[dB]
Returns
Linear gain factor

Definition at line 22 of file decibel.h.

22{ return pow(10.0, db / 20.0); }

◆ to_linear() [2/2]

float xdsp::decibel::to_linear ( float db)
inline

Converts decibel (relative to 1.0) value to linear gain factor.

Parameters
db[dB]
Returns
Linear gain factor

Definition at line 27 of file decibel.h.

27{ return powf(10.0f, db / 20.0f); }

◆ to_linear_off() [1/2]

double xdsp::decibel::to_linear_off ( double db,
double threshold )
inline

Converts decibel (relative to 1.0) value to linear gain factor.
If value is below given threshold, this function returns 0.

Parameters
db[dB] value to convert
threshold[dB] off-threshold
Returns
Linear gain factor

Definition at line 37 of file decibel.h.

37 {
38 if (db <= threshold) {
39 return 0.0;
40 } else {
41 return to_linear(db);
42 }
43}

◆ to_linear_off() [2/2]

float xdsp::decibel::to_linear_off ( float db,
double threshold )
inline

Converts decibel (relative to 1.0) value to linear gain factor.
If value is below given threshold, this function returns 0.

Parameters
db[dB] value to convert
threshold[dB] off-threshold
Returns
Linear gain factor

Definition at line 48 of file decibel.h.

48 {
49 if (db <= threshold) {
50 return 0.0f;
51 } else {
52 return to_linear(db);
53 }
54}

Variable Documentation

◆ DB_REF

double xdsp::decibel::DB_REF = 1.0
constexpr

Reference value for all decibel conversions.

Definition at line 14 of file decibel.h.