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.
37
#define OVERRIDE_NORMALIZE16
38
int normalize16(const spx_sig_t *x, spx_word16_t *y, spx_sig_t max_scale, int len)
49
"LOOP norm_max%= LC0 = %2;\n\t"
50
"LOOP_BEGIN norm_max%=;\n\t"
51
"R2 = ABS R1 || R1 = [I0++];\n\t"
52
"%0 = MAX(%0, R2);\n\t"
53
"LOOP_END norm_max%=;\n\t"
60
while (max_val>max_scale)
73
"LOOP norm_shift%= LC0 = %3 >> 1;\n\t"
74
"LOOP_BEGIN norm_shift%=;\n\t"
75
"R1 = ASHIFT R0 by %2.L || R2 = [I0++];\n\t"
76
"R3 = ASHIFT R2 by %2.L || R0 = [I0++];\n\t"
77
"R3 = PACK(R3.L, R1.L);\n\t"
79
"LOOP_END norm_shift%=;\n\t"
80
: : "a" (x), "a" (y), "d" (-sig_shift), "a" (len)
81
: "I0", "L0", "I1", "L1", "R0", "R1", "R2", "R3", "memory"
86
#define OVERRIDE_FILTER_MEM2
87
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)
89
spx_word32_t xy2[N+1];
90
spx_word32_t *xy = xy2+1;
91
spx_word32_t numden_a[2*ord+2];
92
spx_word16_t *numden = (spx_word16_t*) numden_a;
97
numden[2*i+1] = den[i];
102
"R0 = %5;\n\t" /*ord */
125
"R2 = PACK(R1.H, R2.H);\n\t"
128
/* Samples 1 to ord-1 (using memory) */
132
"LOOP filter_start%= LC0;\n\t"
133
"LOOP_BEGIN filter_start%=;\n\t"
143
"R4 = [I0++] || R5 = [I2--];\n\t"
144
"LOOP filter_start_inner%= LC1;\n\t"
145
"LOOP_BEGIN filter_start_inner%=;\n\t"
146
"A0 += R4.L*R5.L (IS), A1 -= R4.H*R5.H (IS) || R4 = [I0++] || R5 = [I2--];\n\t"
147
"LOOP_END filter_start_inner%=;\n\t"
156
"R2 = PACK(R4.H, R2.H);\n\t"
159
"LOOP_END filter_start%=;\n\t"
161
/* Samples ord to N*/
180
"LOOP filter_mid%= LC0;\n\t"
181
"LOOP_BEGIN filter_mid%=;\n\t"
182
"LOOP filter_mid_inner%= LC1=P3;\n\t"
183
"LOOP_BEGIN filter_mid_inner%=;\n\t"
184
"A0 += R4.L*R5.L (IS), A1 -= R4.H*R5.H (IS) || R4 = [I0++] || R5 = [I2--];\n\t"
185
"LOOP_END filter_mid_inner%=;\n\t"
186
"R0 = (A0 += A1) || I2 += M0;\n\t"
187
"R0 = R0 << 1 || R5 = [P0++];\n\t"
189
"R0 = R0 << 2 || [P1++] = R0;\n\t"
191
"R5 = PACK(R0.H, R5.H);\n\t"
192
"A0 = A1 = 0 || [I2--] = R5\n\t"
193
"LOOP_END filter_mid%=;\n\t"
202
"LOOP mem_update%= LC0;\n\t"
203
"LOOP_BEGIN mem_update%=;\n\t"
209
"R5 = [I2--] || R4 = [I0++];\n\t"
210
"LOOP mem_accum%= LC1;\n\t"
211
"LOOP_BEGIN mem_accum%=;\n\t"
212
"A0 += R4.L*R5.L (IS), A1 -= R4.H*R5.H (IS) || R4 = [I0++] || R5 = [I2--];\n\t"
213
"LOOP_END mem_accum%=;\n\t"
214
"R0 = (A0 += A1);\n\t"
215
"A0 = A1 = 0 || [P4++] = R0;\n\t"
216
"LOOP_END mem_update%=;\n\t"
218
: : "m" (xy), "m" (_x), "m" (_y), "m" (numden), "m" (N), "m" (ord), "m" (mem)
219
: "A0", "A1", "R0", "R1", "R2", "R3", "R4", "R5", "P0", "P1", "P2", "P3", "P4", "B0", "I0", "I2", "L0", "L2", "M0", "memory"
227
#define OVERRIDE_IIR_MEM2
228
void iir_mem2(const spx_sig_t *_x, const spx_coef_t *den, spx_sig_t *_y, int N, int ord, spx_mem_t *mem)
236
"R0 = %5;\n\t" /*ord */
261
/* Samples 1 to ord-1 (using memory) */
265
"LOOP filter_start%= LC0;\n\t"
266
"LOOP_BEGIN filter_start%=;\n\t"
275
"LOOP filter_start_inner%= LC1;\n\t"
276
"LOOP_BEGIN filter_start_inner%=;\n\t"
277
"R4.L = W[I1++];\n\t"
278
"R5.L = W[I3--];\n\t"
279
"A1 -= R4.L*R5.L (IS);\n\t"
280
"LOOP_END filter_start_inner%=;\n\t"
290
"LOOP_END filter_start%=;\n\t"
292
/* Samples ord to N*/
301
"R4.L = W[I1++];\n\t"
303
"LOOP filter_mid%= LC0;\n\t"
304
"LOOP_BEGIN filter_mid%=;\n\t"
309
"R5.L = W[I3--];\n\t"
310
"LOOP filter_mid_inner%= LC1;\n\t"
311
"LOOP_BEGIN filter_mid_inner%=;\n\t"
312
"A1 -= R4.L*R5.L (IS) || R4.L = W[I1++] || R5.L = W[I3--];\n\t"
313
"LOOP_END filter_mid_inner%=;\n\t"
315
"R1 = R1 << 1 || R2 = [P0++];\n\t"
317
"R1 = R1 << 2 || [P1++] = R1;\n\t"
319
"LOOP_END filter_mid%=;\n\t"
326
"LOOP mem_update%= LC0;\n\t"
327
"LOOP_BEGIN mem_update%=;\n\t"
334
"R5.L = W[I3--] || R4.L = W[I1++];\n\t"
335
"LOOP mem_accum%= LC1;\n\t"
336
"LOOP_BEGIN mem_accum%=;\n\t"
337
"A0 -= R4.L*R5.L (IS) || R4.L = W[I1++] || R5.L = W[I3--];\n\t"
338
"LOOP_END mem_accum%=;\n\t"
341
"LOOP_END mem_update%=;\n\t"
343
: : "m" (yy), "m" (_x), "m" (_y), "m" (den), "m" (N), "m" (ord), "m" (mem)
344
: "A0", "A1", "R0", "R1", "R2", "R3", "R4", "R5", "P0", "P1", "P2", "P3", "P4", "B1", "I1", "I3", "L1", "L3", "memory"
349
#define OVERRIDE_FIR_MEM2
350
void fir_mem2(const spx_sig_t *x, const spx_coef_t *num, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
355
den = (spx_coef_t*)((((int)den2)+4)&0xfffffffc);
358
filter_mem2(x, num, den, y, N, ord, mem);
362
#define OVERRIDE_COMPUTE_IMPULSE_RESPONSE
363
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)
366
VARDECL(spx_word16_t *ytmp);
367
ALLOC(ytmp, N, spx_word16_t);
368
spx_word16_t *ytmp2 = ytmp;
393
"LOOP samples%= LC0;\n\t"
394
"LOOP_BEGIN samples%=;\n\t"
396
"R2 = MIN(R2, %4);\n\t"
404
"R0.L = W[I0--] || R1.L = W[I2++];\n\t"
406
"LOOP filter%= LC1;\n\t"
407
"LOOP_BEGIN filter%=;\n\t"
408
"A0 -= R0.L*R1.L (IS) || R0.L = W[I1--] || R1.L = W[I3++];\n\t"
409
"A1 -= R0.L*R1.L (IS) || R0.L = W[I0--] || R1.L = W[I2++];\n\t"
410
"LOOP_END filter%=;\n\t"
411
"R0 = A0, R1 = A1;\n\t"
412
"R3 = W[%1] (X);\n\t"
415
"R3 = R0 >>> 13;\n\t"
421
"LOOP_END samples%=;\n\t"
422
: "=a" (ytmp2), "=a" (y)
423
: "a" (awk2), "a" (ak), "d" (ord), "m" (N), "0" (ytmp2), "1" (y)
424
: "A0", "A1", "R0", "R1", "R2", "R3", "I0", "I1", "I2", "I3", "L0", "L1", "L2", "L3", "A0", "A1"
430
#if 0 /* Equivalent C function for filter_mem2 and compute_impulse_response */
431
#define min(a,b) ((a)<(b) ? (a):(b))
433
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)
436
VARDECL(spx_word16_t *ytmp);
437
ALLOC(ytmp, N, spx_word16_t);
448
spx_word32_t yi = SHL32(EXTEND32(y[i]),LPC_SHIFT);
449
spx_word32_t yi2 = 0;
450
for (j=0;j<min(i,ord);j++)
452
yi = MAC16_16(yi, awk2[j], -ytmp[i-j-1]);
453
yi2 = MAC16_16(yi2, ak[j], -y[i-j-1]);
455
ytmp[i] = EXTRACT16(SHR32(yi,LPC_SHIFT));
456
yi2 = ADD32(yi2,SHL32(yi,1));
457
y[i] = EXTRACT16(SHR32(yi2,LPC_SHIFT));
463
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)
466
spx_word16_t xi,yi,nyi;
467
spx_word16_t x[N],y[N];
468
spx_word16_t *xx, *yy;
473
x[i] = EXTRACT16(SHR32(_x[i],SIG_SHIFT));
478
spx_word32_t yi = mem[i];
481
yi = MAC16_16(yi, num[j], x[i-j-1]);
482
yi = MAC16_16(yi, den[j], -y[i-j-1]);
484
_y[i] = ADD32(_x[i],SHL32(yi,1));
485
y[i] = EXTRACT16(SHR32(_y[i],SIG_SHIFT));
492
yi = MAC16_16(yi, num[j], x[i-j-1]);
493
yi = MAC16_16(yi, den[j], -y[i-j-1]);
495
_y[i] = ADD32(_x[i],SHL32(yi,1));
496
y[i] = EXTRACT16(SHR32(_y[i],SIG_SHIFT));
502
for (j=0;j<ord-i;j++)
504
m = MAC16_16(m, x[N-1-j], num[j+i]);
505
m = MAC16_16(m, -y[N-1-j], den[j+i]);