OLD | NEW |
1 /* Copyright (c) 2007-2008 CSIRO | 1 /* Copyright (c) 2007-2008 CSIRO |
2 Copyright (c) 2007-2009 Xiph.Org Foundation | 2 Copyright (c) 2007-2009 Xiph.Org Foundation |
3 Copyright (c) 2008-2009 Gregory Maxwell | 3 Copyright (c) 2008-2009 Gregory Maxwell |
4 Written by Jean-Marc Valin and Gregory Maxwell */ | 4 Written by Jean-Marc Valin and Gregory Maxwell */ |
5 /* | 5 /* |
6 Redistribution and use in source and binary forms, with or without | 6 Redistribution and use in source and binary forms, with or without |
7 modification, are permitted provided that the following conditions | 7 modification, are permitted provided that the following conditions |
8 are met: | 8 are met: |
9 | 9 |
10 - Redistributions of source code must retain the above copyright | 10 - Redistributions of source code must retain the above copyright |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 { | 207 { |
208 int j, band_end; | 208 int j, band_end; |
209 opus_val16 g; | 209 opus_val16 g; |
210 opus_val16 lg; | 210 opus_val16 lg; |
211 #ifdef FIXED_POINT | 211 #ifdef FIXED_POINT |
212 int shift; | 212 int shift; |
213 #endif | 213 #endif |
214 j=M*eBands[i]; | 214 j=M*eBands[i]; |
215 band_end = M*eBands[i+1]; | 215 band_end = M*eBands[i+1]; |
216 lg = ADD16(bandLogE[i+c*m->nbEBands], SHL16((opus_val16)eMeans[i],6)); | 216 lg = ADD16(bandLogE[i+c*m->nbEBands], SHL16((opus_val16)eMeans[i],6)); |
217 #ifdef FIXED_POINT | 217 #ifndef FIXED_POINT |
| 218 g = celt_exp2(lg); |
| 219 #else |
218 /* Handle the integer part of the log energy */ | 220 /* Handle the integer part of the log energy */ |
219 shift = 16-(lg>>DB_SHIFT); | 221 shift = 16-(lg>>DB_SHIFT); |
220 if (shift>31) | 222 if (shift>31) |
221 { | 223 { |
222 shift=0; | 224 shift=0; |
223 g=0; | 225 g=0; |
224 } else { | 226 } else { |
225 /* Handle the fractional part. */ | 227 /* Handle the fractional part. */ |
226 g = celt_exp2_frac(lg&((1<<DB_SHIFT)-1)); | 228 g = celt_exp2_frac(lg&((1<<DB_SHIFT)-1)); |
227 } | 229 } |
228 #else | 230 /* Handle extreme gains with negative shift. */ |
229 g = celt_exp2(lg); | 231 if (shift<0) |
| 232 { |
| 233 /* For shift < -2 we'd be likely to overflow, so we're capping |
| 234 the gain here. This shouldn't happen unless the bitstream is |
| 235 already corrupted. */ |
| 236 if (shift < -2) |
| 237 { |
| 238 g = 32767; |
| 239 shift = -2; |
| 240 } |
| 241 do { |
| 242 *f++ = SHL32(MULT16_16(*x++, g), -shift); |
| 243 } while (++j<band_end); |
| 244 } else |
230 #endif | 245 #endif |
| 246 /* Be careful of the fixed-point "else" just above when changing this c
ode */ |
231 do { | 247 do { |
232 *f++ = SHR32(MULT16_16(*x++, g), shift); | 248 *f++ = SHR32(MULT16_16(*x++, g), shift); |
233 } while (++j<band_end); | 249 } while (++j<band_end); |
234 } | 250 } |
235 celt_assert(start <= end); | 251 celt_assert(start <= end); |
236 for (i=M*eBands[end];i<N;i++) | 252 for (i=M*eBands[end];i<N;i++) |
237 *f++ = 0; | 253 *f++ = 0; |
238 } while (++c<C); | 254 } while (++c<C); |
239 } | 255 } |
240 | 256 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 else if (*tapset_decision==0) | 501 else if (*tapset_decision==0) |
486 hf_sum -= 4; | 502 hf_sum -= 4; |
487 if (hf_sum > 22) | 503 if (hf_sum > 22) |
488 *tapset_decision=2; | 504 *tapset_decision=2; |
489 else if (hf_sum > 18) | 505 else if (hf_sum > 18) |
490 *tapset_decision=1; | 506 *tapset_decision=1; |
491 else | 507 else |
492 *tapset_decision=0; | 508 *tapset_decision=0; |
493 } | 509 } |
494 /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/ | 510 /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/ |
495 celt_assert(nbBands>0); /*M*(eBands[end]-eBands[end-1]) <= 8 assures this*/ | 511 celt_assert(nbBands>0); /* end has to be non-zero */ |
496 sum /= nbBands; | 512 sum /= nbBands; |
497 /* Recursive averaging */ | 513 /* Recursive averaging */ |
498 sum = (sum+*average)>>1; | 514 sum = (sum+*average)>>1; |
499 *average = sum; | 515 *average = sum; |
500 /* Hysteresis */ | 516 /* Hysteresis */ |
501 sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2; | 517 sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2; |
502 if (sum < 80) | 518 if (sum < 80) |
503 { | 519 { |
504 decision = SPREAD_AGGRESSIVE; | 520 decision = SPREAD_AGGRESSIVE; |
505 } else if (sum < 256) | 521 } else if (sum < 256) |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 split in 8 parts. */ | 878 split in 8 parts. */ |
863 static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, | 879 static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, |
864 int N, int b, int B, celt_norm *lowband, | 880 int N, int b, int B, celt_norm *lowband, |
865 int LM, | 881 int LM, |
866 opus_val16 gain, int fill) | 882 opus_val16 gain, int fill) |
867 { | 883 { |
868 const unsigned char *cache; | 884 const unsigned char *cache; |
869 int q; | 885 int q; |
870 int curr_bits; | 886 int curr_bits; |
871 int imid=0, iside=0; | 887 int imid=0, iside=0; |
872 int N_B=N; | |
873 int B0=B; | 888 int B0=B; |
874 opus_val16 mid=0, side=0; | 889 opus_val16 mid=0, side=0; |
875 unsigned cm=0; | 890 unsigned cm=0; |
876 #ifdef RESYNTH | 891 #ifdef RESYNTH |
877 int resynth = 1; | 892 int resynth = 1; |
878 #else | 893 #else |
879 int resynth = !ctx->encode; | 894 int resynth = !ctx->encode; |
880 #endif | 895 #endif |
881 celt_norm *Y=NULL; | 896 celt_norm *Y=NULL; |
882 int encode; | 897 int encode; |
883 const CELTMode *m; | 898 const CELTMode *m; |
884 int i; | 899 int i; |
885 int spread; | 900 int spread; |
886 ec_ctx *ec; | 901 ec_ctx *ec; |
887 | 902 |
888 encode = ctx->encode; | 903 encode = ctx->encode; |
889 m = ctx->m; | 904 m = ctx->m; |
890 i = ctx->i; | 905 i = ctx->i; |
891 spread = ctx->spread; | 906 spread = ctx->spread; |
892 ec = ctx->ec; | 907 ec = ctx->ec; |
893 | 908 |
894 N_B /= B; | |
895 | |
896 /* If we need 1.5 more bit than we can produce, split the band in two. */ | 909 /* If we need 1.5 more bit than we can produce, split the band in two. */ |
897 cache = m->cache.bits + m->cache.index[(LM+1)*m->nbEBands+i]; | 910 cache = m->cache.bits + m->cache.index[(LM+1)*m->nbEBands+i]; |
898 if (LM != -1 && b > cache[cache[0]]+12 && N>2) | 911 if (LM != -1 && b > cache[cache[0]]+12 && N>2) |
899 { | 912 { |
900 int mbits, sbits, delta; | 913 int mbits, sbits, delta; |
901 int itheta; | 914 int itheta; |
902 int qalloc; | 915 int qalloc; |
903 struct split_ctx sctx; | 916 struct split_ctx sctx; |
904 celt_norm *next_lowband2=NULL; | 917 celt_norm *next_lowband2=NULL; |
905 opus_int32 rebalance; | 918 opus_int32 rebalance; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 int k; | 1078 int k; |
1066 int encode; | 1079 int encode; |
1067 int tf_change; | 1080 int tf_change; |
1068 | 1081 |
1069 encode = ctx->encode; | 1082 encode = ctx->encode; |
1070 tf_change = ctx->tf_change; | 1083 tf_change = ctx->tf_change; |
1071 | 1084 |
1072 longBlocks = B0==1; | 1085 longBlocks = B0==1; |
1073 | 1086 |
1074 N_B /= B; | 1087 N_B /= B; |
1075 N_B0 = N_B; | |
1076 | 1088 |
1077 /* Special case for one sample */ | 1089 /* Special case for one sample */ |
1078 if (N==1) | 1090 if (N==1) |
1079 { | 1091 { |
1080 return quant_band_n1(ctx, X, NULL, b, lowband_out); | 1092 return quant_band_n1(ctx, X, NULL, b, lowband_out); |
1081 } | 1093 } |
1082 | 1094 |
1083 if (tf_change>0) | 1095 if (tf_change>0) |
1084 recombine = tf_change; | 1096 recombine = tf_change; |
1085 /* Band recombining to increase frequency resolution */ | 1097 /* Band recombining to increase frequency resolution */ |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 balance += pulses[i] + tell; | 1509 balance += pulses[i] + tell; |
1498 | 1510 |
1499 /* Update the folding position only as long as we have 1 bit/sample depth.
*/ | 1511 /* Update the folding position only as long as we have 1 bit/sample depth.
*/ |
1500 update_lowband = b>(N<<BITRES); | 1512 update_lowband = b>(N<<BITRES); |
1501 } | 1513 } |
1502 *seed = ctx.seed; | 1514 *seed = ctx.seed; |
1503 | 1515 |
1504 RESTORE_STACK; | 1516 RESTORE_STACK; |
1505 } | 1517 } |
1506 | 1518 |
OLD | NEW |