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.c267
1 files changed, 0 insertions, 267 deletions
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index 8bb3b5a113..bd72179cbd 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -71,23 +71,11 @@ const uint8_t ff_log2_tab[256]={
71#define MAX_SUBPACKETS 5 71#define MAX_SUBPACKETS 5
72//#define COOKDEBUG 72//#define COOKDEBUG
73#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)
74
75static float pow2tab[127];
76static float rootpow2tab[127];
77#include "cook_fixpoint.h" 74#include "cook_fixpoint.h"
78 75
79/* debug functions */ 76/* debug functions */
80 77
81#ifdef COOKDEBUG 78#ifdef COOKDEBUG
82static void dump_float_table(float* table, int size, int delimiter) {
83 int i=0;
84 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
85 for (i=0 ; i<size ; i++) {
86 av_log(NULL, AV_LOG_ERROR, "%5.1f, ", table[i]);
87 if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
88 }
89}
90
91static void dump_int_table(int* table, int size, int delimiter) { 79static void dump_int_table(int* table, int size, int delimiter) {
92 int i=0; 80 int i=0;
93 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i); 81 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
@@ -109,27 +97,6 @@ static void dump_short_table(short* table, int size, int delimiter) {
109#endif 97#endif
110 98
111/*************** init functions ***************/ 99/*************** init functions ***************/
112
113/* table generator */
114static av_cold void init_pow2table(void){
115 int i;
116 for (i=-63 ; i<64 ; i++){
117 pow2tab[63+i]= pow(2, i);
118 rootpow2tab[63+i]=sqrt(pow(2, i));
119 }
120}
121
122/* table generator */
123static av_cold void init_gain_table(COOKContext *q) {
124 int i;
125 q->gain_size_factor = q->samples_per_channel/8;
126 for (i=0 ; i<23 ; i++) {
127 q->gain_table[i] = pow(pow2tab[i+52] ,
128 (1.0/(double)q->gain_size_factor));
129 }
130}
131
132
133static av_cold int init_cook_vlc_tables(COOKContext *q) { 100static av_cold int init_cook_vlc_tables(COOKContext *q) {
134 int i, result; 101 int i, result;
135 102
@@ -156,42 +123,6 @@ static av_cold int init_cook_vlc_tables(COOKContext *q) {
156 av_log(NULL,AV_LOG_ERROR,"VLC tables initialized. Result = %d\n",result); 123 av_log(NULL,AV_LOG_ERROR,"VLC tables initialized. Result = %d\n",result);
157 return result; 124 return result;
158} 125}
159
160static av_cold int init_cook_mlt(COOKContext *q) {
161 int j;
162 int mlt_size = q->samples_per_channel;
163
164 if ((q->mlt_window = av_malloc(sizeof(float)*mlt_size)) == 0)
165 return -1;
166
167 /* Initialize the MLT window: simple sine window. */
168 ff_sine_window_init(q->mlt_window, mlt_size);
169 for(j=0 ; j<mlt_size ; j++)
170 q->mlt_window[j] *= sqrt(2.0 / q->samples_per_channel);
171
172 /* Initialize the MDCT. */
173 if (ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size)+1, 1)) {
174 av_free(q->mlt_window);
175 return -1;
176 }
177 av_log(NULL,AV_LOG_ERROR,"MDCT initialized, order = %d. mlt_window = %d\n",
178 av_log2(mlt_size)+1,sizeof(q->mlt_window)*mlt_size);
179
180 return 0;
181}
182
183static const float *maybe_reformat_buffer32 (COOKContext *q, const float *ptr, int n)
184{
185 if (1)
186 return ptr;
187}
188
189static av_cold void init_cplscales_table (COOKContext *q) {
190 int i;
191 for (i=0;i<5;i++)
192 q->cplscales[i] = maybe_reformat_buffer32 (q, q->cplscales[i], (1<<(i+2))-1);
193}
194
195/*************** init functions end ***********/ 126/*************** init functions end ***********/
196 127
197/** 128/**
@@ -249,12 +180,8 @@ av_cold int cook_decode_close(COOKContext *q)
249 av_log(NULL,AV_LOG_ERROR, "Deallocating memory.\n"); 180 av_log(NULL,AV_LOG_ERROR, "Deallocating memory.\n");
250 181
251 /* Free allocated memory buffers. */ 182 /* Free allocated memory buffers. */
252 av_free(q->mlt_window);
253 av_free(q->decoded_bytes_buffer); 183 av_free(q->decoded_bytes_buffer);
254 184
255 /* Free the transform. */
256 ff_mdct_end(&q->mdct_ctx);
257
258 /* Free the VLC tables. */ 185 /* Free the VLC tables. */
259 for (i=0 ; i<13 ; i++) { 186 for (i=0 ; i<13 ; i++) {
260 free_vlc(&q->envelope_quant_index[i]); 187 free_vlc(&q->envelope_quant_index[i]);
@@ -444,37 +371,6 @@ static inline void expand_category(COOKContext *q, int* category,
444} 371}
445 372
446/** 373/**
447 * The real requantization of the mltcoefs
448 *
449 * @param q pointer to the COOKContext
450 * @param index index
451 * @param quant_index quantisation index
452 * @param subband_coef_index array of indexes to quant_centroid_tab
453 * @param subband_coef_sign signs of coefficients
454 * @param mlt_p pointer into the mlt buffer
455 */
456
457#if 0
458static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
459 int* subband_coef_index, int* subband_coef_sign,
460 float* mlt_p){
461 int i;
462 float f1;
463
464 for(i=0 ; i<SUBBAND_SIZE ; i++) {
465 if (subband_coef_index[i]) {
466 f1 = quant_centroid_tab[index][subband_coef_index[i]];
467 if (subband_coef_sign[i]) f1 = -f1;
468 } else {
469 /* noise coding if subband_coef_index[i] == 0 */
470 f1 = dither_tab[index];
471 if (av_lfg_get(&q->random_state) < 0x80000000) f1 = -f1;
472 }
473 mlt_p[i] = f1 * rootpow2tab[quant_index+63];
474 }
475}
476#endif
477/**
478 * Unpack the subband_coef_index and subband_coef_sign vectors. 374 * Unpack the subband_coef_index and subband_coef_sign vectors.
479 * 375 *
480 * @param q pointer to the COOKContext 376 * @param q pointer to the COOKContext
@@ -585,102 +481,6 @@ static void mono_decode(COOKContext *q, REAL_T* mlt_buffer) {
585 decode_vectors(q, category, quant_index_table, mlt_buffer); 481 decode_vectors(q, category, quant_index_table, mlt_buffer);
586} 482}
587 483
588
589/**
590 * the actual requantization of the timedomain samples
591 *
592 * @param q pointer to the COOKContext
593 * @param buffer pointer to the timedomain buffer
594 * @param gain_index index for the block multiplier
595 * @param gain_index_next index for the next block multiplier
596 */
597
598#if 0
599static void interpolate_float(COOKContext *q, float* buffer,
600 int gain_index, int gain_index_next){
601 int i;
602 float fc1, fc2;
603 fc1 = pow2tab[gain_index+63];
604
605 if(gain_index == gain_index_next){ //static gain
606 for(i=0 ; i<q->gain_size_factor ; i++){
607 buffer[i]*=fc1;
608 }
609 return;
610 } else { //smooth gain
611 fc2 = q->gain_table[11 + (gain_index_next-gain_index)];
612 for(i=0 ; i<q->gain_size_factor ; i++){
613 buffer[i]*=fc1;
614 fc1*=fc2;
615 }
616 return;
617 }
618}
619#endif
620
621/**
622 * Apply transform window, overlap buffers.
623 *
624 * @param q pointer to the COOKContext
625 * @param inbuffer pointer to the mltcoefficients
626 * @param gains_ptr current and previous gains
627 * @param previous_buffer pointer to the previous buffer to be used for overlapping
628 */
629
630static void imlt_window_float (COOKContext *q, float *buffer1,
631 cook_gains *gains_ptr, float *previous_buffer)
632{
633 const float fc = pow2tab[gains_ptr->previous[0] + 63];
634 int i;
635 /* The weird thing here, is that the two halves of the time domain
636 * buffer are swapped. Also, the newest data, that we save away for
637 * next frame, has the wrong sign. Hence the subtraction below.
638 * Almost sounds like a complex conjugate/reverse data/FFT effect.
639 */
640
641 /* Apply window and overlap */
642 for(i = 0; i < q->samples_per_channel; i++){
643 buffer1[i] = buffer1[i] * fc * q->mlt_window[i] -
644 previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i];
645 }
646}
647
648/**
649 * The modulated lapped transform, this takes transform coefficients
650 * and transforms them into timedomain samples.
651 * Apply transform window, overlap buffers, apply gain profile
652 * and buffer management.
653 *
654 * @param q pointer to the COOKContext
655 * @param inbuffer pointer to the mltcoefficients
656 * @param gains_ptr current and previous gains
657 * @param previous_buffer pointer to the previous buffer to be used for overlapping
658 */
659#if 0
660static void imlt_gain(COOKContext *q, REAL_T *inbuffer,
661 cook_gains *gains_ptr, REAL_T* previous_buffer)
662{
663 REAL_T *buffer0 = q->mono_mdct_output;
664 REAL_T *buffer1 = q->mono_mdct_output + q->samples_per_channel;
665 int i;
666
667 /* Inverse modified discrete cosine transform */
668 ff_imdct_calc(&q->mdct_ctx, q->mono_mdct_output, inbuffer);
669
670 q->imlt_window (q, buffer1, gains_ptr, previous_buffer);
671
672 /* Apply gain profile */
673 for (i = 0; i < 8; i++) {
674 if (gains_ptr->now[i] || gains_ptr->now[i + 1])
675 q->interpolate(q, &buffer1[q->gain_size_factor * i],
676 gains_ptr->now[i], gains_ptr->now[i + 1]);
677 }
678
679 /* Save away the current to be previous block. */
680 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel);
681}
682
683#endif
684/** 484/**
685 * function for getting the jointstereo coupling information 485 * function for getting the jointstereo coupling information
686 * 486 *
@@ -711,31 +511,6 @@ static void decouple_info(COOKContext *q, int* decouple_tab){
711 return; 511 return;
712} 512}
713 513
714/*
715 * function decouples a pair of signals from a single signal via multiplication.
716 *
717 * @param q pointer to the COOKContext
718 * @param subband index of the current subband
719 * @param f1 multiplier for channel 1 extraction
720 * @param f2 multiplier for channel 2 extraction
721 * @param decode_buffer input buffer
722 * @param mlt_buffer1 pointer to left channel mlt coefficients
723 * @param mlt_buffer2 pointer to right channel mlt coefficients
724 */
725static void decouple_float (COOKContext *q,
726 int subband,
727 REAL_T f1, REAL_T f2,
728 REAL_T *decode_buffer,
729 REAL_T *mlt_buffer1, REAL_T *mlt_buffer2)
730{
731 int j, tmp_idx;
732 for (j=0 ; j<SUBBAND_SIZE ; j++) {
733 tmp_idx = ((q->js_subband_start + subband)*SUBBAND_SIZE)+j;
734 mlt_buffer1[SUBBAND_SIZE*subband + j] = f1 * decode_buffer[tmp_idx];
735 mlt_buffer2[SUBBAND_SIZE*subband + j] = f2 * decode_buffer[tmp_idx];
736 }
737}
738
739/** 514/**
740 * function for decoding joint stereo data 515 * function for decoding joint stereo data
741 * 516 *
@@ -809,26 +584,6 @@ decode_bytes_and_gain(COOKContext *q, const uint8_t *inbuffer,
809 FFSWAP(int *, gains_ptr->now, gains_ptr->previous); 584 FFSWAP(int *, gains_ptr->now, gains_ptr->previous);
810} 585}
811 586
812 /**
813 * Saturate the output signal to signed 16bit integers.
814 *
815 * @param q pointer to the COOKContext
816 * @param chan channel to saturate
817 * @param out pointer to the output vector
818 */
819static void
820saturate_output_float (COOKContext *q, int chan, int16_t *out)
821{
822 int j;
823 float *output = (float*)q->mono_mdct_output + q->samples_per_channel;
824 /* Clip and convert floats to 16 bits.
825 */
826 for (j = 0; j < q->samples_per_channel; j++) {
827 out[chan + q->nb_channels * j] =
828 av_clip_int16(lrintf(output[j]));
829 }
830}
831
832/** 587/**
833 * Final part of subpacket decoding: 588 * Final part of subpacket decoding:
834 * Apply modulated lapped transform, gain compensation, 589 * Apply modulated lapped transform, gain compensation,
@@ -965,18 +720,6 @@ static void dump_cook_context(COOKContext *q)
965} 720}
966#endif 721#endif
967 722
968#if 0
969static av_cold int cook_count_channels(unsigned int mask){
970 int i;
971 int channels = 0;
972 for(i = 0;i<32;i++){
973 if(mask & (1<<i))
974 ++channels;
975 }
976 return channels;
977}
978#endif
979
980/** 723/**
981 * Cook initialization 724 * Cook initialization
982 */ 725 */
@@ -1057,10 +800,6 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
1057 q->numvector_size = (1 << q->log2_numvector_size); 800 q->numvector_size = (1 << q->log2_numvector_size);
1058 801
1059 /* Generate tables */ 802 /* Generate tables */
1060 init_pow2table();
1061 init_gain_table(q);
1062 init_cplscales_table(q);
1063
1064 if (init_cook_vlc_tables(q) != 0) 803 if (init_cook_vlc_tables(q) != 0)
1065 return -1; 804 return -1;
1066 805
@@ -1092,17 +831,11 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
1092 q->gains2.now = q->gain_3; 831 q->gains2.now = q->gain_3;
1093 q->gains2.previous = q->gain_4; 832 q->gains2.previous = q->gain_4;
1094 833
1095 /* Initialize transform. */
1096 if ( init_cook_mlt(q) != 0 )
1097 return -1;
1098 834
1099 /* Initialize COOK signal arithmetic handling */ 835 /* Initialize COOK signal arithmetic handling */
1100 if (1) { 836 if (1) {
1101 q->scalar_dequant = scalar_dequant_math; 837 q->scalar_dequant = scalar_dequant_math;
1102 q->decouple = decouple_float;
1103 q->imlt_window = imlt_window_float;
1104 q->interpolate = interpolate_math; 838 q->interpolate = interpolate_math;
1105 q->saturate_output = saturate_output_float;
1106 } 839 }
1107 840
1108 /* Try to catch some obviously faulty streams, othervise it might be exploitable */ 841 /* Try to catch some obviously faulty streams, othervise it might be exploitable */