summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libopus/celt/quant_bands.c
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2013-05-20 22:25:57 +0200
committerNils Wallménius <nils@rockbox.org>2013-08-31 08:30:51 +0200
commit580b307fd791c0997a8831bc800bba87797bfb7e (patch)
tree807846056f06fd944a750ce41217a877910ebd59 /lib/rbcodec/codecs/libopus/celt/quant_bands.c
parent74761b70acd96cecc0d35450dd56a98ad9ee7d3d (diff)
downloadrockbox-580b307fd791c0997a8831bc800bba87797bfb7e.tar.gz
rockbox-580b307fd791c0997a8831bc800bba87797bfb7e.zip
Sync opus codec to upstream git
Sync opus codec to upstream commit 02fed471a4568852d6618e041c4f2af0d7730ee2 (August 30 2013) This brings in a lot of optimizations but also makes the diff between our codec and the upstream much smaller as most of our optimizations have been upstreamed or supeceded. Speedups across the board for CELT mode files: 64kbps 128kbps H300 9.82MHz 15.48MHz c200 4.86MHz 9.63MHz fuze v1 10.32MHz 15.92MHz For the silk mode test file (16kbps) arm targets get a speedup of about 2MHz while the H300 is 7.8MHz slower, likely because it's now using the pseudostack more rather than the real stack which is in iram. Patches to get around that are upcomming. Change-Id: Ifecf963e461c51ac42e09dac1e91bc4bc3b12fa3
Diffstat (limited to 'lib/rbcodec/codecs/libopus/celt/quant_bands.c')
-rw-r--r--lib/rbcodec/codecs/libopus/celt/quant_bands.c55
1 files changed, 20 insertions, 35 deletions
diff --git a/lib/rbcodec/codecs/libopus/celt/quant_bands.c b/lib/rbcodec/codecs/libopus/celt/quant_bands.c
index 5ad5311f84..79685e17cb 100644
--- a/lib/rbcodec/codecs/libopus/celt/quant_bands.c
+++ b/lib/rbcodec/codecs/libopus/celt/quant_bands.c
@@ -27,7 +27,7 @@
27*/ 27*/
28 28
29#ifdef HAVE_CONFIG_H 29#ifdef HAVE_CONFIG_H
30#include "opus_config.h" 30#include "config.h"
31#endif 31#endif
32 32
33#include "quant_bands.h" 33#include "quant_bands.h"
@@ -40,8 +40,8 @@
40#include "rate.h" 40#include "rate.h"
41 41
42#ifdef FIXED_POINT 42#ifdef FIXED_POINT
43/* Mean energy in each band quantized in Q6 */ 43/* Mean energy in each band quantized in Q4 */
44static const signed char eMeans[25] = { 44const signed char eMeans[25] = {
45 103,100, 92, 85, 81, 45 103,100, 92, 85, 81,
46 77, 72, 70, 78, 75, 46 77, 72, 70, 78, 75,
47 73, 71, 78, 74, 69, 47 73, 71, 78, 74, 69,
@@ -49,8 +49,8 @@ static const signed char eMeans[25] = {
49 60, 60, 60, 60, 60 49 60, 60, 60, 60, 60
50}; 50};
51#else 51#else
52/* Mean energy in each band quantized in Q6 and converted back to float */ 52/* Mean energy in each band quantized in Q4 and converted back to float */
53static const opus_val16 eMeans[25] = { 53const opus_val16 eMeans[25] = {
54 6.437500f, 6.250000f, 5.750000f, 5.312500f, 5.062500f, 54 6.437500f, 6.250000f, 5.750000f, 5.312500f, 5.062500f,
55 4.812500f, 4.500000f, 4.375000f, 4.875000f, 4.687500f, 55 4.812500f, 4.500000f, 4.375000f, 4.875000f, 4.687500f,
56 4.562500f, 4.437500f, 4.875000f, 4.625000f, 4.312500f, 56 4.562500f, 4.437500f, 4.875000f, 4.625000f, 4.312500f,
@@ -157,7 +157,7 @@ static int quant_coarse_energy_impl(const CELTMode *m, int start, int end,
157 const opus_val16 *eBands, opus_val16 *oldEBands, 157 const opus_val16 *eBands, opus_val16 *oldEBands,
158 opus_int32 budget, opus_int32 tell, 158 opus_int32 budget, opus_int32 tell,
159 const unsigned char *prob_model, opus_val16 *error, ec_enc *enc, 159 const unsigned char *prob_model, opus_val16 *error, ec_enc *enc,
160 int C, int LM, int intra, opus_val16 max_decay) 160 int C, int LM, int intra, opus_val16 max_decay, int lfe)
161{ 161{
162 int i, c; 162 int i, c;
163 int badness = 0; 163 int badness = 0;
@@ -222,6 +222,8 @@ static int quant_coarse_energy_impl(const CELTMode *m, int start, int end,
222 if (bits_left < 16) 222 if (bits_left < 16)
223 qi = IMAX(-1, qi); 223 qi = IMAX(-1, qi);
224 } 224 }
225 if (lfe && i>=2)
226 qi = IMIN(qi, 0);
225 if (budget-tell >= 15) 227 if (budget-tell >= 15)
226 { 228 {
227 int pi; 229 int pi;
@@ -253,13 +255,13 @@ static int quant_coarse_energy_impl(const CELTMode *m, int start, int end,
253 prev[c] = prev[c] + SHL32(q,7) - MULT16_16(beta,PSHR32(q,8)); 255 prev[c] = prev[c] + SHL32(q,7) - MULT16_16(beta,PSHR32(q,8));
254 } while (++c < C); 256 } while (++c < C);
255 } 257 }
256 return badness; 258 return lfe ? 0 : badness;
257} 259}
258 260
259void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd, 261void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
260 const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget, 262 const opus_val16 *eBands, opus_val16 *oldEBands, opus_uint32 budget,
261 opus_val16 *error, ec_enc *enc, int C, int LM, int nbAvailableBytes, 263 opus_val16 *error, ec_enc *enc, int C, int LM, int nbAvailableBytes,
262 int force_intra, opus_val32 *delayedIntra, int two_pass, int loss_rate) 264 int force_intra, opus_val32 *delayedIntra, int two_pass, int loss_rate, int lfe)
263{ 265{
264 int intra; 266 int intra;
265 opus_val16 max_decay; 267 opus_val16 max_decay;
@@ -280,15 +282,17 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
280 if (tell+3 > budget) 282 if (tell+3 > budget)
281 two_pass = intra = 0; 283 two_pass = intra = 0;
282 284
283 /* Encode the global flags using a simple probability model 285 max_decay = QCONST16(16.f,DB_SHIFT);
284 (first symbols in the stream) */ 286 if (end-start>10)
285 287 {
286#ifdef FIXED_POINT 288#ifdef FIXED_POINT
287 max_decay = MIN32(QCONST16(16.f,DB_SHIFT), SHL32(EXTEND32(nbAvailableBytes),DB_SHIFT-3)); 289 max_decay = MIN32(max_decay, SHL32(EXTEND32(nbAvailableBytes),DB_SHIFT-3));
288#else 290#else
289 max_decay = MIN32(16.f, .125f*nbAvailableBytes); 291 max_decay = MIN32(max_decay, .125f*nbAvailableBytes);
290#endif 292#endif
291 293 }
294 if (lfe)
295 max_decay=3;
292 enc_start_state = *enc; 296 enc_start_state = *enc;
293 297
294 ALLOC(oldEBands_intra, C*m->nbEBands, opus_val16); 298 ALLOC(oldEBands_intra, C*m->nbEBands, opus_val16);
@@ -298,7 +302,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
298 if (two_pass || intra) 302 if (two_pass || intra)
299 { 303 {
300 badness1 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands_intra, budget, 304 badness1 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands_intra, budget,
301 tell, e_prob_model[LM][1], error_intra, enc, C, LM, 1, max_decay); 305 tell, e_prob_model[LM][1], error_intra, enc, C, LM, 1, max_decay, lfe);
302 } 306 }
303 307
304 if (!intra) 308 if (!intra)
@@ -325,7 +329,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
325 *enc = enc_start_state; 329 *enc = enc_start_state;
326 330
327 badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget, 331 badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget,
328 tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay); 332 tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay, lfe);
329 333
330 if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ((opus_int32)ec_tell_frac(enc))+intra_bias > tell_intra))) 334 if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ((opus_int32)ec_tell_frac(enc))+intra_bias > tell_intra)))
331 { 335 {
@@ -532,25 +536,6 @@ void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *
532 } 536 }
533} 537}
534 538
535void log2Amp(const CELTMode *m, int start, int end,
536 celt_ener *eBands, const opus_val16 *oldEBands, int C)
537{
538 int c, i;
539 c=0;
540 do {
541 for (i=0;i<start;i++)
542 eBands[i+c*m->nbEBands] = 0;
543 for (;i<end;i++)
544 {
545 opus_val16 lg = ADD16(oldEBands[i+c*m->nbEBands],
546 SHL16((opus_val16)eMeans[i],6));
547 eBands[i+c*m->nbEBands] = PSHR32(celt_exp2(lg),4);
548 }
549 for (;i<m->nbEBands;i++)
550 eBands[i+c*m->nbEBands] = 0;
551 } while (++c < C);
552}
553
554void amp2Log2(const CELTMode *m, int effEnd, int end, 539void amp2Log2(const CELTMode *m, int effEnd, int end,
555 celt_ener *bandE, opus_val16 *bandLogE, int C) 540 celt_ener *bandE, opus_val16 *bandLogE, int C)
556{ 541{