comparison cook.c @ 3009:f5898b9b8a8a libavcodec

Fix an out of array access and some minor cleanup of the code. All available cook samples decode correctly now. patch by Benjamin Larsson < banan ** at ** student ** dot ** ltu ** dot ** se >
author diego
date Wed, 04 Jan 2006 12:48:10 +0000
parents 24805f4d1b84
children 959b8ad880dc
comparison
equal deleted inserted replaced
3008:e23d2bddf122 3009:f5898b9b8a8a
129 float gain_table[23]; 129 float gain_table[23];
130 float pow2tab[127]; 130 float pow2tab[127];
131 float rootpow2tab[127]; 131 float rootpow2tab[127];
132 132
133 /* data buffers */ 133 /* data buffers */
134 uint8_t* frame_reorder_buffer;
135 int* frame_reorder_index;
136 int frame_reorder_counter;
137 int frame_reorder_complete;
138 int frame_reorder_index_size;
139 134
140 uint8_t* decoded_bytes_buffer; 135 uint8_t* decoded_bytes_buffer;
141 float mono_mdct_output[2048] __attribute__((aligned(16))); 136 float mono_mdct_output[2048] __attribute__((aligned(16)));
142 float* previous_buffer_ptr[2]; 137 float* previous_buffer_ptr[2];
143 float mono_previous_buffer1[1024]; 138 float mono_previous_buffer1[1024];
323 /* Free allocated memory buffers. */ 318 /* Free allocated memory buffers. */
324 av_free(q->mlt_window); 319 av_free(q->mlt_window);
325 av_free(q->mlt_precos); 320 av_free(q->mlt_precos);
326 av_free(q->mlt_presin); 321 av_free(q->mlt_presin);
327 av_free(q->mlt_postcos); 322 av_free(q->mlt_postcos);
328 av_free(q->frame_reorder_index);
329 av_free(q->frame_reorder_buffer);
330 av_free(q->decoded_bytes_buffer); 323 av_free(q->decoded_bytes_buffer);
331 324
332 /* Free the transform. */ 325 /* Free the transform. */
333 ff_fft_end(&q->fft_ctx); 326 ff_fft_end(&q->fft_ctx);
334 327
913 906
914 static void joint_decode(COOKContext *q, float* mlt_buffer1, 907 static void joint_decode(COOKContext *q, float* mlt_buffer1,
915 float* mlt_buffer2) { 908 float* mlt_buffer2) {
916 int i,j; 909 int i,j;
917 int decouple_tab[SUBBAND_SIZE]; 910 int decouple_tab[SUBBAND_SIZE];
918 float decode_buffer[2048]; //Only 1060 might be needed. 911 float decode_buffer[1060];
919 int idx, cpl_tmp,tmp_idx; 912 int idx, cpl_tmp,tmp_idx;
920 float f1,f2; 913 float f1,f2;
921 float* cplscale; 914 float* cplscale;
922 915
923 memset(decouple_tab, 0, sizeof(decouple_tab)); 916 memset(decouple_tab, 0, sizeof(decouple_tab));
938 } 931 }
939 932
940 /* When we reach js_subband_start (the higher frequencies) 933 /* When we reach js_subband_start (the higher frequencies)
941 the coefficients are stored in a coupling scheme. */ 934 the coefficients are stored in a coupling scheme. */
942 idx = (1 << q->js_vlc_bits) - 1; 935 idx = (1 << q->js_vlc_bits) - 1;
943 if (q->js_subband_start < q->subbands) { 936 for (i=q->js_subband_start ; i<q->subbands ; i++) {
944 for (i=0 ; i<q->subbands ; i++) { 937 cpl_tmp = cplband[i];
945 cpl_tmp = cplband[i + q->js_subband_start]; 938 idx -=decouple_tab[cpl_tmp];
946 idx -=decouple_tab[cpl_tmp]; 939 cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table
947 cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table 940 f1 = cplscale[decouple_tab[cpl_tmp]];
948 f1 = cplscale[decouple_tab[cpl_tmp]]; 941 f2 = cplscale[idx-1];
949 f2 = cplscale[idx-1]; 942 for (j=0 ; j<SUBBAND_SIZE ; j++) {
950 for (j=0 ; j<SUBBAND_SIZE ; j++) { 943 tmp_idx = ((q->js_subband_start + i)*20)+j;
951 tmp_idx = ((2*q->js_subband_start + i)*20)+j; 944 mlt_buffer1[20*i + j] = f1 * decode_buffer[tmp_idx];
952 mlt_buffer1[20*(i+q->js_subband_start) + j] = f1 * decode_buffer[tmp_idx]; 945 mlt_buffer2[20*i + j] = f2 * decode_buffer[tmp_idx];
953 mlt_buffer2[20*(i+q->js_subband_start) + j] = f2 * decode_buffer[tmp_idx]; 946 }
954 } 947 idx = (1 << q->js_vlc_bits) - 1;
955 idx = (1 << q->js_vlc_bits) - 1;
956 }
957 } 948 }
958 } 949 }
959 950
960 /** 951 /**
961 * Cook subpacket decoding. This function returns one decoded subpacket, 952 * Cook subpacket decoding. This function returns one decoded subpacket,
1157 PRINT("mlt_size",q->mlt_size); 1148 PRINT("mlt_size",q->mlt_size);
1158 PRINT("js_subband_start",q->js_subband_start); 1149 PRINT("js_subband_start",q->js_subband_start);
1159 PRINT("numvector_bits",q->numvector_bits); 1150 PRINT("numvector_bits",q->numvector_bits);
1160 PRINT("numvector_size",q->numvector_size); 1151 PRINT("numvector_size",q->numvector_size);
1161 PRINT("total_subbands",q->total_subbands); 1152 PRINT("total_subbands",q->total_subbands);
1162 PRINT("frame_reorder_counter",q->frame_reorder_counter);
1163 PRINT("frame_reorder_index_size",q->frame_reorder_index_size);
1164 } 1153 }
1165 #endif 1154 #endif
1166 /** 1155 /**
1167 * Cook initialization 1156 * Cook initialization
1168 * 1157 *
1291 memset(q->decode_buffer_4,0,1024*sizeof(float)); 1280 memset(q->decode_buffer_4,0,1024*sizeof(float));
1292 1281
1293 /* Initialize transform. */ 1282 /* Initialize transform. */
1294 if ( init_cook_mlt(q) == 0 ) 1283 if ( init_cook_mlt(q) == 0 )
1295 return -1; 1284 return -1;
1296 1285 #ifdef COOKDEBUG
1297 //dump_cook_context(q,e); 1286 dump_cook_context(q,e);
1287 #endif
1298 return 0; 1288 return 0;
1299 } 1289 }
1300 1290
1301 1291
1302 AVCodec cook_decoder = 1292 AVCodec cook_decoder =