forked from Tsukihime/OpenExpertSDR
-
Notifications
You must be signed in to change notification settings - Fork 4
/
graphiceq.c
156 lines (133 loc) · 4.56 KB
/
graphiceq.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* graphiceq.c
*
* PCM frequency domain equalizer
*
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2004, 2005, 2006 by Frank Brickle, AB2KT and Bob McGwier, N4HY
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The authors can be reached by email at
or
or by paper mail at
The DTTS Microwave Society
6 Kathleen Place
Bridgewater, NJ 08807
*/
#include <graphiceq.h>
static REAL EQ_Num[3];
static REAL EQ_Den[3];
static REAL EQ_Num_48000[] = { 0.99220706371f, -1.98392450292f, 0.99220706371f };
static REAL EQ_Den_48000[] = { 1.98392450292f, -0.98441412742f };
static REAL EQ_Num_96000[] = { 0.99608835009f, -1.99205381333f, 0.99608835009f };
static REAL EQ_Den_96000[] = { 1.99205381333f, -0.99217670018f };
static REAL EQ_Num_192000[] = { 0.99804034984f, -1.99604991764f, 0.99804034984f };
static REAL EQ_Den_192000[] = { 1.99604991764f, -0.99608069967f };
EQ
new_EQ(CXB d, REAL samplerate, int pbits)
{
ComplexFIR BP;
EQ a = (EQ)safealloc(1,
sizeof(eq),
"new eq state");
BP = newFIR_Bandpass_COMPLEX(-6000.0, 6000.0, samplerate, 257);
a->p = newFiltOvSv(BP->coef, 257, pbits);
a->in = newCXB(256, FiltOvSv_fetchpoint(a->p), "EQ input CXB");
a->out = newCXB(256, FiltOvSv_storepoint(a->p), "EQ output CXB");
a->data = d;
delFIR_Bandpass_COMPLEX(BP);
memset(a->num, 0, 9 * sizeof(COMPLEX));
memset(a->den, 0, 6 * sizeof(COMPLEX));
a->notchflag = FALSE;
if(samplerate == 48000.0f)
{
EQ_Num[0] = EQ_Num_48000[0];
EQ_Num[1] = EQ_Num_48000[1];
EQ_Num[2] = EQ_Num_48000[2];
EQ_Den[0] = EQ_Den_48000[0];
EQ_Den[1] = EQ_Den_48000[1];
}
if(samplerate == 96000.0f)
{
EQ_Num[0] = EQ_Num_96000[0];
EQ_Num[1] = EQ_Num_96000[1];
EQ_Num[2] = EQ_Num_96000[2];
EQ_Den[0] = EQ_Den_96000[0];
EQ_Den[1] = EQ_Den_96000[1];
}
if(samplerate == 192000.0f)
{
EQ_Num[0] = EQ_Num_192000[0];
EQ_Num[1] = EQ_Num_192000[1];
EQ_Num[2] = EQ_Num_192000[2];
EQ_Den[0] = EQ_Den_192000[0];
EQ_Den[1] = EQ_Den_192000[1];
}
return (a);
}
void
delEQ(EQ a)
{
if(a)
{
delCXB(a->in);
delCXB(a->out);
delFiltOvSv(a->p);
safefree((char *)a);
}
}
void
graphiceq(EQ a)
{
int sigsize = CXBhave(a->data);
int sigidx = 0;
do
{
memcpy(CXBbase(a->in), &CXBdata(a->data, sigidx),
256 * sizeof(COMPLEX));
filter_OvSv(a->p);
memcpy(&CXBdata(a->data, sigidx), CXBbase(a->out),
256 * sizeof(COMPLEX));
sigidx += 256;
}while(sigidx < sigsize);
if(a->notchflag)
{
int i;
for (i = 0; i < sigsize; i++)
{
int j;
for (j = 0; j < 3; j++)
{
int k = 3 * j;
int l = 2 * j;
COMPLEX numfilt;
a->num[k] = CXBdata(a->data, i);
numfilt.re =
a->num[k].re * EQ_Num[0] + a->num[k + 1].re * EQ_Num[1] +
a->num[k + 2].re * EQ_Num[2];
numfilt.im =
a->num[k].im * EQ_Num[0] + a->num[k + 1].im * EQ_Num[1] +
a->num[k + 2].im * EQ_Num[2];
a->num[k + 2] = a->num[k + 1];
a->num[k + 1] = a->num[k];
CXBdata(a->data, i) =
Cmplx(numfilt.re + a->den[l].re * EQ_Den[0] +
a->den[l + 1].re * EQ_Den[1],
numfilt.im + a->den[l].im * EQ_Den[0] +
a->den[l + 1].im * EQ_Den[1]);
a->den[l + 1] = a->den[l];
a->den[l] = CXBdata(a->data, i);
}
}
}
}