summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook/cook.c
diff options
context:
space:
mode:
authorDave Hooper <dave@beermex.com>2009-07-26 19:06:36 +0000
committerDave Hooper <dave@beermex.com>2009-07-26 19:06:36 +0000
commita8d1cfdec8f62f976ba03713da07b88bd927fce5 (patch)
treed9a5177cbab89abdd1e9ae4c0e6820a9187f36c0 /apps/codecs/libcook/cook.c
parentcece75eb42ca7e294fb423ff64c0d664cb374ec6 (diff)
downloadrockbox-a8d1cfdec8f62f976ba03713da07b88bd927fce5.tar.gz
rockbox-a8d1cfdec8f62f976ba03713da07b88bd927fce5.zip
Approx 10% speedup in cook on files tested: Remove some inner loops in favour of memcpy/memset/vect_add calls; remove multiplication from index arithmetic in loops in favour of pointer arithmetic; make use of the MULT31, MULT31_SHIFT15 and CLIP_TO_15 implementations from codelib instead of having their own implementations in cook
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22055 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libcook/cook.c')
-rw-r--r--apps/codecs/libcook/cook.c79
1 files changed, 46 insertions, 33 deletions
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index 524f5e1ff8..7ad994926e 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -328,13 +328,8 @@ static void categorize(COOKContext *q, int* quant_index_table,
328 --exp_index2[index]; 328 --exp_index2[index];
329 } 329 }
330 } 330 }
331 331 memcpy(category, exp_index2, sizeof(int) * q->total_subbands );
332 for(i=0 ; i<q->total_subbands ; i++) 332 memcpy(category_index, tmp_categorize_array+tmp_categorize_array2_idx, sizeof(int) * (q->numvector_size-1) );
333 category[i] = exp_index2[i];
334
335 for(i=0 ; i<q->numvector_size-1 ; i++)
336 category_index[i] = tmp_categorize_array[tmp_categorize_array2_idx++];
337
338} 333}
339 334
340 335
@@ -370,27 +365,38 @@ static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
370 365
371 vd = vd_tab[category]; 366 vd = vd_tab[category];
372 result = 0; 367 result = 0;
373 for(i=0 ; i<vpr_tab[category] ; i++){ 368 for(i=0 ; i<vpr_tab[category] ; i++)
369 {
374 vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3); 370 vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
375 if (q->bits_per_subpacket < get_bits_count(&q->gb)){ 371 if (q->bits_per_subpacket < get_bits_count(&q->gb))
372 {
376 vlc = 0; 373 vlc = 0;
377 result = 1; 374 result = 1;
375 memset(subband_coef_index, 0, sizeof(int)*vd);
376 memset(subband_coef_sign, 0, sizeof(int)*vd);
377 subband_coef_index+=vd;
378 subband_coef_sign+=vd;
378 } 379 }
379 for(j=vd-1 ; j>=0 ; j--){ 380 else
380 tmp = (vlc * invradix_tab[category])/0x100000; 381 {
381 subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1); 382 for(j=vd-1 ; j>=0 ; j--){
382 vlc = tmp; 383 tmp = (vlc * invradix_tab[category])/0x100000;
383 } 384 subband_coef_index[j] = vlc - tmp * (kmax_tab[category]+1);
384 for(j=0 ; j<vd ; j++){ 385 vlc = tmp;
385 if (subband_coef_index[i*vd + j]) { 386 }
386 if(get_bits_count(&q->gb) < q->bits_per_subpacket){ 387
387 subband_coef_sign[i*vd+j] = get_bits1(&q->gb); 388 for(j=0 ; j<vd ; j++)
389 {
390 if (*subband_coef_index++) {
391 if(get_bits_count(&q->gb) < q->bits_per_subpacket) {
392 *subband_coef_sign++ = get_bits1(&q->gb);
393 } else {
394 result=1;
395 *subband_coef_sign++=0;
396 }
388 } else { 397 } else {
389 result=1; 398 *subband_coef_sign++=0;
390 subband_coef_sign[i*vd+j]=0;
391 } 399 }
392 } else {
393 subband_coef_sign[i*vd+j]=0;
394 } 400 }
395 } 401 }
396 } 402 }
@@ -505,7 +511,7 @@ static void decouple_info(COOKContext *q, int* decouple_tab){
505 511
506static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1, 512static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1,
507 REAL_T* mlt_buffer2) { 513 REAL_T* mlt_buffer2) {
508 int i,j; 514 int i;
509 int decouple_tab[SUBBAND_SIZE]; 515 int decouple_tab[SUBBAND_SIZE];
510 REAL_T *decode_buffer = q->decode_buffer_0; 516 REAL_T *decode_buffer = q->decode_buffer_0;
511 int idx; 517 int idx;
@@ -520,11 +526,14 @@ static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1,
520 mono_decode(q, decode_buffer); 526 mono_decode(q, decode_buffer);
521 527
522 /* The two channels are stored interleaved in decode_buffer. */ 528 /* The two channels are stored interleaved in decode_buffer. */
523 for (i=0 ; i<q->js_subband_start ; i++) { 529 REAL_T * mlt_buffer1_end = mlt_buffer1 + (q->js_subband_start*SUBBAND_SIZE);
524 for (j=0 ; j<SUBBAND_SIZE ; j++) { 530 while(mlt_buffer1 < mlt_buffer1_end)
525 mlt_buffer1[i*20+j] = decode_buffer[i*40+j]; 531 {
526 mlt_buffer2[i*20+j] = decode_buffer[i*40+20+j]; 532 memcpy(mlt_buffer1,decode_buffer,sizeof(REAL_T)*SUBBAND_SIZE);
527 } 533 memcpy(mlt_buffer2,decode_buffer+20,sizeof(REAL_T)*SUBBAND_SIZE);
534 mlt_buffer1 += 20;
535 mlt_buffer2 += 20;
536 decode_buffer += 40;
528 } 537 }
529 538
530 /* When we reach js_subband_start (the higher frequencies) 539 /* When we reach js_subband_start (the higher frequencies)
@@ -533,11 +542,15 @@ static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1,
533 for (i=q->js_subband_start ; i<q->subbands ; i++) { 542 for (i=q->js_subband_start ; i<q->subbands ; i++) {
534 int i1 = decouple_tab[cplband[i]]; 543 int i1 = decouple_tab[cplband[i]];
535 int i2 = idx - i1 - 1; 544 int i2 = idx - i1 - 1;
536 for (j=0 ; j<SUBBAND_SIZE ; j++) { 545 mlt_buffer1_end = mlt_buffer1 + SUBBAND_SIZE;
537 REAL_T x = decode_buffer[((q->js_subband_start + i)*20)+j]; 546 while(mlt_buffer1 < mlt_buffer1_end)
538 mlt_buffer1[20*i+j] = cplscale_math(x, q->js_vlc_bits, i1); 547 {
539 mlt_buffer2[20*i+j] = cplscale_math(x, q->js_vlc_bits, i2); 548 *mlt_buffer1++ = cplscale_math(*decode_buffer, q->js_vlc_bits, i1);
549 *mlt_buffer2++ = cplscale_math(*decode_buffer++, q->js_vlc_bits, i2);
540 } 550 }
551 mlt_buffer1 += (20-SUBBAND_SIZE);
552 mlt_buffer2 += (20-SUBBAND_SIZE);
553 decode_buffer += (20-SUBBAND_SIZE);
541 } 554 }
542} 555}
543 556
@@ -581,7 +594,7 @@ decode_bytes_and_gain(COOKContext *q, const uint8_t *inbuffer,
581 * @param chan 0: left or single channel, 1: right channel 594 * @param chan 0: left or single channel, 1: right channel
582 */ 595 */
583 596
584static inline void 597static void
585mlt_compensate_output(COOKContext *q, REAL_T *decode_buffer, 598mlt_compensate_output(COOKContext *q, REAL_T *decode_buffer,
586 cook_gains *gains, REAL_T *previous_buffer, 599 cook_gains *gains, REAL_T *previous_buffer,
587 int16_t *out, int chan) 600 int16_t *out, int chan)