summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook/cook.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libcook/cook.c')
-rw-r--r--apps/codecs/libcook/cook.c91
1 files changed, 56 insertions, 35 deletions
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index e3a919ddec..8bb3b5a113 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -70,11 +70,11 @@ const uint8_t ff_log2_tab[256]={
70#define SUBBAND_SIZE 20 70#define SUBBAND_SIZE 20
71#define MAX_SUBPACKETS 5 71#define MAX_SUBPACKETS 5
72//#define COOKDEBUG 72//#define COOKDEBUG
73//#define DUMP_RAW_FRAMES
74#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args) 73#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args)
75 74
76static float pow2tab[127]; 75static float pow2tab[127];
77static float rootpow2tab[127]; 76static float rootpow2tab[127];
77#include "cook_fixpoint.h"
78 78
79/* debug functions */ 79/* debug functions */
80 80
@@ -189,7 +189,7 @@ static const float *maybe_reformat_buffer32 (COOKContext *q, const float *ptr, i
189static av_cold void init_cplscales_table (COOKContext *q) { 189static av_cold void init_cplscales_table (COOKContext *q) {
190 int i; 190 int i;
191 for (i=0;i<5;i++) 191 for (i=0;i<5;i++)
192 q->cplscales[i] = maybe_reformat_buffer32 (q, cplscales[i], (1<<(i+2))-1); 192 q->cplscales[i] = maybe_reformat_buffer32 (q, q->cplscales[i], (1<<(i+2))-1);
193} 193}
194 194
195/*************** init functions end ***********/ 195/*************** init functions end ***********/
@@ -454,6 +454,7 @@ static inline void expand_category(COOKContext *q, int* category,
454 * @param mlt_p pointer into the mlt buffer 454 * @param mlt_p pointer into the mlt buffer
455 */ 455 */
456 456
457#if 0
457static void scalar_dequant_float(COOKContext *q, int index, int quant_index, 458static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
458 int* subband_coef_index, int* subband_coef_sign, 459 int* subband_coef_index, int* subband_coef_sign,
459 float* mlt_p){ 460 float* mlt_p){
@@ -472,6 +473,7 @@ static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
472 mlt_p[i] = f1 * rootpow2tab[quant_index+63]; 473 mlt_p[i] = f1 * rootpow2tab[quant_index+63];
473 } 474 }
474} 475}
476#endif
475/** 477/**
476 * Unpack the subband_coef_index and subband_coef_sign vectors. 478 * Unpack the subband_coef_index and subband_coef_sign vectors.
477 * 479 *
@@ -527,7 +529,7 @@ static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
527 529
528 530
529static void decode_vectors(COOKContext* q, int* category, 531static void decode_vectors(COOKContext* q, int* category,
530 int *quant_index_table, float* mlt_buffer){ 532 int *quant_index_table, REAL_T* mlt_buffer){
531 /* A zero in this table means that the subband coefficient is 533 /* A zero in this table means that the subband coefficient is
532 random noise coded. */ 534 random noise coded. */
533 int subband_coef_index[SUBBAND_SIZE]; 535 int subband_coef_index[SUBBAND_SIZE];
@@ -567,7 +569,7 @@ static void decode_vectors(COOKContext* q, int* category,
567 * @param mlt_buffer pointer to mlt coefficients 569 * @param mlt_buffer pointer to mlt coefficients
568 */ 570 */
569 571
570static void mono_decode(COOKContext *q, float* mlt_buffer) { 572static void mono_decode(COOKContext *q, REAL_T* mlt_buffer) {
571 573
572 int category_index[128]; 574 int category_index[128];
573 int quant_index_table[102]; 575 int quant_index_table[102];
@@ -593,6 +595,7 @@ static void mono_decode(COOKContext *q, float* mlt_buffer) {
593 * @param gain_index_next index for the next block multiplier 595 * @param gain_index_next index for the next block multiplier
594 */ 596 */
595 597
598#if 0
596static void interpolate_float(COOKContext *q, float* buffer, 599static void interpolate_float(COOKContext *q, float* buffer,
597 int gain_index, int gain_index_next){ 600 int gain_index, int gain_index_next){
598 int i; 601 int i;
@@ -613,6 +616,7 @@ static void interpolate_float(COOKContext *q, float* buffer,
613 return; 616 return;
614 } 617 }
615} 618}
619#endif
616 620
617/** 621/**
618 * Apply transform window, overlap buffers. 622 * Apply transform window, overlap buffers.
@@ -652,12 +656,12 @@ static void imlt_window_float (COOKContext *q, float *buffer1,
652 * @param gains_ptr current and previous gains 656 * @param gains_ptr current and previous gains
653 * @param previous_buffer pointer to the previous buffer to be used for overlapping 657 * @param previous_buffer pointer to the previous buffer to be used for overlapping
654 */ 658 */
655 659#if 0
656static void imlt_gain(COOKContext *q, float *inbuffer, 660static void imlt_gain(COOKContext *q, REAL_T *inbuffer,
657 cook_gains *gains_ptr, float* previous_buffer) 661 cook_gains *gains_ptr, REAL_T* previous_buffer)
658{ 662{
659 float *buffer0 = q->mono_mdct_output; 663 REAL_T *buffer0 = q->mono_mdct_output;
660 float *buffer1 = q->mono_mdct_output + q->samples_per_channel; 664 REAL_T *buffer1 = q->mono_mdct_output + q->samples_per_channel;
661 int i; 665 int i;
662 666
663 /* Inverse modified discrete cosine transform */ 667 /* Inverse modified discrete cosine transform */
@@ -676,7 +680,7 @@ static void imlt_gain(COOKContext *q, float *inbuffer,
676 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel); 680 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel);
677} 681}
678 682
679 683#endif
680/** 684/**
681 * function for getting the jointstereo coupling information 685 * function for getting the jointstereo coupling information
682 * 686 *
@@ -720,9 +724,9 @@ static void decouple_info(COOKContext *q, int* decouple_tab){
720 */ 724 */
721static void decouple_float (COOKContext *q, 725static void decouple_float (COOKContext *q,
722 int subband, 726 int subband,
723 float f1, float f2, 727 REAL_T f1, REAL_T f2,
724 float *decode_buffer, 728 REAL_T *decode_buffer,
725 float *mlt_buffer1, float *mlt_buffer2) 729 REAL_T *mlt_buffer1, REAL_T *mlt_buffer2)
726{ 730{
727 int j, tmp_idx; 731 int j, tmp_idx;
728 for (j=0 ; j<SUBBAND_SIZE ; j++) { 732 for (j=0 ; j<SUBBAND_SIZE ; j++) {
@@ -740,21 +744,19 @@ static void decouple_float (COOKContext *q,
740 * @param mlt_buffer2 pointer to right channel mlt coefficients 744 * @param mlt_buffer2 pointer to right channel mlt coefficients
741 */ 745 */
742 746
743static void joint_decode(COOKContext *q, float* mlt_buffer1, 747static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1,
744 float* mlt_buffer2) { 748 REAL_T* mlt_buffer2) {
745 int i,j; 749 int i,j;
746 int decouple_tab[SUBBAND_SIZE]; 750 int decouple_tab[SUBBAND_SIZE];
747 float *decode_buffer = q->decode_buffer_0; 751 REAL_T *decode_buffer = q->decode_buffer_0;
748 int idx, cpl_tmp; 752 int idx;
749 float f1,f2;
750 const float* cplscale;
751 753
752 memset(decouple_tab, 0, sizeof(decouple_tab)); 754 memset(decouple_tab, 0, sizeof(decouple_tab));
753 memset(decode_buffer, 0, sizeof(decode_buffer)); 755 memset(decode_buffer, 0, sizeof(decode_buffer));
754 756
755 /* Make sure the buffers are zeroed out. */ 757 /* Make sure the buffers are zeroed out. */
756 memset(mlt_buffer1,0, 1024*sizeof(float)); 758 memset(mlt_buffer1,0, 1024*sizeof(REAL_T));
757 memset(mlt_buffer2,0, 1024*sizeof(float)); 759 memset(mlt_buffer2,0, 1024*sizeof(REAL_T));
758 decouple_info(q, decouple_tab); 760 decouple_info(q, decouple_tab);
759 mono_decode(q, decode_buffer); 761 mono_decode(q, decode_buffer);
760 762
@@ -770,13 +772,13 @@ static void joint_decode(COOKContext *q, float* mlt_buffer1,
770 the coefficients are stored in a coupling scheme. */ 772 the coefficients are stored in a coupling scheme. */
771 idx = (1 << q->js_vlc_bits) - 1; 773 idx = (1 << q->js_vlc_bits) - 1;
772 for (i=q->js_subband_start ; i<q->subbands ; i++) { 774 for (i=q->js_subband_start ; i<q->subbands ; i++) {
773 cpl_tmp = cplband[i]; 775 int i1 = decouple_tab[cplband[i]];
774 idx -=decouple_tab[cpl_tmp]; 776 int i2 = idx - i1 - 1;
775 cplscale = q->cplscales[q->js_vlc_bits-2]; //choose decoupler table 777 for (j=0 ; j<SUBBAND_SIZE ; j++) {
776 f1 = cplscale[decouple_tab[cpl_tmp]]; 778 REAL_T x = decode_buffer[((q->js_subband_start + i)*20)+j];
777 f2 = cplscale[idx-1]; 779 mlt_buffer1[20*i+j] = cplscale_math(x, q->js_vlc_bits, i1);
778 q->decouple (q, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); 780 mlt_buffer2[20*i+j] = cplscale_math(x, q->js_vlc_bits, i2);
779 idx = (1 << q->js_vlc_bits) - 1; 781 }
780 } 782 }
781} 783}
782 784
@@ -818,7 +820,7 @@ static void
818saturate_output_float (COOKContext *q, int chan, int16_t *out) 820saturate_output_float (COOKContext *q, int chan, int16_t *out)
819{ 821{
820 int j; 822 int j;
821 float *output = q->mono_mdct_output + q->samples_per_channel; 823 float *output = (float*)q->mono_mdct_output + q->samples_per_channel;
822 /* Clip and convert floats to 16 bits. 824 /* Clip and convert floats to 16 bits.
823 */ 825 */
824 for (j = 0; j < q->samples_per_channel; j++) { 826 for (j = 0; j < q->samples_per_channel; j++) {
@@ -841,12 +843,29 @@ saturate_output_float (COOKContext *q, int chan, int16_t *out)
841 */ 843 */
842 844
843static inline void 845static inline void
844mlt_compensate_output(COOKContext *q, float *decode_buffer, 846mlt_compensate_output(COOKContext *q, REAL_T *decode_buffer,
845 cook_gains *gains, float *previous_buffer, 847 cook_gains *gains, REAL_T *previous_buffer,
846 int16_t *out, int chan) 848 int16_t *out, int chan)
847{ 849{
848 imlt_gain(q, decode_buffer, gains, previous_buffer); 850 REAL_T *buffer = q->mono_mdct_output;
849 q->saturate_output (q, chan, out); 851 int i;
852 imlt_math(q, decode_buffer);
853
854 /* Overlap with the previous block. */
855 overlap_math(q, gains->previous[0], previous_buffer);
856
857 /* Apply gain profile */
858 for (i = 0; i < 8; i++) {
859 if (gains->now[i] || gains->now[i + 1])
860 interpolate_math(q, &buffer[q->samples_per_channel/8 * i],
861 gains->now[i], gains->now[i + 1]);
862 }
863
864 /* Save away the current to be previous block. */
865 memcpy(previous_buffer, buffer+q->samples_per_channel,
866 sizeof(REAL_T)*q->samples_per_channel);
867
868 output_math(q, out, chan);
850} 869}
851 870
852 871
@@ -946,6 +965,7 @@ static void dump_cook_context(COOKContext *q)
946} 965}
947#endif 966#endif
948 967
968#if 0
949static av_cold int cook_count_channels(unsigned int mask){ 969static av_cold int cook_count_channels(unsigned int mask){
950 int i; 970 int i;
951 int channels = 0; 971 int channels = 0;
@@ -955,6 +975,7 @@ static av_cold int cook_count_channels(unsigned int mask){
955 } 975 }
956 return channels; 976 return channels;
957} 977}
978#endif
958 979
959/** 980/**
960 * Cook initialization 981 * Cook initialization
@@ -1077,10 +1098,10 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
1077 1098
1078 /* Initialize COOK signal arithmetic handling */ 1099 /* Initialize COOK signal arithmetic handling */
1079 if (1) { 1100 if (1) {
1080 q->scalar_dequant = scalar_dequant_float; 1101 q->scalar_dequant = scalar_dequant_math;
1081 q->decouple = decouple_float; 1102 q->decouple = decouple_float;
1082 q->imlt_window = imlt_window_float; 1103 q->imlt_window = imlt_window_float;
1083 q->interpolate = interpolate_float; 1104 q->interpolate = interpolate_math;
1084 q->saturate_output = saturate_output_float; 1105 q->saturate_output = saturate_output_float;
1085 } 1106 }
1086 1107