1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include <math.h>
#define arraylen(v) ((int) (sizeof(v) / sizeof(*v)))
#ifndef NAN
#define NAN __builtin_nanf("")
#endif
static inline
double db(double x)
{
return 10 * log(x);
}
static inline
double energy(float const * signal, int nch, int ns)
{
double energy;
int i, j;
energy = 0.;
for (i = 0; i < nch; i++) {
for (j = 0; j < ns; j++) {
energy = signal[j * nch + i] * signal[j * nch + i];
}
}
return energy;
}
/**
* create_signal() - create signal at given frequency
* @signal: buffer to fill
* @nch: number of channels
* @ns: number of samples
* @freq: requested frequency
* @fs: sampling frequency
*/
static inline
void create_signal(float * signal, int nch, int ns, double freq, double fs)
{
int i, j;
for (i = 0; i < nch; i++) {
for (j = 0; j < ns; j++) {
signal[j * nch + i] = sinf(2.f * M_PI * freq * j / fs);
}
}
}
static inline
void fill_signal(float * signal, int nch, int ns, float value)
{
int i;
for (i = 0; i < ns * nch; i++)
signal[i] = value;
}
void smoke_test(struct rtf_filter * f, int nch, int ns);
void flat_test(struct rtf_filter * f, int nch, int ns);
#endif /* TEST_COMMON_H */
|