OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. | 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 Redistribution and use in source and binary forms, with or without | 3 Redistribution and use in source and binary forms, with or without |
4 modification, are permitted provided that the following conditions | 4 modification, are permitted provided that the following conditions |
5 are met: | 5 are met: |
6 - Redistributions of source code must retain the above copyright notice, | 6 - Redistributions of source code must retain the above copyright notice, |
7 this list of conditions and the following disclaimer. | 7 this list of conditions and the following disclaimer. |
8 - Redistributions in binary form must reproduce the above copyright | 8 - Redistributions in binary form must reproduce the above copyright |
9 notice, this list of conditions and the following disclaimer in the | 9 notice, this list of conditions and the following disclaimer in the |
10 documentation and/or other materials provided with the distribution. | 10 documentation and/or other materials provided with the distribution. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #ifndef SILK_SIGPROC_FIX_H | 28 #ifndef SILK_SIGPROC_FIX_H |
29 #define SILK_SIGPROC_FIX_H | 29 #define SILK_SIGPROC_FIX_H |
30 | 30 |
31 #ifdef __cplusplus | 31 #ifdef __cplusplus |
32 extern "C" | 32 extern "C" |
33 { | 33 { |
34 #endif | 34 #endif |
35 | 35 |
36 /*#define silk_MACRO_COUNT */ /* Used to enable WMOPS counting */ | 36 /*#define silk_MACRO_COUNT */ /* Used to enable WMOPS counting */ |
37 | 37 |
38 #define SILK_MAX_ORDER_LPC 16 /* max order of the LPC anal
ysis in schur() and k2a() */ | 38 #define SILK_MAX_ORDER_LPC 24 /* max order of the LPC anal
ysis in schur() and k2a() */ |
39 | 39 |
40 #include <string.h> /* for memset(), memcpy(), m
emmove() */ | 40 #include <string.h> /* for memset(), memcpy(), m
emmove() */ |
41 #include "typedef.h" | 41 #include "typedef.h" |
42 #include "resampler_structs.h" | 42 #include "resampler_structs.h" |
43 #include "macros.h" | 43 #include "macros.h" |
44 #include "cpu_support.h" | 44 #include "cpu_support.h" |
45 | 45 |
46 #if defined(OPUS_X86_MAY_HAVE_SSE4_1) | 46 #if defined(OPUS_X86_MAY_HAVE_SSE4_1) |
47 #include "x86/SigProc_FIX_sse.h" | 47 #include "x86/SigProc_FIX_sse.h" |
48 #endif | 48 #endif |
49 | 49 |
| 50 #if (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) |
| 51 #include "arm/biquad_alt_arm.h" |
| 52 #include "arm/LPC_inv_pred_gain_arm.h" |
| 53 #endif |
| 54 |
50 /********************************************************************/ | 55 /********************************************************************/ |
51 /* SIGNAL PROCESSING FUNCTIONS */ | 56 /* SIGNAL PROCESSING FUNCTIONS */ |
52 /********************************************************************/ | 57 /********************************************************************/ |
53 | 58 |
54 /*! | 59 /*! |
55 * Initialize/reset the resampler state for a given pair of input/output samplin
g rates | 60 * Initialize/reset the resampler state for a given pair of input/output samplin
g rates |
56 */ | 61 */ |
57 opus_int silk_resampler_init( | 62 opus_int silk_resampler_init( |
58 silk_resampler_state_struct *S, /* I/O Resampler state
*/ | 63 silk_resampler_state_struct *S, /* I/O Resampler state
*/ |
59 opus_int32 Fs_Hz_in, /* I Input sampling rate
(Hz) */ | 64 opus_int32 Fs_Hz_in, /* I Input sampling rate
(Hz) */ |
(...skipping 29 matching lines...) Expand all Loading... |
89 opus_int16 *out, /* O Output signal [ floo
r(2*inLen/3) ] */ | 94 opus_int16 *out, /* O Output signal [ floo
r(2*inLen/3) ] */ |
90 const opus_int16 *in, /* I Input signal [ inLen
] */ | 95 const opus_int16 *in, /* I Input signal [ inLen
] */ |
91 opus_int32 inLen /* I Number of input samp
les */ | 96 opus_int32 inLen /* I Number of input samp
les */ |
92 ); | 97 ); |
93 | 98 |
94 /*! | 99 /*! |
95 * second order ARMA filter; | 100 * second order ARMA filter; |
96 * slower than biquad() but uses more precise coefficients | 101 * slower than biquad() but uses more precise coefficients |
97 * can handle (slowly) varying coefficients | 102 * can handle (slowly) varying coefficients |
98 */ | 103 */ |
99 void silk_biquad_alt( | 104 void silk_biquad_alt_stride1( |
100 const opus_int16 *in, /* I input signal
*/ | 105 const opus_int16 *in, /* I input signal
*/ |
101 const opus_int32 *B_Q28, /* I MA coefficients [3]
*/ | 106 const opus_int32 *B_Q28, /* I MA coefficients [3]
*/ |
102 const opus_int32 *A_Q28, /* I AR coefficients [2]
*/ | 107 const opus_int32 *A_Q28, /* I AR coefficients [2]
*/ |
103 opus_int32 *S, /* I/O State vector [2]
*/ | 108 opus_int32 *S, /* I/O State vector [2]
*/ |
104 opus_int16 *out, /* O output signal
*/ | 109 opus_int16 *out, /* O output signal
*/ |
105 const opus_int32 len, /* I signal length (must
be even) */ | 110 const opus_int32 len /* I signal length (must
be even) */ |
106 opus_int stride /* I Operate on interlea
ved signal if > 1 */ | 111 ); |
| 112 |
| 113 void silk_biquad_alt_stride2_c( |
| 114 const opus_int16 *in, /* I input signal
*/ |
| 115 const opus_int32 *B_Q28, /* I MA coefficients [3]
*/ |
| 116 const opus_int32 *A_Q28, /* I AR coefficients [2]
*/ |
| 117 opus_int32 *S, /* I/O State vector [4]
*/ |
| 118 opus_int16 *out, /* O output signal
*/ |
| 119 const opus_int32 len /* I signal length (must
be even) */ |
107 ); | 120 ); |
108 | 121 |
109 /* Variable order MA prediction error filter. */ | 122 /* Variable order MA prediction error filter. */ |
110 void silk_LPC_analysis_filter( | 123 void silk_LPC_analysis_filter( |
111 opus_int16 *out, /* O Output signal
*/ | 124 opus_int16 *out, /* O Output signal
*/ |
112 const opus_int16 *in, /* I Input signal
*/ | 125 const opus_int16 *in, /* I Input signal
*/ |
113 const opus_int16 *B, /* I MA prediction coeffi
cients, Q12 [order] */ | 126 const opus_int16 *B, /* I MA prediction coeffi
cients, Q12 [order] */ |
114 const opus_int32 len, /* I Signal length
*/ | 127 const opus_int32 len, /* I Signal length
*/ |
115 const opus_int32 d, /* I Filter order
*/ | 128 const opus_int32 d, /* I Filter order
*/ |
116 int arch /* I Run-time architectur
e */ | 129 int arch /* I Run-time architectur
e */ |
117 ); | 130 ); |
118 | 131 |
119 /* Chirp (bandwidth expand) LP AR filter */ | 132 /* Chirp (bandwidth expand) LP AR filter */ |
120 void silk_bwexpander( | 133 void silk_bwexpander( |
121 opus_int16 *ar, /* I/O AR filter to be expa
nded (without leading 1) */ | 134 opus_int16 *ar, /* I/O AR filter to be expa
nded (without leading 1) */ |
122 const opus_int d, /* I Length of ar
*/ | 135 const opus_int d, /* I Length of ar
*/ |
123 opus_int32 chirp_Q16 /* I Chirp factor (typica
lly in the range 0 to 1) */ | 136 opus_int32 chirp_Q16 /* I Chirp factor (typica
lly in the range 0 to 1) */ |
124 ); | 137 ); |
125 | 138 |
126 /* Chirp (bandwidth expand) LP AR filter */ | 139 /* Chirp (bandwidth expand) LP AR filter */ |
127 void silk_bwexpander_32( | 140 void silk_bwexpander_32( |
128 opus_int32 *ar, /* I/O AR filter to be expa
nded (without leading 1) */ | 141 opus_int32 *ar, /* I/O AR filter to be expa
nded (without leading 1) */ |
129 const opus_int d, /* I Length of ar
*/ | 142 const opus_int d, /* I Length of ar
*/ |
130 opus_int32 chirp_Q16 /* I Chirp factor in Q16
*/ | 143 opus_int32 chirp_Q16 /* I Chirp factor in Q16
*/ |
131 ); | 144 ); |
132 | 145 |
133 /* Compute inverse of LPC prediction gain, and */ | 146 /* Compute inverse of LPC prediction gain, and */ |
134 /* test if LPC coefficients are stable (all poles within unit circle) */ | 147 /* test if LPC coefficients are stable (all poles within unit circle) */ |
135 opus_int32 silk_LPC_inverse_pred_gain( /* O Returns inverse predi
ction gain in energy domain, Q30 */ | 148 opus_int32 silk_LPC_inverse_pred_gain_c( /* O Returns inverse predi
ction gain in energy domain, Q30 */ |
136 const opus_int16 *A_Q12, /* I Prediction coefficien
ts, Q12 [order] */ | 149 const opus_int16 *A_Q12, /* I Prediction coefficien
ts, Q12 [order] */ |
137 const opus_int order /* I Prediction order
*/ | 150 const opus_int order /* I Prediction order
*/ |
138 ); | 151 ); |
139 | 152 |
140 /* For input in Q24 domain */ | |
141 opus_int32 silk_LPC_inverse_pred_gain_Q24( /* O Returns inverse pred
iction gain in energy domain, Q30 */ | |
142 const opus_int32 *A_Q24, /* I Prediction coefficie
nts [order] */ | |
143 const opus_int order /* I Prediction order
*/ | |
144 ); | |
145 | |
146 /* Split signal in two decimated bands using first-order allpass filters */ | 153 /* Split signal in two decimated bands using first-order allpass filters */ |
147 void silk_ana_filt_bank_1( | 154 void silk_ana_filt_bank_1( |
148 const opus_int16 *in, /* I Input signal [N]
*/ | 155 const opus_int16 *in, /* I Input signal [N]
*/ |
149 opus_int32 *S, /* I/O State vector [2]
*/ | 156 opus_int32 *S, /* I/O State vector [2]
*/ |
150 opus_int16 *outL, /* O Low band [N/2]
*/ | 157 opus_int16 *outL, /* O Low band [N/2]
*/ |
151 opus_int16 *outH, /* O High band [N/2]
*/ | 158 opus_int16 *outH, /* O High band [N/2]
*/ |
152 const opus_int32 N /* I Number of input samp
les */ | 159 const opus_int32 N /* I Number of input samp
les */ |
153 ); | 160 ); |
154 | 161 |
| 162 #if !defined(OVERRIDE_silk_biquad_alt_stride2) |
| 163 #define silk_biquad_alt_stride2(in, B_Q28, A_Q28, S, out, len, arch) ((void)(arc
h), silk_biquad_alt_stride2_c(in, B_Q28, A_Q28, S, out, len)) |
| 164 #endif |
| 165 |
| 166 #if !defined(OVERRIDE_silk_LPC_inverse_pred_gain) |
| 167 #define silk_LPC_inverse_pred_gain(A_Q12, order, arch) ((void)(arch), silk_L
PC_inverse_pred_gain_c(A_Q12, order)) |
| 168 #endif |
| 169 |
155 /********************************************************************/ | 170 /********************************************************************/ |
156 /* SCALAR FUNCTIONS */ | 171 /* SCALAR FUNCTIONS */ |
157 /********************************************************************/ | 172 /********************************************************************/ |
158 | 173 |
159 /* Approximation of 128 * log2() (exact inverse of approx 2^() below) */ | 174 /* Approximation of 128 * log2() (exact inverse of approx 2^() below) */ |
160 /* Convert input to a log scale */ | 175 /* Convert input to a log scale */ |
161 opus_int32 silk_lin2log( | 176 opus_int32 silk_lin2log( |
162 const opus_int32 inLin /* I input in linear scale
*/ | 177 const opus_int32 inLin /* I input in linear scale
*/ |
163 ); | 178 ); |
164 | 179 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 void silk_A2NLSF( | 279 void silk_A2NLSF( |
265 opus_int16 *NLSF, /* O Normalized Line Spec
tral Frequencies in Q15 (0..2^15-1) [d] */ | 280 opus_int16 *NLSF, /* O Normalized Line Spec
tral Frequencies in Q15 (0..2^15-1) [d] */ |
266 opus_int32 *a_Q16, /* I/O Monic whitening filt
er coefficients in Q16 [d] */ | 281 opus_int32 *a_Q16, /* I/O Monic whitening filt
er coefficients in Q16 [d] */ |
267 const opus_int d /* I Filter order (must b
e even) */ | 282 const opus_int d /* I Filter order (must b
e even) */ |
268 ); | 283 ); |
269 | 284 |
270 /* compute whitening filter coefficients from normalized line spectral frequenci
es */ | 285 /* compute whitening filter coefficients from normalized line spectral frequenci
es */ |
271 void silk_NLSF2A( | 286 void silk_NLSF2A( |
272 opus_int16 *a_Q12, /* O monic whitening filt
er coefficients in Q12, [ d ] */ | 287 opus_int16 *a_Q12, /* O monic whitening filt
er coefficients in Q12, [ d ] */ |
273 const opus_int16 *NLSF, /* I normalized line spec
tral frequencies in Q15, [ d ] */ | 288 const opus_int16 *NLSF, /* I normalized line spec
tral frequencies in Q15, [ d ] */ |
274 const opus_int d /* I filter order (should
be even) */ | 289 const opus_int d, /* I filter order (should
be even) */ |
| 290 int arch /* I Run-time architectur
e */ |
| 291 ); |
| 292 |
| 293 /* Convert int32 coefficients to int16 coefs and make sure there's no wrap-aroun
d */ |
| 294 void silk_LPC_fit( |
| 295 opus_int16 *a_QOUT, /* O Output signal
*/ |
| 296 opus_int32 *a_QIN, /* I/O Input signal
*/ |
| 297 const opus_int QOUT, /* I Input Q domain
*/ |
| 298 const opus_int QIN, /* I Input Q domain
*/ |
| 299 const opus_int d /* I Filter order
*/ |
275 ); | 300 ); |
276 | 301 |
277 void silk_insertion_sort_increasing( | 302 void silk_insertion_sort_increasing( |
278 opus_int32 *a, /* I/O Unsorted / Sorted v
ector */ | 303 opus_int32 *a, /* I/O Unsorted / Sorted v
ector */ |
279 opus_int *idx, /* O Index vector for th
e sorted elements */ | 304 opus_int *idx, /* O Index vector for th
e sorted elements */ |
280 const opus_int L, /* I Vector length
*/ | 305 const opus_int L, /* I Vector length
*/ |
281 const opus_int K /* I Number of correctly
sorted positions */ | 306 const opus_int K /* I Number of correctly
sorted positions */ |
282 ); | 307 ); |
283 | 308 |
284 void silk_insertion_sort_decreasing_int16( | 309 void silk_insertion_sort_decreasing_int16( |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 #define silk_SUB_SAT64(a, b) ((((a)-(b)) & 0x8000000000000000LL)
== 0 ? \ | 489 #define silk_SUB_SAT64(a, b) ((((a)-(b)) & 0x8000000000000000LL)
== 0 ? \ |
465 (( (a) & ((b)^0x8000000000000000LL)
& 0x8000000000000000LL) ? silk_int64_MIN : (a)-(b)) : \ | 490 (( (a) & ((b)^0x8000000000000000LL)
& 0x8000000000000000LL) ? silk_int64_MIN : (a)-(b)) : \ |
466 ((((a)^0x8000000000000000LL) & (b)
& 0x8000000000000000LL) ? silk_int64_MAX : (a)-(b)) ) | 491 ((((a)^0x8000000000000000LL) & (b)
& 0x8000000000000000LL) ? silk_int64_MAX : (a)-(b)) ) |
467 | 492 |
468 /* Saturation for positive input values */ | 493 /* Saturation for positive input values */ |
469 #define silk_POS_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_M
AX : (a)) | 494 #define silk_POS_SAT32(a) ((a) > silk_int32_MAX ? silk_int32_M
AX : (a)) |
470 | 495 |
471 /* Add with saturation for positive input values */ | 496 /* Add with saturation for positive input values */ |
472 #define silk_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80)
? silk_int8_MAX : ((a)+(b))) | 497 #define silk_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80)
? silk_int8_MAX : ((a)+(b))) |
473 #define silk_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000)
? silk_int16_MAX : ((a)+(b))) | 498 #define silk_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000)
? silk_int16_MAX : ((a)+(b))) |
474 #define silk_ADD_POS_SAT32(a, b) ((((a)+(b)) & 0x80000000)
? silk_int32_MAX : ((a)+(b))) | 499 #define silk_ADD_POS_SAT32(a, b) ((((opus_uint32)(a)+(opus_uint32)(b)
) & 0x80000000) ? silk_int32_MAX : ((a)+(b))) |
475 #define silk_ADD_POS_SAT64(a, b) ((((a)+(b)) & 0x8000000000000000LL)
? silk_int64_MAX : ((a)+(b))) | |
476 | 500 |
477 #define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift
))) /* shift >= 0, shift < 8 */ | 501 #define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift
))) /* shift >= 0, shift < 8 */ |
478 #define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shi
ft))) /* shift >= 0, shift < 16 */ | 502 #define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shi
ft))) /* shift >= 0, shift < 16 */ |
479 #define silk_LSHIFT32(a, shift) ((opus_int32)((opus_uint32)(a)<<(shi
ft))) /* shift >= 0, shift < 32 */ | 503 #define silk_LSHIFT32(a, shift) ((opus_int32)((opus_uint32)(a)<<(shi
ft))) /* shift >= 0, shift < 32 */ |
480 #define silk_LSHIFT64(a, shift) ((opus_int64)((opus_uint64)(a)<<(shi
ft))) /* shift >= 0, shift < 64 */ | 504 #define silk_LSHIFT64(a, shift) ((opus_int64)((opus_uint64)(a)<<(shi
ft))) /* shift >= 0, shift < 64 */ |
481 #define silk_LSHIFT(a, shift) silk_LSHIFT32(a, shift)
/* shift >= 0, shift < 32 */ | 505 #define silk_LSHIFT(a, shift) silk_LSHIFT32(a, shift)
/* shift >= 0, shift < 32 */ |
482 | 506 |
483 #define silk_RSHIFT8(a, shift) ((a)>>(shift))
/* shift >= 0, shift < 8 */ | 507 #define silk_RSHIFT8(a, shift) ((a)>>(shift))
/* shift >= 0, shift < 8 */ |
484 #define silk_RSHIFT16(a, shift) ((a)>>(shift))
/* shift >= 0, shift < 16 */ | 508 #define silk_RSHIFT16(a, shift) ((a)>>(shift))
/* shift >= 0, shift < 16 */ |
485 #define silk_RSHIFT32(a, shift) ((a)>>(shift))
/* shift >= 0, shift < 32 */ | 509 #define silk_RSHIFT32(a, shift) ((a)>>(shift))
/* shift >= 0, shift < 32 */ |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 #define silk_abs_int(a) (((a) ^ ((a) >> (8 * sizeof(a) - 1))
) - ((a) >> (8 * sizeof(a) - 1))) | 589 #define silk_abs_int(a) (((a) ^ ((a) >> (8 * sizeof(a) - 1))
) - ((a) >> (8 * sizeof(a) - 1))) |
566 #define silk_abs_int32(a) (((a) ^ ((a) >> 31)) - ((a) >> 31)) | 590 #define silk_abs_int32(a) (((a) ^ ((a) >> 31)) - ((a) >> 31)) |
567 #define silk_abs_int64(a) (((a) > 0) ? (a) : -(a)) | 591 #define silk_abs_int64(a) (((a) > 0) ? (a) : -(a)) |
568 | 592 |
569 #define silk_sign(a) ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )) | 593 #define silk_sign(a) ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )) |
570 | 594 |
571 /* PSEUDO-RANDOM GENERATOR
*/ | 595 /* PSEUDO-RANDOM GENERATOR
*/ |
572 /* Make sure to store the result as the seed for the next call (also in between
*/ | 596 /* Make sure to store the result as the seed for the next call (also in between
*/ |
573 /* frames), otherwise result won't be random at all. When only using some of the
*/ | 597 /* frames), otherwise result won't be random at all. When only using some of the
*/ |
574 /* bits, take the most significant bits by right-shifting.
*/ | 598 /* bits, take the most significant bits by right-shifting.
*/ |
575 #define silk_RAND(seed) (silk_MLA_ovflw(907633515, (seed), 1
96314165)) | 599 #define RAND_MULTIPLIER 196314165 |
| 600 #define RAND_INCREMENT 907633515 |
| 601 #define silk_RAND(seed) (silk_MLA_ovflw((RAND_INCREMENT), (s
eed), (RAND_MULTIPLIER))) |
576 | 602 |
577 /* Add some multiplication functions that can be easily mapped to ARM. */ | 603 /* Add some multiplication functions that can be easily mapped to ARM. */ |
578 | 604 |
579 /* silk_SMMUL: Signed top word multiply. | 605 /* silk_SMMUL: Signed top word multiply. |
580 ARMv6 2 instruction cycles. | 606 ARMv6 2 instruction cycles. |
581 ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.
(except xM)*/ | 607 ARMv3M+ 3 instruction cycles. use SMULL and ignore LSB registers.
(except xM)*/ |
582 /*#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT(silk_SMLAL
(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)), 16)*/ | 608 /*#define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT(silk_SMLAL
(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)), 16)*/ |
583 /* the following seems faster on x86 */ | 609 /* the following seems faster on x86 */ |
584 #define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL
((a32), (b32)), 32) | 610 #define silk_SMMUL(a32, b32) (opus_int32)silk_RSHIFT64(silk_SMULL
((a32), (b32)), 32) |
585 | 611 |
(...skipping 20 matching lines...) Expand all Loading... |
606 #if defined(MIPSr1_ASM) | 632 #if defined(MIPSr1_ASM) |
607 #include "mips/sigproc_fix_mipsr1.h" | 633 #include "mips/sigproc_fix_mipsr1.h" |
608 #endif | 634 #endif |
609 | 635 |
610 | 636 |
611 #ifdef __cplusplus | 637 #ifdef __cplusplus |
612 } | 638 } |
613 #endif | 639 #endif |
614 | 640 |
615 #endif /* SILK_SIGPROC_FIX_H */ | 641 #endif /* SILK_SIGPROC_FIX_H */ |
OLD | NEW |