Mercurial > libavcodec.hg
comparison cook.c @ 5346:b41036edcf2e libavcodec
fixpoint: lowlevel functional abstraction for all buffer arithmetics
author | mhoffman |
---|---|
date | Mon, 16 Jul 2007 12:32:41 +0000 |
parents | af1c85da8982 |
children | 59ec490fe985 |
comparison
equal
deleted
inserted
replaced
5345:af1c85da8982 | 5346:b41036edcf2e |
---|---|
66 typedef struct { | 66 typedef struct { |
67 int *now; | 67 int *now; |
68 int *previous; | 68 int *previous; |
69 } cook_gains; | 69 } cook_gains; |
70 | 70 |
71 typedef struct { | 71 typedef struct cook { |
72 /* | |
73 * The following 5 functions provide the lowlevel arithmetic on | |
74 * the internal audio buffers. | |
75 */ | |
76 void (* scalar_dequant)(struct cook *q, int index, int quant_index, | |
77 int* subband_coef_index, int* subband_coef_sign, | |
78 float* mlt_p); | |
79 | |
80 void (* decouple) (struct cook *q, | |
81 int subband, | |
82 float f1, float f2, | |
83 float *decode_buffer, | |
84 float *mlt_buffer1, float *mlt_buffer2); | |
85 | |
86 void (* imlt_window) (struct cook *q, float *buffer1, | |
87 cook_gains *gains_ptr, float *previous_buffer); | |
88 | |
89 void (* interpolate) (struct cook *q, float* buffer, | |
90 int gain_index, int gain_index_next); | |
91 | |
92 void (* saturate_output) (struct cook *q, int chan, int16_t *out); | |
93 | |
72 GetBitContext gb; | 94 GetBitContext gb; |
73 /* stream data */ | 95 /* stream data */ |
74 int nb_channels; | 96 int nb_channels; |
75 int joint_stereo; | 97 int joint_stereo; |
76 int bit_rate; | 98 int bit_rate; |
595 } | 617 } |
596 if(index==7) { | 618 if(index==7) { |
597 memset(subband_coef_index, 0, sizeof(subband_coef_index)); | 619 memset(subband_coef_index, 0, sizeof(subband_coef_index)); |
598 memset(subband_coef_sign, 0, sizeof(subband_coef_sign)); | 620 memset(subband_coef_sign, 0, sizeof(subband_coef_sign)); |
599 } | 621 } |
600 scalar_dequant(q, index, quant_index_table[band], | 622 q->scalar_dequant(q, index, quant_index_table[band], |
601 subband_coef_index, subband_coef_sign, | 623 subband_coef_index, subband_coef_sign, |
602 &mlt_buffer[band * SUBBAND_SIZE]); | 624 &mlt_buffer[band * SUBBAND_SIZE]); |
603 } | 625 } |
604 | 626 |
605 if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){ | 627 if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){ |
710 | 732 |
711 /* Inverse modified discrete cosine transform */ | 733 /* Inverse modified discrete cosine transform */ |
712 q->mdct_ctx.fft.imdct_calc(&q->mdct_ctx, q->mono_mdct_output, | 734 q->mdct_ctx.fft.imdct_calc(&q->mdct_ctx, q->mono_mdct_output, |
713 inbuffer, q->mdct_tmp); | 735 inbuffer, q->mdct_tmp); |
714 | 736 |
715 imlt_window_float (q, buffer1, gains_ptr, previous_buffer); | 737 q->imlt_window (q, buffer1, gains_ptr, previous_buffer); |
716 | 738 |
717 /* Apply gain profile */ | 739 /* Apply gain profile */ |
718 for (i = 0; i < 8; i++) { | 740 for (i = 0; i < 8; i++) { |
719 if (gains_ptr->now[i] || gains_ptr->now[i + 1]) | 741 if (gains_ptr->now[i] || gains_ptr->now[i + 1]) |
720 interpolate(q, &buffer1[q->gain_size_factor * i], | 742 q->interpolate(q, &buffer1[q->gain_size_factor * i], |
721 gains_ptr->now[i], gains_ptr->now[i + 1]); | 743 gains_ptr->now[i], gains_ptr->now[i + 1]); |
722 } | 744 } |
723 | 745 |
724 /* Save away the current to be previous block. */ | 746 /* Save away the current to be previous block. */ |
725 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel); | 747 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel); |
822 cpl_tmp = cplband[i]; | 844 cpl_tmp = cplband[i]; |
823 idx -=decouple_tab[cpl_tmp]; | 845 idx -=decouple_tab[cpl_tmp]; |
824 cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table | 846 cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table |
825 f1 = cplscale[decouple_tab[cpl_tmp]]; | 847 f1 = cplscale[decouple_tab[cpl_tmp]]; |
826 f2 = cplscale[idx-1]; | 848 f2 = cplscale[idx-1]; |
827 decouple_float (q, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); | 849 q->decouple (q, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); |
828 idx = (1 << q->js_vlc_bits) - 1; | 850 idx = (1 << q->js_vlc_bits) - 1; |
829 } | 851 } |
830 } | 852 } |
831 | 853 |
832 /** | 854 /** |
891 mlt_compensate_output(COOKContext *q, float *decode_buffer, | 913 mlt_compensate_output(COOKContext *q, float *decode_buffer, |
892 cook_gains *gains, float *previous_buffer, | 914 cook_gains *gains, float *previous_buffer, |
893 int16_t *out, int chan) | 915 int16_t *out, int chan) |
894 { | 916 { |
895 imlt_gain(q, decode_buffer, gains, previous_buffer); | 917 imlt_gain(q, decode_buffer, gains, previous_buffer); |
896 saturate_output_float (q, chan, out); | 918 q->saturate_output (q, chan, out); |
897 } | 919 } |
898 | 920 |
899 | 921 |
900 /** | 922 /** |
901 * Cook subpacket decoding. This function returns one decoded subpacket, | 923 * Cook subpacket decoding. This function returns one decoded subpacket, |
1123 | 1145 |
1124 /* Initialize transform. */ | 1146 /* Initialize transform. */ |
1125 if ( init_cook_mlt(q) != 0 ) | 1147 if ( init_cook_mlt(q) != 0 ) |
1126 return -1; | 1148 return -1; |
1127 | 1149 |
1150 /* Initialize COOK signal arithmetic handling */ | |
1151 if (1) { | |
1152 q->scalar_dequant = scalar_dequant; | |
1153 q->decouple = decouple_float; | |
1154 q->imlt_window = imlt_window_float; | |
1155 q->interpolate = interpolate; | |
1156 q->saturate_output = saturate_output_float; | |
1157 } | |
1158 | |
1128 /* Try to catch some obviously faulty streams, othervise it might be exploitable */ | 1159 /* Try to catch some obviously faulty streams, othervise it might be exploitable */ |
1129 if (q->total_subbands > 53) { | 1160 if (q->total_subbands > 53) { |
1130 av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n"); | 1161 av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n"); |
1131 return -1; | 1162 return -1; |
1132 } | 1163 } |