3483
|
1
|
|
2 static double desired_7kHz_lowpass[] = {1.0, 0.0};
|
|
3 static double weights_7kHz_lowpass[] = {0.1, 0.1};
|
|
4
|
|
5 double *calc_coefficients_7kHz_lowpass(int rate)
|
|
6 {
|
|
7 double *result = (double *)malloc(32*sizeof(double));
|
|
8 double bands[4];
|
|
9
|
|
10 bands[0] = 0.0; bands[1] = 6800.0/rate;
|
|
11 bands[2] = 8500.0/rate; bands[3] = 0.5;
|
|
12
|
|
13 remez(result, 32, 2, bands,
|
|
14 desired_7kHz_lowpass, weights_7kHz_lowpass, BANDPASS);
|
|
15
|
|
16 return result;
|
|
17 }
|
|
18
|
|
19 #if 0
|
|
20
|
|
21 int16_t firfilter(int16_t *buf, int pos, int len, int count, double *coefficients)
|
|
22 {
|
|
23 double result = 0.0;
|
|
24
|
|
25 // Back 32 samples, maybe wrapping in buffer.
|
|
26 pos = (pos+len-count)%len;
|
|
27 // And do the multiply-accumulate
|
|
28 while (count--) {
|
|
29 result += buf[pos++] * *coefficients++; pos %= len;
|
|
30 }
|
|
31 return result;
|
|
32 }
|
|
33
|
|
34 #endif
|
|
35
|
|
36 int16_t firfilter(int16_t *buf, int pos, int len, int count, double *coefficients)
|
|
37 {
|
|
38 double result = 0.0;
|
|
39 int count1, count2;
|
|
40 int16_t *ptr;
|
|
41
|
|
42 if (pos >= count) {
|
|
43 pos -= count;
|
|
44 count1 = count; count2 = 0;
|
|
45 }
|
|
46 else {
|
|
47 count2 = pos;
|
|
48 count1 = count - pos;
|
|
49 pos = len - count1;
|
|
50 }
|
|
51 //fprintf(stderr, "pos=%d, count1=%d, count2=%d\n", pos, count1, count2);
|
|
52
|
|
53 // high part of window
|
|
54 ptr = &buf[pos];
|
|
55 while (count1--) result += *ptr++ * *coefficients++;
|
|
56 // wrapped part of window
|
|
57 while (count2--) result += *buf++ * *coefficients++;
|
|
58 return result;
|
|
59 }
|