#include "dsp.h"

void wave2r(float *s, int ns, int m, float *r);
void poly2r (int m, float *a, float *r);
float alpha = r2lpc(int m, float *r, float *a, float *rc);
void a2cep (int m, int nc, float *a, float *cep);
float total_energy = audchan(float sr, int npts, float *Frame, int NBands, float *Bands);
float total_energy = zcep(sr, npts, data, ncoef, coefs);
float eqloud = loudness(f, a);
void autrfl(long n, int m, float *data, float *rfl, float *alph);
void ffa(float *b, int nfft);
void ffsy(float *b, int nfft);
double bark(double freq);
double barki(double z);
void intspb (int npt, float *datain, float *dataou, float bres, float fsc)


These are the basic signal processing functions used by various applications.

wave2r returns m autocorrelation values in array r given ns samples of a waveform in s as input.

poly2r returns m autocorrelation values in array r given m + 1 coefficients of the LPC inverse filter polynomial in a. This is the autocorrelation of the polynomial, not a signal autocorrelation. poly2r is useful in computing the Itakura distance.

r2lpc returns m reflection coefficients in array rc and m + 1 inverse filter coeficients in a given m autocorrelation coefficients in input array r. The error term (alpha) is returned as the function return. If the function return is <= 0.0, the filter is unstable and other return values are unreliable (i.e., computation may have stopped part way through the m stages).

a2cep returns nc lpc cepstral coeficients in array CEP given an m + 1 term LPC inverse filter polynomial in a.

audchan returns the total energy in the STFT of the input sequence Frame, an array of npts samples and NumOfBands channels of "perceptual filter" output estimated from the STFT. The NumOfBands perceptual filters are spaced evenly on a bark scale covering the Nyquist interval of the signal. Each filter is assymetrical with linear skirts (in Bark units) having a low frequency slope of 1.5 dB/Bark and high frequency slope of 3 dB/Bark. The magnitude of the FT is converted to equivalent loudness before filtering, and filter outputs are the natural logarithm of the weighted sum of the linear amplitude equivalent loudness values. The energy level in each channel is stored in Bands.

zcep accepts an npts length sequence of waveform data in data and returns ncoef terms of the cosine expansion of the auditory spectrum of the waveform data in coefs. The input waveform data should be windowed prior to calling zcep and tha actual length of data must be long enough to hold nfft+2 points of fourier transform data where nfft is the lowest power of two that is >= npts. The input parameter sr must contain the waveform sampling rate in samples per sec. The dunction returns total energy (if >= 0) or -1 on failure. Failure is always due to inability to allocate memory needed for tables during the analysis.

loudness returns the equivalent loudness (a perceptual quality) of a tone at frequency f (in Hz) and of amplitude a (in dB re 0.0002 dyn/cm^2. The return value is also in dB. This code implements the quadratic formula and table of coefficients published by Robinson & Dadson (1956). Linear interpolation is used to estimate loudness at frequencies between those in the table.

autrfl is Markle and Gray's autocorrelation LPC analysis.

ffa returns the complex (positive) fourier transform of its real input. This is a C implementation of the IEEE fortran program FFA.

ffsy returns the real inverse FFT of its complex positive fourier transform input. This is a C implementation of the IEEE fortran program FFS (renamed because of a utility function in the GNU c library).

bark returns the bark (critical bandwidth scale) value associated with its frequency input value.

barki returns a frequency corresponding to the bark interval given as input.

intspb convolves the NPT point spectrum in DATA with a window of constant Bark width. BRES is the window width in Bark units, FSC is the frequency scale such that Frequency in Hz = wavenumber * fsc. The returned spectrum is NPT points evenly spaced on a Bark scale and smoothed to BRES resolution.


Several of these functions trace their origin to the fortran code published by Markle and Gray (1976) with translation to C and some additions by H.T.Bunnell. Mariusz Fecko did some cleanup work on the zcep function.