1
/* Copyright (C) 2005 Analog Devices */
4
@brief Various analysis/synthesis filters (Blackfin version)
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in the
16
documentation and/or other materials provided with the distribution.
18
- Neither the name of the Xiph.org Foundation nor the names of its
19
contributors may be used to endorse or promote products derived from
20
this software without specific prior written permission.
22
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
26
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
#define OVERRIDE_NORMALIZE16
36
int normalize16(const spx_sig_t *x, spx_word16_t *y, spx_sig_t max_scale, int len)
46
"LOOP norm_max%= LC0 = %2;\n\t"
47
"LOOP_BEGIN norm_max%=;\n\t"
48
"R2 = ABS R1 || R1 = [I0++];\n\t"
49
"%0 = MAX(%0, R2);\n\t"
50
"LOOP_END norm_max%=;\n\t"
57
while (max_val>max_scale)
69
"LOOP norm_shift%= LC0 = %3;\n\t"
70
"LOOP_BEGIN norm_shift%=;\n\t"
71
"R1 = ASHIFT R0 by %2.L || R0 = [I0++];\n\t"
73
"LOOP_END norm_shift%=;\n\t"
74
"R1 = ASHIFT R0 by %2.L;\n\t"
76
: : "a" (x), "a" (y), "d" (-sig_shift), "a" (len-1)
77
: "I0", "L0", "P1", "R0", "R1", "memory"
84
#define OVERRIDE_FILTER_MEM16
85
void filter_mem16(const spx_word16_t *_x, const spx_coef_t *num, const spx_coef_t *den, spx_word16_t *_y, int N, int ord, spx_mem_t *mem, char *stack)
87
VARDECL(spx_word32_t *xy2);
88
VARDECL(spx_word32_t *numden_a);
93
ALLOC(xy2, (N+1), spx_word32_t);
94
ALLOC(numden_a, (2*ord+2), spx_word32_t);
96
numden = (spx_word16_t*) numden_a;
100
numden[2*i] = num[i];
101
numden[2*i+1] = den[i];
106
"R0 = %5;\n\t" /*ord */
110
"B0 = P0;\n\t" /* numden */
113
"P2 = %0;\n\t" /* Fused xy */
117
"P4 = %6;\n\t" /* mem */
118
"P0 = %1;\n\t" /* _x */
119
"P1 = %2;\n\t" /* _y */
123
"R1 <<= 3;\n\t" /* shift mem */
124
"R1.L = R1 (RND);\n\t"
125
"R2 = W[P0++];\n\t" /* load x[0] */
126
"R1.L = R1.L + R2.L;\n\t"
127
"W[P1++] = R1;\n\t" /* store y[0] */
128
"R2 = PACK(R1.L, R2.L);\n\t" /* pack x16 and y16 */
131
/* Samples 1 to ord-1 (using memory) */
135
"LOOP filter_start%= LC0;\n\t"
136
"LOOP_BEGIN filter_start%=;\n\t"
146
"R4 = [I0++] || R5 = [I2--];\n\t"
147
"LOOP filter_start_inner%= LC1;\n\t"
148
"LOOP_BEGIN filter_start_inner%=;\n\t"
149
"A1 -= R4.H*R5.H, A0 += R4.L*R5.L (IS) || R4 = [I0++] || R5 = [I2--];\n\t"
150
"LOOP_END filter_start_inner%=;\n\t"
153
"R4 <<= 3;\n\t" /* shift mem */
154
"R4.L = R4 (RND);\n\t"
155
"R2 = W[P0++];\n\t" /* load x */
156
"R4.L = R4.L + R2.L;\n\t"
157
"W[P1++] = R4;\n\t" /* store y */
160
"R2 = PACK(R4.L, R2.L);\n\t" /* pack x16 and y16 */
163
"LOOP_END filter_start%=;\n\t"
165
/* Samples ord to N*/
168
"I0 = B0;\n\t" /* numden */
172
"R0 = %5;\n\t" /* org */
173
"R2 = %4;\n\t" /* N */
175
"R4 = [I0++];\n\t" /* numden */
183
"R5 = [I2--];\n\t" /* load xy */
184
"LOOP filter_mid%= LC0;\n\t"
185
"LOOP_BEGIN filter_mid%=;\n\t"
186
"LOOP filter_mid_inner%= LC1=P3;\n\t"
187
"LOOP_BEGIN filter_mid_inner%=;\n\t"
188
"A1 -= R4.H*R5.H, A0 += R4.L*R5.L (IS) || R4 = [I0++] || R5 = [I2--];\n\t"
189
"LOOP_END filter_mid_inner%=;\n\t"
190
"R0 = (A0 += A1) || I2 += M0;\n\t"
191
"R0 = R0 << 3 || R5 = W[P0++];\n\t" /* load x */
192
"R0.L = R0 (RND);\n\t"
193
"R0.L = R0.L + R5.L;\n\t"
194
"R5 = PACK(R0.L, R5.L) || W[P1++] = R0;\n\t" /* shift y | store y */
195
"A1 = A0 = 0 || [I2--] = R5\n\t"
196
"LOOP_END filter_mid%=;\n\t"
205
"LOOP mem_update%= LC0;\n\t"
206
"LOOP_BEGIN mem_update%=;\n\t"
212
"R5 = [I2--] || R4 = [I0++];\n\t"
213
"LOOP mem_accum%= LC1;\n\t"
214
"LOOP_BEGIN mem_accum%=;\n\t"
215
"A1 -= R4.H*R5.H, A0 += R4.L*R5.L (IS) || R4 = [I0++] || R5 = [I2--];\n\t"
216
"LOOP_END mem_accum%=;\n\t"
217
"R0 = (A0 += A1);\n\t"
218
"A1 = A0 = 0 || [P4++] = R0;\n\t"
219
"LOOP_END mem_update%=;\n\t"
221
: : "m" (xy), "m" (_x), "m" (_y), "m" (numden), "m" (N), "m" (ord), "m" (mem)
222
: "A0", "A1", "R0", "R1", "R2", "R3", "R4", "R5", "P0", "P1", "P2", "P3", "P4", "B0", "I0", "I2", "L0", "L2", "M0", "memory"
229
#define OVERRIDE_IIR_MEM16
230
void iir_mem16(const spx_word16_t *_x, const spx_coef_t *den, spx_word16_t *_y, int N, int ord, spx_mem_t *mem, char *stack)
232
VARDECL(spx_word16_t *y);
235
ALLOC(y, (N+2), spx_word16_t);
241
"R0 = %5;\n\t" /*ord */
258
"R1 = R1 << 3 (S);\n\t"
259
"R1.L = R1 (RND);\n\t"
265
/* Samples 1 to ord-1 (using memory) */
269
"LOOP filter_start%= LC0;\n\t"
270
"LOOP_BEGIN filter_start%=;\n\t"
279
"LOOP filter_start_inner%= LC1;\n\t"
280
"LOOP_BEGIN filter_start_inner%=;\n\t"
281
"R4.L = W[I1++];\n\t"
282
"R5.L = W[I3--];\n\t"
283
"A1 -= R4.L*R5.L (IS);\n\t"
284
"LOOP_END filter_start_inner%=;\n\t"
288
"R1.L = R1 (RND);\n\t"
293
"LOOP_END filter_start%=;\n\t"
295
/* Samples ord to N*/
304
"R4.L = W[I1++];\n\t"
306
"LOOP filter_mid%= LC0;\n\t"
307
"LOOP_BEGIN filter_mid%=;\n\t"
312
"R5.L = W[I3--];\n\t"
313
"LOOP filter_mid_inner%= LC1;\n\t"
314
"LOOP_BEGIN filter_mid_inner%=;\n\t"
315
"A1 -= R4.L*R5.L (IS) || R4.L = W[I1++] || R5.L = W[I3--];\n\t"
316
"LOOP_END filter_mid_inner%=;\n\t"
318
"R1 = R1 << 3 || R2 = W[P0++];\n\t"
319
"R1.L = R1 (RND);\n\t"
323
"LOOP_END filter_mid%=;\n\t"
330
"LOOP mem_update%= LC0;\n\t"
331
"LOOP_BEGIN mem_update%=;\n\t"
338
"R5.L = W[I3--] || R4.L = W[I1++];\n\t"
339
"LOOP mem_accum%= LC1;\n\t"
340
"LOOP_BEGIN mem_accum%=;\n\t"
341
"A0 -= R4.L*R5.L (IS) || R4.L = W[I1++] || R5.L = W[I3--];\n\t"
342
"LOOP_END mem_accum%=;\n\t"
345
"LOOP_END mem_update%=;\n\t"
347
: : "m" (yy), "m" (_x), "m" (_y), "m" (den), "m" (N), "m" (ord), "m" (mem)
348
: "A0", "A1", "R0", "R1", "R2", "R3", "R4", "R5", "P0", "P1", "P2", "P3", "P4", "B1", "I1", "I3", "L1", "L3", "memory"
354
#define OVERRIDE_FIR_MEM16
355
void fir_mem16(const spx_word16_t *x, const spx_coef_t *num, spx_word16_t *y, int N, int ord, spx_mem_t *mem, char *stack)
360
den = (spx_coef_t*)((((int)den2)+4)&0xfffffffc);
363
filter_mem16(x, num, den, y, N, ord, mem, stack);
367
#define OVERRIDE_COMPUTE_IMPULSE_RESPONSE
368
void compute_impulse_response(const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack)
371
VARDECL(spx_word16_t *ytmp);
372
ALLOC(ytmp, N, spx_word16_t);
373
spx_word16_t *ytmp2 = ytmp;
398
"LOOP samples%= LC0;\n\t"
399
"LOOP_BEGIN samples%=;\n\t"
401
"R2 = MIN(R2, %4);\n\t"
409
"R0.L = W[I0--] || R1.L = W[I2++];\n\t"
411
"LOOP filter%= LC1;\n\t"
412
"LOOP_BEGIN filter%=;\n\t"
413
"A0 -= R0.L*R1.L (IS) || R0.L = W[I1--] || R1.L = W[I3++];\n\t"
414
"A1 -= R0.L*R1.L (IS) || R0.L = W[I0--] || R1.L = W[I2++];\n\t"
415
"LOOP_END filter%=;\n\t"
416
"R0 = A0, R1 = A1;\n\t"
417
"R3 = W[%1] (X);\n\t"
420
"R3 = R0 >>> 13;\n\t"
426
"LOOP_END samples%=;\n\t"
427
: "=a" (ytmp2), "=a" (y)
428
: "a" (awk2), "a" (ak), "d" (ord), "m" (N), "0" (ytmp2), "1" (y)
429
: "A0", "A1", "R0", "R1", "R2", "R3", "I0", "I1", "I2", "I3", "L0", "L1", "L2", "L3", "A0", "A1"
435
#if 0 /* Equivalent C function for filter_mem2 and compute_impulse_response */
436
#define min(a,b) ((a)<(b) ? (a):(b))
438
void compute_impulse_response(const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack)
441
VARDECL(spx_word16_t *ytmp);
442
ALLOC(ytmp, N, spx_word16_t);
453
spx_word32_t yi = SHL32(EXTEND32(y[i]),LPC_SHIFT);
454
spx_word32_t yi2 = 0;
455
for (j=0;j<min(i,ord);j++)
457
yi = MAC16_16(yi, awk2[j], -ytmp[i-j-1]);
458
yi2 = MAC16_16(yi2, ak[j], -y[i-j-1]);
460
ytmp[i] = EXTRACT16(SHR32(yi,LPC_SHIFT));
461
yi2 = ADD32(yi2,SHL32(yi,1));
462
y[i] = EXTRACT16(SHR32(yi2,LPC_SHIFT));
468
void filter_mem2(const spx_sig_t *_x, const spx_coef_t *num, const spx_coef_t *den, spx_sig_t *_y, int N, int ord, spx_mem_t *mem)
471
spx_word16_t xi,yi,nyi;
472
spx_word16_t x[N],y[N];
473
spx_word16_t *xx, *yy;
478
x[i] = EXTRACT16(SHR32(_x[i],SIG_SHIFT));
483
spx_word32_t yi = mem[i];
486
yi = MAC16_16(yi, num[j], x[i-j-1]);
487
yi = MAC16_16(yi, den[j], -y[i-j-1]);
489
_y[i] = ADD32(_x[i],SHL32(yi,1));
490
y[i] = EXTRACT16(SHR32(_y[i],SIG_SHIFT));
497
yi = MAC16_16(yi, num[j], x[i-j-1]);
498
yi = MAC16_16(yi, den[j], -y[i-j-1]);
500
_y[i] = ADD32(_x[i],SHL32(yi,1));
501
y[i] = EXTRACT16(SHR32(_y[i],SIG_SHIFT));
507
for (j=0;j<ord-i;j++)
509
m = MAC16_16(m, x[N-1-j], num[j+i]);
510
m = MAC16_16(m, -y[N-1-j], den[j+i]);