diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/celt/kiss_fft.c')
-rw-r--r-- | lib/rbcodec/codecs/libopus/celt/kiss_fft.c | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/lib/rbcodec/codecs/libopus/celt/kiss_fft.c b/lib/rbcodec/codecs/libopus/celt/kiss_fft.c index 833ef5a71f..83775165d8 100644 --- a/lib/rbcodec/codecs/libopus/celt/kiss_fft.c +++ b/lib/rbcodec/codecs/libopus/celt/kiss_fft.c | |||
@@ -82,8 +82,8 @@ static void kf_bfly2( | |||
82 | C_SUB( Fout2[0] , Fout[0] , t ); | 82 | C_SUB( Fout2[0] , Fout[0] , t ); |
83 | C_ADDTO( Fout[0] , t ); | 83 | C_ADDTO( Fout[0] , t ); |
84 | 84 | ||
85 | t.r = S_MUL(Fout2[1].r+Fout2[1].i, tw); | 85 | t.r = S_MUL(ADD32_ovflw(Fout2[1].r, Fout2[1].i), tw); |
86 | t.i = S_MUL(Fout2[1].i-Fout2[1].r, tw); | 86 | t.i = S_MUL(SUB32_ovflw(Fout2[1].i, Fout2[1].r), tw); |
87 | C_SUB( Fout2[1] , Fout[1] , t ); | 87 | C_SUB( Fout2[1] , Fout[1] , t ); |
88 | C_ADDTO( Fout[1] , t ); | 88 | C_ADDTO( Fout[1] , t ); |
89 | 89 | ||
@@ -92,8 +92,8 @@ static void kf_bfly2( | |||
92 | C_SUB( Fout2[2] , Fout[2] , t ); | 92 | C_SUB( Fout2[2] , Fout[2] , t ); |
93 | C_ADDTO( Fout[2] , t ); | 93 | C_ADDTO( Fout[2] , t ); |
94 | 94 | ||
95 | t.r = S_MUL(Fout2[3].i-Fout2[3].r, tw); | 95 | t.r = S_MUL(SUB32_ovflw(Fout2[3].i, Fout2[3].r), tw); |
96 | t.i = S_MUL(-Fout2[3].i-Fout2[3].r, tw); | 96 | t.i = S_MUL(NEG32_ovflw(ADD32_ovflw(Fout2[3].i, Fout2[3].r)), tw); |
97 | C_SUB( Fout2[3] , Fout[3] , t ); | 97 | C_SUB( Fout2[3] , Fout[3] , t ); |
98 | C_ADDTO( Fout[3] , t ); | 98 | C_ADDTO( Fout[3] , t ); |
99 | Fout += 8; | 99 | Fout += 8; |
@@ -126,10 +126,10 @@ static void kf_bfly4( | |||
126 | C_ADDTO( *Fout , scratch1 ); | 126 | C_ADDTO( *Fout , scratch1 ); |
127 | C_SUB( scratch1 , Fout[1] , Fout[3] ); | 127 | C_SUB( scratch1 , Fout[1] , Fout[3] ); |
128 | 128 | ||
129 | Fout[1].r = scratch0.r + scratch1.i; | 129 | Fout[1].r = ADD32_ovflw(scratch0.r, scratch1.i); |
130 | Fout[1].i = scratch0.i - scratch1.r; | 130 | Fout[1].i = SUB32_ovflw(scratch0.i, scratch1.r); |
131 | Fout[3].r = scratch0.r - scratch1.i; | 131 | Fout[3].r = SUB32_ovflw(scratch0.r, scratch1.i); |
132 | Fout[3].i = scratch0.i + scratch1.r; | 132 | Fout[3].i = ADD32_ovflw(scratch0.i, scratch1.r); |
133 | Fout+=4; | 133 | Fout+=4; |
134 | } | 134 | } |
135 | } else { | 135 | } else { |
@@ -160,10 +160,10 @@ static void kf_bfly4( | |||
160 | tw3 += fstride*3; | 160 | tw3 += fstride*3; |
161 | C_ADDTO( *Fout , scratch[3] ); | 161 | C_ADDTO( *Fout , scratch[3] ); |
162 | 162 | ||
163 | Fout[m].r = scratch[5].r + scratch[4].i; | 163 | Fout[m].r = ADD32_ovflw(scratch[5].r, scratch[4].i); |
164 | Fout[m].i = scratch[5].i - scratch[4].r; | 164 | Fout[m].i = SUB32_ovflw(scratch[5].i, scratch[4].r); |
165 | Fout[m3].r = scratch[5].r - scratch[4].i; | 165 | Fout[m3].r = SUB32_ovflw(scratch[5].r, scratch[4].i); |
166 | Fout[m3].i = scratch[5].i + scratch[4].r; | 166 | Fout[m3].i = ADD32_ovflw(scratch[5].i, scratch[4].r); |
167 | ++Fout; | 167 | ++Fout; |
168 | } | 168 | } |
169 | } | 169 | } |
@@ -191,7 +191,7 @@ static void kf_bfly3( | |||
191 | 191 | ||
192 | kiss_fft_cpx * Fout_beg = Fout; | 192 | kiss_fft_cpx * Fout_beg = Fout; |
193 | #ifdef FIXED_POINT | 193 | #ifdef FIXED_POINT |
194 | epi3.r = -16384; | 194 | /*epi3.r = -16384;*/ /* Unused */ |
195 | epi3.i = -28378; | 195 | epi3.i = -28378; |
196 | #else | 196 | #else |
197 | epi3 = st->twiddles[fstride*m]; | 197 | epi3 = st->twiddles[fstride*m]; |
@@ -212,18 +212,18 @@ static void kf_bfly3( | |||
212 | tw1 += fstride; | 212 | tw1 += fstride; |
213 | tw2 += fstride*2; | 213 | tw2 += fstride*2; |
214 | 214 | ||
215 | Fout[m].r = Fout->r - HALF_OF(scratch[3].r); | 215 | Fout[m].r = SUB32_ovflw(Fout->r, HALF_OF(scratch[3].r)); |
216 | Fout[m].i = Fout->i - HALF_OF(scratch[3].i); | 216 | Fout[m].i = SUB32_ovflw(Fout->i, HALF_OF(scratch[3].i)); |
217 | 217 | ||
218 | C_MULBYSCALAR( scratch[0] , epi3.i ); | 218 | C_MULBYSCALAR( scratch[0] , epi3.i ); |
219 | 219 | ||
220 | C_ADDTO(*Fout,scratch[3]); | 220 | C_ADDTO(*Fout,scratch[3]); |
221 | 221 | ||
222 | Fout[m2].r = Fout[m].r + scratch[0].i; | 222 | Fout[m2].r = ADD32_ovflw(Fout[m].r, scratch[0].i); |
223 | Fout[m2].i = Fout[m].i - scratch[0].r; | 223 | Fout[m2].i = SUB32_ovflw(Fout[m].i, scratch[0].r); |
224 | 224 | ||
225 | Fout[m].r -= scratch[0].i; | 225 | Fout[m].r = SUB32_ovflw(Fout[m].r, scratch[0].i); |
226 | Fout[m].i += scratch[0].r; | 226 | Fout[m].i = ADD32_ovflw(Fout[m].i, scratch[0].r); |
227 | 227 | ||
228 | ++Fout; | 228 | ++Fout; |
229 | } while(--k); | 229 | } while(--k); |
@@ -282,22 +282,22 @@ static void kf_bfly5( | |||
282 | C_ADD( scratch[8],scratch[2],scratch[3]); | 282 | C_ADD( scratch[8],scratch[2],scratch[3]); |
283 | C_SUB( scratch[9],scratch[2],scratch[3]); | 283 | C_SUB( scratch[9],scratch[2],scratch[3]); |
284 | 284 | ||
285 | Fout0->r += scratch[7].r + scratch[8].r; | 285 | Fout0->r = ADD32_ovflw(Fout0->r, ADD32_ovflw(scratch[7].r, scratch[8].r)); |
286 | Fout0->i += scratch[7].i + scratch[8].i; | 286 | Fout0->i = ADD32_ovflw(Fout0->i, ADD32_ovflw(scratch[7].i, scratch[8].i)); |
287 | 287 | ||
288 | scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,ya.r) + S_MUL(scratch[8].r,yb.r); | 288 | scratch[5].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,ya.r), S_MUL(scratch[8].r,yb.r))); |
289 | scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,ya.r) + S_MUL(scratch[8].i,yb.r); | 289 | scratch[5].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,ya.r), S_MUL(scratch[8].i,yb.r))); |
290 | 290 | ||
291 | scratch[6].r = S_MUL(scratch[10].i,ya.i) + S_MUL(scratch[9].i,yb.i); | 291 | scratch[6].r = ADD32_ovflw(S_MUL(scratch[10].i,ya.i), S_MUL(scratch[9].i,yb.i)); |
292 | scratch[6].i = -S_MUL(scratch[10].r,ya.i) - S_MUL(scratch[9].r,yb.i); | 292 | scratch[6].i = NEG32_ovflw(ADD32_ovflw(S_MUL(scratch[10].r,ya.i), S_MUL(scratch[9].r,yb.i))); |
293 | 293 | ||
294 | C_SUB(*Fout1,scratch[5],scratch[6]); | 294 | C_SUB(*Fout1,scratch[5],scratch[6]); |
295 | C_ADD(*Fout4,scratch[5],scratch[6]); | 295 | C_ADD(*Fout4,scratch[5],scratch[6]); |
296 | 296 | ||
297 | scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,yb.r) + S_MUL(scratch[8].r,ya.r); | 297 | scratch[11].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,yb.r), S_MUL(scratch[8].r,ya.r))); |
298 | scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,yb.r) + S_MUL(scratch[8].i,ya.r); | 298 | scratch[11].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,yb.r), S_MUL(scratch[8].i,ya.r))); |
299 | scratch[12].r = - S_MUL(scratch[10].i,yb.i) + S_MUL(scratch[9].i,ya.i); | 299 | scratch[12].r = SUB32_ovflw(S_MUL(scratch[9].i,ya.i), S_MUL(scratch[10].i,yb.i)); |
300 | scratch[12].i = S_MUL(scratch[10].r,yb.i) - S_MUL(scratch[9].r,ya.i); | 300 | scratch[12].i = SUB32_ovflw(S_MUL(scratch[10].r,yb.i), S_MUL(scratch[9].r,ya.i)); |
301 | 301 | ||
302 | C_ADD(*Fout2,scratch[11],scratch[12]); | 302 | C_ADD(*Fout2,scratch[11],scratch[12]); |
303 | C_SUB(*Fout3,scratch[11],scratch[12]); | 303 | C_SUB(*Fout3,scratch[11],scratch[12]); |
@@ -423,13 +423,19 @@ static void compute_twiddles(kiss_twiddle_cpx *twiddles, int nfft) | |||
423 | #endif | 423 | #endif |
424 | } | 424 | } |
425 | 425 | ||
426 | int opus_fft_alloc_arch_c(kiss_fft_state *st) { | ||
427 | (void)st; | ||
428 | return 0; | ||
429 | } | ||
430 | |||
426 | /* | 431 | /* |
427 | * | 432 | * |
428 | * Allocates all necessary storage space for the fft and ifft. | 433 | * Allocates all necessary storage space for the fft and ifft. |
429 | * The return value is a contiguous block of memory. As such, | 434 | * The return value is a contiguous block of memory. As such, |
430 | * It can be freed with free(). | 435 | * It can be freed with free(). |
431 | * */ | 436 | * */ |
432 | kiss_fft_state *opus_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base) | 437 | kiss_fft_state *opus_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, |
438 | const kiss_fft_state *base, int arch) | ||
433 | { | 439 | { |
434 | kiss_fft_state *st=NULL; | 440 | kiss_fft_state *st=NULL; |
435 | size_t memneeded = sizeof(struct kiss_fft_state); /* twiddle factors*/ | 441 | size_t memneeded = sizeof(struct kiss_fft_state); /* twiddle factors*/ |
@@ -478,22 +484,31 @@ kiss_fft_state *opus_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, co | |||
478 | if (st->bitrev==NULL) | 484 | if (st->bitrev==NULL) |
479 | goto fail; | 485 | goto fail; |
480 | compute_bitrev_table(0, bitrev, 1,1, st->factors,st); | 486 | compute_bitrev_table(0, bitrev, 1,1, st->factors,st); |
487 | |||
488 | /* Initialize architecture specific fft parameters */ | ||
489 | if (opus_fft_alloc_arch(st, arch)) | ||
490 | goto fail; | ||
481 | } | 491 | } |
482 | return st; | 492 | return st; |
483 | fail: | 493 | fail: |
484 | opus_fft_free(st); | 494 | opus_fft_free(st, arch); |
485 | return NULL; | 495 | return NULL; |
486 | } | 496 | } |
487 | 497 | ||
488 | kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem ) | 498 | kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem, int arch) |
489 | { | 499 | { |
490 | return opus_fft_alloc_twiddles(nfft, mem, lenmem, NULL); | 500 | return opus_fft_alloc_twiddles(nfft, mem, lenmem, NULL, arch); |
491 | } | 501 | } |
492 | 502 | ||
493 | void opus_fft_free(const kiss_fft_state *cfg) | 503 | void opus_fft_free_arch_c(kiss_fft_state *st) { |
504 | (void)st; | ||
505 | } | ||
506 | |||
507 | void opus_fft_free(const kiss_fft_state *cfg, int arch) | ||
494 | { | 508 | { |
495 | if (cfg) | 509 | if (cfg) |
496 | { | 510 | { |
511 | opus_fft_free_arch((kiss_fft_state *)cfg, arch); | ||
497 | opus_free((opus_int16*)cfg->bitrev); | 512 | opus_free((opus_int16*)cfg->bitrev); |
498 | if (cfg->shift < 0) | 513 | if (cfg->shift < 0) |
499 | opus_free((kiss_twiddle_cpx*)cfg->twiddles); | 514 | opus_free((kiss_twiddle_cpx*)cfg->twiddles); |
@@ -551,8 +566,7 @@ void opus_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout) | |||
551 | } | 566 | } |
552 | } | 567 | } |
553 | 568 | ||
554 | #if 0 | 569 | void opus_fft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) |
555 | void opus_fft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) | ||
556 | { | 570 | { |
557 | int i; | 571 | int i; |
558 | opus_val16 scale; | 572 | opus_val16 scale; |
@@ -573,11 +587,9 @@ void opus_fft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fou | |||
573 | } | 587 | } |
574 | opus_fft_impl(st, fout); | 588 | opus_fft_impl(st, fout); |
575 | } | 589 | } |
576 | #endif | ||
577 | 590 | ||
578 | 591 | ||
579 | #ifdef TEST_UNIT_DFT_C | 592 | void opus_ifft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) |
580 | void opus_ifft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout) | ||
581 | { | 593 | { |
582 | int i; | 594 | int i; |
583 | celt_assert2 (fin != fout, "In-place FFT not supported"); | 595 | celt_assert2 (fin != fout, "In-place FFT not supported"); |
@@ -590,4 +602,3 @@ void opus_ifft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fo | |||
590 | for (i=0;i<st->nfft;i++) | 602 | for (i=0;i<st->nfft;i++) |
591 | fout[i].i = -fout[i].i; | 603 | fout[i].i = -fout[i].i; |
592 | } | 604 | } |
593 | #endif | ||