blob: 1879dff7091c513dbd0b086bf5093d3be6223ba9 (
plain)
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
|
/*
tquisk_filter.c
Unit test for complex band pass filters in src/filter.c
cd codec2/build_linux
./misc/mksine - 1500 2 | unittest/tquisk_filter | aplay
By adjusting the frequency you can audibly test filter response.
*/
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "filter.h"
#include "filter_coef.h"
#define N 159 /* processing buffer size (odd number deliberate) */
#define CENTRE 1500.0
#define FS 8000.0
int main() {
short buf_short[N];
complex float buf[N];
struct quisk_cfFilter *bpf;
int i;
bpf = malloc(sizeof(struct quisk_cfFilter));
assert(bpf != NULL);
quisk_filt_cfInit(bpf, filtP200S400, sizeof(filtP200S400) / sizeof(float));
quisk_cfTune(bpf, CENTRE / FS);
while (fread(buf_short, sizeof(short), N, stdin) == N) {
for (i = 0; i < N; i++) buf[i] = buf_short[i];
quisk_ccfFilter(buf, buf, N, bpf);
/* we only output the real part in this test */
for (i = 0; i < N; i++) buf_short[i] = creal(buf[i]);
fwrite(buf_short, sizeof(short), N, stdout);
}
quisk_filt_destroy(bpf);
free(bpf);
return 0;
}
|