The "r8brain-free-src" library namespace. More...
Classes | |
| class | CDSPBlockConvolver |
| Single-block overlap-save convolution processing class. More... | |
| class | CDSPFIRFilter |
| Calculation and storage class for FIR filters. More... | |
| class | CDSPFIRFilterCache |
| FIR filter cache class. More... | |
| class | CDSPFracDelayFilterBank |
| Sinc function-based fractional delay filter bank class. More... | |
| class | CDSPFracDelayFilterBankCache |
| Fractional delay filter cache class. More... | |
| class | CDSPFracInterpolator |
| Fractional delay filter bank-based interpolator class. More... | |
| class | CDSPHBDownsampler |
| Half-band downsampler class. More... | |
| class | CDSPHBUpsampler |
| Half-band upsampling class. More... | |
| class | CDSPProcessor |
| The base virtual class for DSP processing algorithms. More... | |
| class | CDSPRealFFT |
| Real-valued FFT transform class. More... | |
| class | CDSPRealFFTKeeper |
| A "keeper" class for real-valued FFT transform objects. More... | |
| class | CDSPResampler |
| The master sample rate converter (resampler) class. More... | |
| class | CDSPResampler16 |
| The resampler class for 16-bit resampling. More... | |
| class | CDSPResampler16IR |
| The resampler class for 16-bit impulse response resampling. More... | |
| class | CDSPResampler24 |
| The resampler class for 24-bit resampling. More... | |
| class | CDSPSincFilterGen |
| Sinc function-based FIR filter generator class. More... | |
| class | CFixedBuffer |
| Templated memory buffer class for element buffers of fixed capacity. More... | |
| class | CPtrKeeper |
| Pointer-to-object "keeper" class with automatic deletion. More... | |
| class | CSineGen |
| Sine signal generator class. More... | |
| class | CStdClassAllocator |
| The default base class for objects created on heap. More... | |
| class | CStdMemAllocator |
| The default base class for objects that allocate blocks of memory. More... | |
| class | CSyncKeeper |
| A "keeper" class for CSyncObject-based synchronization. More... | |
| class | CSyncObject |
| Multi-threaded synchronization object class. More... | |
Enumerations | |
| enum | EDSPFilterPhaseResponse { fprLinearPhase = 0 , fprMinPhase } |
| Enumeration of filter's phase responses. More... | |
Functions | |
| template<typename T> | |
| T * | alignptr (T *const ptr, const uintptr_t align) |
Forces the provided ptr pointer to be aligned to align bytes. | |
| double | asinh (const double v) |
| Hyperbolic sine of a value. | |
| double | besselI0 (const double x) |
| 1st kind, 0th order modified Bessel function of a value. | |
| double | calcFIRFilterGroupDelay (const double *const flt, const int fltlen, const double th) |
| FIR filter's group delay calculation function. | |
| void | calcFIRFilterResponse (const double *flt, int fltlen, const double th, double &re0, double &im0, const int fltlat=0) |
| FIR filter's frequency response calculation. | |
| void | calcMinPhaseTransform (double *const Kernel, const int KernelLen, const int LenMult=2, const bool DoFinalMul=true, double *const DCGroupDelay=R8B_NULL) |
| Calculates the minimum-phase transform of the filter kernel, using a discrete Hilbert transform in cepstrum domain. | |
| void | calcSpline2p8Coeffs (double *const c, const double xm3, const double xm2, const double xm1, const double x0, const double x1, const double x2, const double x3, const double x4) |
| Calculates 2nd order spline coefficients, using 8 points. | |
| void | calcSpline3p4Coeffs (double *const c, const double *const y) |
| Calculates 3rd order spline coefficients, using 4 points. | |
| void | calcSpline3p6Coeffs (double *const c, const double *const y) |
| Calculates 3rd order spline coefficients, using 6 points. | |
| void | calcSpline3p8Coeffs (double *const c, const double xm3, const double xm2, const double xm1, const double x0, const double x1, const double x2, const double x3, const double x4) |
| Calculates 3rd order spline coefficients, using 8 points. | |
| double | clampr (const double Value, const double minv, const double maxv) |
| Clamps a value to be within the specified min-max range. | |
| double | convertResponseToLog (const double re, const double im) |
| Converts complex response into magnitude in log scale. | |
| void | findFIRFilterResponseLevelRtoL (const double *const flt, const int fltlen, const double maxg, double &th, const double thend) |
| Locates normalized frequency at which the specified maximum filter gain is reached. | |
| void | findFIRFilterResponseMaxLtoR (const double *const flt, const int fltlen, double &maxg, double &maxth, const double thend) |
| Locates normalized frequency at which the maximal filter gain is reached. | |
| void | findFIRFilterResponseMinLtoR (const double *const flt, const int fltlen, double &ming, double &minth, const double thend) |
| Locates normalized frequency at which the minimum filter gain is reached. | |
| bool | findGCD (double l, double s, double &GCD) |
| Interatively searches for a greatest common denominator (GCD) of 2 numbers. | |
| double | gauss (const double v) |
| Single-argument Gaussian function of a value. | |
| int | getBitOccupancy (const int v) |
| Calculate the exact number of bits a value needs for representation. | |
| bool | getWholeStepping (const double SSampleRate, const double DSampleRate, int &ResInStep, int &ResOutStep) |
| Evaluates source and destination sample rate ratio and returns the required input and output stepping. | |
| template<typename T> | |
| T | max (const T &v1, const T &v2) |
| Returns maximum of two values. | |
| template<typename T> | |
| T | min (const T &v1, const T &v2) |
| Returns minimum of two values. | |
| void | normalizeFIRFilter (double *const p, const int l, const double DCGain, const int pstep=1) |
| FIR filter's gain normalization. | |
| double | pow_a (const double v, const double p) |
| Power of an absolute value. | |
| double | sqr (const double x) |
| Returns square ot a value. | |
| void | updateScanStep (double &step, const double curg, double &prevg_log, const double prec, const double maxstep, const double minstep=1e-11) |
| An utility function that performs frequency response scanning step update based on the current magnitude response's slope. | |
Variables | |
| R8B_CONST double | R8B_2PI = 6.28318530717958648 |
Equals 2*pi. | |
| R8B_CONST double | R8B_3PI = 9.42477796076937972 |
Equals 3*pi. | |
| R8B_CONST double | R8B_PI = 3.14159265358979324 |
Equals pi. | |
| R8B_CONST double | R8B_PId2 = 1.57079632679489662 |
Equals 0.5*pi. | |
The "r8brain-free-src" library namespace.
The "r8brain-free-src" sample rate converter library namespace.
Enumeration of filter's phase responses.
| T * r8b::alignptr | ( | T *const | ptr, |
| const uintptr_t | align ) |
Forces the provided ptr pointer to be aligned to align bytes.
Works with power-of-2 alignments only.
| ptr | Pointer to align. |
| align | Alignment, in bytes, power-of-2. |
| T | Pointer's element type. |
| double r8b::asinh | ( | const double | v | ) |
Hyperbolic sine of a value.
| v | Input value. |
| double r8b::besselI0 | ( | const double | x | ) |
1st kind, 0th order modified Bessel function of a value.
| x | Input value. |
| double r8b::calcFIRFilterGroupDelay | ( | const double *const | flt, |
| const int | fltlen, | ||
| const double | th ) |
FIR filter's group delay calculation function.
Function calculates group delay of the specified FIR filter at the specified circular frequency. The group delay is calculated by evaluating the filter's response at close side-band frequencies of "th".
| flt | FIR filter's coefficients. |
| fltlen | Number of coefficients (taps) in the filter. |
| th | Circular frequency [0; pi]. |
| void r8b::calcFIRFilterResponse | ( | const double * | flt, |
| int | fltlen, | ||
| const double | th, | ||
| double & | re0, | ||
| double & | im0, | ||
| const int | fltlat = 0 ) |
FIR filter's frequency response calculation.
Function calculates frequency response of the specified FIR filter at the specified circular frequency. Phase can be calculated as atan2( im, re ).
| flt | FIR filter's coefficients. | |
| fltlen | Number of coefficients (taps) in the filter. | |
| th | Circular frequency [0; pi]. | |
| [out] | re0 | Resulting real part of the complex frequency response. |
| [out] | im0 | Resulting imaginary part of the complex frequency response. |
| fltlat | Filter's latency, in samples. |
| void r8b::calcMinPhaseTransform | ( | double *const | Kernel, |
| const int | KernelLen, | ||
| const int | LenMult = 2, | ||
| const bool | DoFinalMul = true, | ||
| double *const | DCGroupDelay = R8B_NULL ) |
Calculates the minimum-phase transform of the filter kernel, using a discrete Hilbert transform in cepstrum domain.
For more details, see part III.B of http://www.hpl.hp.com/personal/Niranjan_Damera-Venkata/files/ComplexMinPhase.pdf
| [in,out] | Kernel | Filter kernel buffer. |
| KernelLen | Filter kernel's length, in samples. | |
| LenMult | Kernel length multiplier. Used as a coefficient of oversampling in the frequency domain. Such oversampling is needed to improve the precision of the minimum-phase transform. If the filter's attenuation is high, this multiplier should be increased or otherwise the required attenuation will not be reached due to "smoothing" effect of this transform. | |
| DoFinalMul | true if the final multiplication after transform should be performed. Such multiplication returns the gain of the signal to its original value. This parameter can be set to false if normalization of the resulting filter kernel is planned to be used. | |
| [out] | DCGroupDelay | If not nullptr, this variable receives group delay at DC offset, in samples (can be a non-integer value). |
| void r8b::calcSpline2p8Coeffs | ( | double *const | c, |
| const double | xm3, | ||
| const double | xm2, | ||
| const double | xm1, | ||
| const double | x0, | ||
| const double | x1, | ||
| const double | x2, | ||
| const double | x3, | ||
| const double | x4 ) |
Calculates 2nd order spline coefficients, using 8 points.
Function calculates coefficients used to calculate 2nd order spline (polynomial) on the equidistant lattice, using 8 points. This function is based on the calcSpline3p8Coeffs() function, but without the 3rd order coefficient.
| [out] | c | Output coefficients buffer, length = 3. |
| xm3 | Point at x-3 position. | |
| xm2 | Point at x-2 position. | |
| xm1 | Point at x-1 position. | |
| x0 | Point at x position. | |
| x1 | Point at x+1 position. | |
| x2 | Point at x+2 position. | |
| x3 | Point at x+3 position. | |
| x4 | Point at x+4 position. |
| void r8b::calcSpline3p4Coeffs | ( | double *const | c, |
| const double *const | y ) |
Calculates 3rd order spline coefficients, using 4 points.
Function calculates coefficients used to calculate 3rd order segment interpolation polynomial on the equidistant lattice, using 4 points.
| [out] | c | Output coefficients buffer, length = 4. |
| [in] | y | Equidistant point values. Value at offset 1 corresponds to x=0 point. |
| void r8b::calcSpline3p6Coeffs | ( | double *const | c, |
| const double *const | y ) |
Calculates 3rd order spline coefficients, using 6 points.
Function calculates coefficients used to calculate 3rd order segment interpolation polynomial on the equidistant lattice, using 6 points.
| [out] | c | Output coefficients buffer, length = 4. |
| [in] | y | Equidistant point values. Value at offset 2 corresponds to x=0 point. |
| void r8b::calcSpline3p8Coeffs | ( | double *const | c, |
| const double | xm3, | ||
| const double | xm2, | ||
| const double | xm1, | ||
| const double | x0, | ||
| const double | x1, | ||
| const double | x2, | ||
| const double | x3, | ||
| const double | x4 ) |
Calculates 3rd order spline coefficients, using 8 points.
Function calculates coefficients used to calculate 3rd order spline (polynomial) on the equidistant lattice, using 8 points.
| [out] | c | Output coefficients buffer, length = 4. |
| xm3 | Point at x-3 position. | |
| xm2 | Point at x-2 position. | |
| xm1 | Point at x-1 position. | |
| x0 | Point at x position. | |
| x1 | Point at x+1 position. | |
| x2 | Point at x+2 position. | |
| x3 | Point at x+3 position. | |
| x4 | Point at x+4 position. |
| double r8b::clampr | ( | const double | Value, |
| const double | minv, | ||
| const double | maxv ) |
Clamps a value to be within the specified min-max range.
Function "clamps" (clips) the specified value so that it is not lesser than "minv", and not greater than "maxv".
| Value | Value to clamp. |
| minv | Minimal allowed value. |
| maxv | Maximal allowed value. |
| double r8b::convertResponseToLog | ( | const double | re, |
| const double | im ) |
Converts complex response into magnitude in log scale.
| re | Real part of the frequency response. |
| im | Imaginary part of the frequency response. |
| void r8b::findFIRFilterResponseLevelRtoL | ( | const double *const | flt, |
| const int | fltlen, | ||
| const double | maxg, | ||
| double & | th, | ||
| const double | thend ) |
Locates normalized frequency at which the specified maximum filter gain is reached.
The scanning is performed from higher (right) to lower (left) frequencies, scanning stops when the required gain value was crossed. Function uses an extremely efficient binary search and thus expects that the magnitude response has the "main lobe" form produced by windowing, with a minimal pass-band ripple.
| flt | Filter response. | |
| fltlen | Filter response's length in samples (taps). | |
| maxg | Maximal gain (squared). | |
| [out] | th | The current normalized frequency. On function's return will point to the normalized frequency where "maxg" is reached. |
| thend | The leftmost frequency to scan, inclusive. |
| void r8b::findFIRFilterResponseMaxLtoR | ( | const double *const | flt, |
| const int | fltlen, | ||
| double & | maxg, | ||
| double & | maxth, | ||
| const double | thend ) |
Locates normalized frequency at which the maximal filter gain is reached.
The scanning is performed from lower (left) to higher (right) frequencies, the whole range is scanned.
Note: this function may "stall" in very rare cases if the magnitude response happens to be "saw-tooth" like, requiring a very small stepping to be used. If this happens, it may take dozens of seconds to complete.
| flt | Filter response. | |
| fltlen | Filter response's length in samples (taps). | |
| [out] | maxg | The current maximal gain (squared). On function's return will contain the maximal gain value (squared). |
| [out] | maxth | The normalized frequency where the maximal gain is currently at. On function's return will point to the normalized frequency where the maximum was reached. |
| thend | The ending frequency, inclusive. |
| void r8b::findFIRFilterResponseMinLtoR | ( | const double *const | flt, |
| const int | fltlen, | ||
| double & | ming, | ||
| double & | minth, | ||
| const double | thend ) |
Locates normalized frequency at which the minimum filter gain is reached.
The scanning is performed from lower (left) to higher (right) frequencies, the whole range is scanned.
Function expects that the magnitude response is always reducing from lower to high frequencies, starting at "minth".
| flt | Filter response. | |
| fltlen | Filter response's length in samples (taps). | |
| [out] | ming | The current minimal gain (squared). On function's return will contain the minimal gain value found (squared). |
| [out] | minth | The normalized frequency where the minimal gain is currently at. On function's return will point to the normalized frequency where the new minimum was found. |
| thend | The ending frequency, inclusive. |
| bool r8b::findGCD | ( | double | l, |
| double | s, | ||
| double & | GCD ) |
Interatively searches for a greatest common denominator (GCD) of 2 numbers.
| l | Number 1. | |
| s | Number 2. | |
| [out] | GCD | Resulting GCD. |
true if the greatest common denominator of 2 numbers was found. | double r8b::gauss | ( | const double | v | ) |
Single-argument Gaussian function of a value.
| v | Input value. |
| int r8b::getBitOccupancy | ( | const int | v | ) |
Calculate the exact number of bits a value needs for representation.
| v | Input value. |
| bool r8b::getWholeStepping | ( | const double | SSampleRate, |
| const double | DSampleRate, | ||
| int & | ResInStep, | ||
| int & | ResOutStep ) |
Evaluates source and destination sample rate ratio and returns the required input and output stepping.
Function returns false if whole stepping cannot be used to perform interpolation using these sample rates.
| SSampleRate | Source sample rate. | |
| DSampleRate | Destination sample rate. | |
| [out] | ResInStep | Resulting input step. |
| [out] | ResOutStep | Resulting output step. |
true if stepping was acquired. | T r8b::max | ( | const T & | v1, |
| const T & | v2 ) |
Returns maximum of two values.
| v1 | Value 1. |
| v2 | Value 2. |
| T | Values' type. |
| T r8b::min | ( | const T & | v1, |
| const T & | v2 ) |
Returns minimum of two values.
| v1 | Value 1. |
| v2 | Value 2. |
| T | Values' type. |
| void r8b::normalizeFIRFilter | ( | double *const | p, |
| const int | l, | ||
| const double | DCGain, | ||
| const int | pstep = 1 ) |
FIR filter's gain normalization.
Function normalizes FIR filter so that its frequency response at DC is equal to DCGain.
| [in,out] | p | Filter coefficients. |
| l | Filter length. | |
| DCGain | Filter's gain at DC (linear, non-decibel value). | |
| pstep | "p" array step. |
| double r8b::pow_a | ( | const double | v, |
| const double | p ) |
Power of an absolute value.
| v | Input value. |
| p | Power factor. |
| double r8b::sqr | ( | const double | x | ) |
Returns square ot a value.
| x | Value to square. |
| void r8b::updateScanStep | ( | double & | step, |
| const double | curg, | ||
| double & | prevg_log, | ||
| const double | prec, | ||
| const double | maxstep, | ||
| const double | minstep = 1e-11 ) |
An utility function that performs frequency response scanning step update based on the current magnitude response's slope.
| [in,out] | step | The current scanning step. Will be updated on function's return. Must be a positive value. |
| curg | Squared magnitude response at the current frequency point. | |
| [in,out] | prevg_log | Previous magnitude response, log scale. Will be updated on function's return. |
| prec | Precision multiplier, affects the size of the step. | |
| maxstep | The maximal allowed step. | |
| minstep | The minimal allowed step. |