Skip to content

Latest commit

 

History

History
199 lines (174 loc) · 5.78 KB

filter_templates.h

File metadata and controls

199 lines (174 loc) · 5.78 KB
 
Jul 13, 2002
Jul 13, 2002
1
/*
Jun 18, 2002
Jun 18, 2002
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
* Extended Audio Converter for SDL (Simple DirectMedia Layer)
* Copyright (C) 2002 Frank Ranostaj
* Institute of Applied Physik
* Johann Wolfgang Goethe-Universität
* Frankfurt am Main, Germany
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Frank Ranostaj
* ranostaj@stud.uni-frankfurt.de
*
* (This code blatantly abducted for SDL_sound. Thanks, Frank! --ryan.)
*/
Jul 13, 2002
Jul 13, 2002
27
28
29
30
31
32
33
#ifndef Suffix
#error include filter_template.h with defined Suffix macro!
#else
#define CH(x) (Suffix((x)*))
/*-------------------------------------------------------------------------*/
Jun 21, 2002
Jun 21, 2002
34
/* this filter (Kaiser-window beta=6.8) gives a decent -80dB attentuation */
Jul 13, 2002
Jul 13, 2002
35
36
37
38
/*-------------------------------------------------------------------------*/
#define sum_d(v,dx) ((int) v[CH(dx)] + v[CH(1-dx)])
static Sint16* Suffix(doubleRate)( Sint16 *outp, Sint16 *inp, int length,
VarFilter* filt, RateAux* aux )
May 20, 2002
May 20, 2002
39
{
Jun 21, 2002
Jun 21, 2002
40
41
int out;
Sint16 *to;
Jun 12, 2002
Jun 12, 2002
42
Jun 21, 2002
Jun 21, 2002
43
to = inp - length;
Jun 12, 2002
Jun 12, 2002
44
Jun 21, 2002
Jun 21, 2002
45
while( inp > to )
Jun 12, 2002
Jun 12, 2002
46
{
Jun 21, 2002
Jun 21, 2002
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
out = 0;
out-= 9 * sum_d( inp, 16);
out+= 23 * sum_d( inp, 15);
out-= 46 * sum_d( inp, 14);
out+= 83 * sum_d( inp, 13);
out-= 138 * sum_d( inp, 12);
out+= 217 * sum_d( inp, 11);
out-= 326 * sum_d( inp, 10);
out+= 474 * sum_d( inp, 9);
out-= 671 * sum_d( inp, 8);
out+= 936 * sum_d( inp, 7);
out-= 1295 * sum_d( inp, 6);
out+= 1800 * sum_d( inp, 5);
out-= 2560 * sum_d( inp, 4);
out+= 3863 * sum_d( inp, 3);
out-= 6764 * sum_d( inp, 2);
out+= 20798 * sum_d( inp, 1);
Jun 12, 2002
Jun 12, 2002
64
Jun 18, 2002
Jun 18, 2002
65
66
outp[CH(1)] = ( 32770 * inp[CH(1)] + out) >> 16;
outp[CH(0)] = ( 32770 * inp[CH(0)] + out) >> 16;
Jun 21, 2002
Jun 21, 2002
67
68
inp -= CH(1);
Jun 18, 2002
Jun 18, 2002
69
outp -= CH(2);
Jun 12, 2002
Jun 12, 2002
70
}
Jul 13, 2002
Jul 13, 2002
71
Jun 18, 2002
Jun 18, 2002
72
return outp;
May 20, 2002
May 20, 2002
73
}
Jun 29, 2002
Jun 29, 2002
74
#undef sum_d
May 20, 2002
May 20, 2002
75
Jun 18, 2002
Jun 18, 2002
76
/*-------------------------------------------------------------------------*/
Jun 21, 2002
Jun 21, 2002
77
#define sum_h(v,dx) ((int) v[CH(dx)] + v[CH(-dx)])
Jun 18, 2002
Jun 18, 2002
78
static Sint16* Suffix(halfRate)( Sint16 *outp, Sint16 *inp, int length,
Jul 13, 2002
Jul 13, 2002
79
VarFilter* filt, RateAux* aux )
May 20, 2002
May 20, 2002
80
{
Jun 21, 2002
Jun 21, 2002
81
int out;
Jun 18, 2002
Jun 18, 2002
82
Sint16* to;
Jun 12, 2002
Jun 12, 2002
83
Jun 18, 2002
Jun 18, 2002
84
to = inp + length;
Jul 13, 2002
Jul 13, 2002
85
inp += aux->carry;
Jun 12, 2002
Jun 12, 2002
86
Jun 21, 2002
Jun 21, 2002
87
while( inp < to )
Jun 12, 2002
Jun 12, 2002
88
{
Jun 21, 2002
Jun 21, 2002
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
out = 0;
out-= 9 * sum_h( inp, 31);
out+= 23 * sum_h( inp, 29);
out-= 46 * sum_h( inp, 27);
out+= 83 * sum_h( inp, 25);
out-= 138 * sum_h( inp, 23);
out+= 217 * sum_h( inp, 21);
out-= 326 * sum_h( inp, 19);
out+= 474 * sum_h( inp, 17);
out-= 671 * sum_h( inp, 15);
out+= 936 * sum_h( inp, 13);
out-= 1295 * sum_h( inp, 11);
out+= 1800 * sum_h( inp, 9);
out-= 2560 * sum_h( inp, 7);
out+= 3863 * sum_h( inp, 5);
Jun 25, 2002
Jun 25, 2002
104
out-= 6764 * sum_h( inp, 3);
Jun 21, 2002
Jun 21, 2002
105
106
107
out+= 20798 * sum_h( inp, 1);
out+= 32770 * (int)inp[0];
Jun 18, 2002
Jun 18, 2002
108
outp[0] = out >> 16;
Jun 12, 2002
Jun 12, 2002
109
Jul 13, 2002
Jul 13, 2002
110
inp += CH(2);
Jun 18, 2002
Jun 18, 2002
111
outp += CH(1);
Jun 12, 2002
Jun 12, 2002
112
}
Jul 13, 2002
Jul 13, 2002
113
114
aux->carry = inp < to + CH(1) ? 0 : CH(1);
Jun 18, 2002
Jun 18, 2002
115
return outp;
May 20, 2002
May 20, 2002
116
}
Jun 29, 2002
Jun 29, 2002
117
#undef sum_h
May 20, 2002
May 20, 2002
118
Jun 18, 2002
Jun 18, 2002
119
120
/*-------------------------------------------------------------------------*/
static Sint16* Suffix(increaseRate)( Sint16 *outp, Sint16 *inp, int length,
Jul 13, 2002
Jul 13, 2002
121
VarFilter* filter, RateAux* aux )
May 20, 2002
May 20, 2002
122
{
Jun 21, 2002
Jun 21, 2002
123
const static int fsize = CH(2*_fsize);
Jun 25, 2002
Jun 25, 2002
124
Sint16 *f;
Jun 18, 2002
Jun 18, 2002
125
126
127
int out;
int i, pos;
Sint16* to;
Jun 12, 2002
Jun 12, 2002
128
Jun 21, 2002
Jun 21, 2002
129
130
inp -= fsize;
to = inp - length;
Jul 13, 2002
Jul 13, 2002
131
pos = aux->pos;
May 20, 2002
May 20, 2002
132
Jun 18, 2002
Jun 18, 2002
133
while( inp > to )
Jun 12, 2002
Jun 12, 2002
134
{
Jun 18, 2002
Jun 18, 2002
135
out = 0;
Jun 25, 2002
Jun 25, 2002
136
f = filter->c[pos];
Jul 3, 2002
Jul 3, 2002
137
for( i = _fsize + 1; --i; inp+=CH(4), f+=4 )
Jun 25, 2002
Jun 25, 2002
138
139
{
out+= f[0] * (int)inp[CH(0)];
Jul 3, 2002
Jul 3, 2002
140
141
142
out+= f[1] * (int)inp[CH(1)];
out+= f[2] * (int)inp[CH(2)];
out+= f[3] * (int)inp[CH(3)];
Jun 25, 2002
Jun 25, 2002
143
}
Jun 18, 2002
Jun 18, 2002
144
outp[0] = out >> 16;
May 20, 2002
May 20, 2002
145
Jul 3, 2002
Jul 3, 2002
146
147
148
pos = ( pos + filter->ratio.denominator - 1 )
% filter->ratio.denominator;
inp -= CH( 4 * _fsize );
Jun 25, 2002
Jun 25, 2002
149
inp -= CH( filter->incr[pos] );
Jun 18, 2002
Jun 18, 2002
150
outp -= CH(1);
Jun 12, 2002
Jun 12, 2002
151
}
Jun 25, 2002
Jun 25, 2002
152
Jul 13, 2002
Jul 13, 2002
153
aux->pos = pos;
Jun 18, 2002
Jun 18, 2002
154
return outp;
May 20, 2002
May 20, 2002
155
156
}
Jun 18, 2002
Jun 18, 2002
157
158
/*-------------------------------------------------------------------------*/
static Sint16* Suffix(decreaseRate)( Sint16 *outp, Sint16 *inp, int length,
Jul 13, 2002
Jul 13, 2002
159
VarFilter* filter, RateAux* aux )
May 20, 2002
May 20, 2002
160
{
Jun 21, 2002
Jun 21, 2002
161
const static int fsize = CH(2*_fsize);
Jun 25, 2002
Jun 25, 2002
162
Sint16 *f;
Jun 18, 2002
Jun 18, 2002
163
164
165
int out;
int i, pos;
Sint16 *to;
Jun 12, 2002
Jun 12, 2002
166
Jun 18, 2002
Jun 18, 2002
167
168
inp -= fsize;
to = inp + length;
Jul 13, 2002
Jul 13, 2002
169
170
pos = aux->pos;
inp += aux->carry;
Jun 12, 2002
Jun 12, 2002
171
Jun 18, 2002
Jun 18, 2002
172
while( inp < to )
Jun 12, 2002
Jun 12, 2002
173
{
Jun 18, 2002
Jun 18, 2002
174
out = 0;
Jun 25, 2002
Jun 25, 2002
175
176
177
178
179
180
181
182
f = filter->c[pos];
for( i = _fsize + 1; --i; inp+=CH(4), f+=4 )
{
out+= f[0] * (int)inp[CH(0)];
out+= f[1] * (int)inp[CH(1)];
out+= f[2] * (int)inp[CH(2)];
out+= f[3] * (int)inp[CH(3)];
}
Jun 18, 2002
Jun 18, 2002
183
184
outp[0] = out >> 16;
Jun 25, 2002
Jun 25, 2002
185
186
inp -= CH( 4 * _fsize );
inp += CH( filter->incr[pos] );
Jun 18, 2002
Jun 18, 2002
187
outp += CH(1);
Jul 3, 2002
Jul 3, 2002
188
pos = ( pos + 1 ) % filter->ratio.denominator;
Jun 12, 2002
Jun 12, 2002
189
}
Jun 25, 2002
Jun 25, 2002
190
Jul 13, 2002
Jul 13, 2002
191
192
aux->pos = pos;
aux->carry = inp < to + CH(1) ? 0 : CH(1);
Jun 18, 2002
Jun 18, 2002
193
return outp;
May 20, 2002
May 20, 2002
194
}
Jun 18, 2002
Jun 18, 2002
195
196
/*-------------------------------------------------------------------------*/
May 20, 2002
May 20, 2002
197
198
#undef CH
#endif /* Suffix */
Jul 13, 2002
Jul 13, 2002
199