Mercurial > libavcodec.hg
comparison flacenc.c @ 12305:000218dd70aa libavcodec
cosmetics: change FlacEncodeContext variable name from ctx to s in several
places for consistency.
author | jbr |
---|---|
date | Fri, 30 Jul 2010 19:40:18 +0000 |
parents | 78275120749d |
children | 94e9dcf99f21 |
comparison
equal
deleted
inserted
replaced
12304:78275120749d | 12305:000218dd70aa |
---|---|
789 } | 789 } |
790 #endif | 790 #endif |
791 } | 791 } |
792 | 792 |
793 | 793 |
794 static int encode_residual(FlacEncodeContext *ctx, int ch) | 794 static int encode_residual(FlacEncodeContext *s, int ch) |
795 { | 795 { |
796 int i, n; | 796 int i, n; |
797 int min_order, max_order, opt_order, precision, omethod; | 797 int min_order, max_order, opt_order, precision, omethod; |
798 int min_porder, max_porder; | 798 int min_porder, max_porder; |
799 FlacFrame *frame; | 799 FlacFrame *frame; |
800 FlacSubframe *sub; | 800 FlacSubframe *sub; |
801 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; | 801 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; |
802 int shift[MAX_LPC_ORDER]; | 802 int shift[MAX_LPC_ORDER]; |
803 int32_t *res, *smp; | 803 int32_t *res, *smp; |
804 | 804 |
805 frame = &ctx->frame; | 805 frame = &s->frame; |
806 sub = &frame->subframes[ch]; | 806 sub = &frame->subframes[ch]; |
807 res = sub->residual; | 807 res = sub->residual; |
808 smp = sub->samples; | 808 smp = sub->samples; |
809 n = frame->blocksize; | 809 n = frame->blocksize; |
810 | 810 |
823 sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM; | 823 sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM; |
824 encode_residual_verbatim(res, smp, n); | 824 encode_residual_verbatim(res, smp, n); |
825 return sub->obits * n; | 825 return sub->obits * n; |
826 } | 826 } |
827 | 827 |
828 min_order = ctx->options.min_prediction_order; | 828 min_order = s->options.min_prediction_order; |
829 max_order = ctx->options.max_prediction_order; | 829 max_order = s->options.max_prediction_order; |
830 min_porder = ctx->options.min_partition_order; | 830 min_porder = s->options.min_partition_order; |
831 max_porder = ctx->options.max_partition_order; | 831 max_porder = s->options.max_partition_order; |
832 precision = ctx->options.lpc_coeff_precision; | 832 precision = s->options.lpc_coeff_precision; |
833 omethod = ctx->options.prediction_order_method; | 833 omethod = s->options.prediction_order_method; |
834 | 834 |
835 /* FIXED */ | 835 /* FIXED */ |
836 if (ctx->options.lpc_type == AV_LPC_TYPE_NONE || | 836 if (s->options.lpc_type == AV_LPC_TYPE_NONE || |
837 ctx->options.lpc_type == AV_LPC_TYPE_FIXED || n <= max_order) { | 837 s->options.lpc_type == AV_LPC_TYPE_FIXED || n <= max_order) { |
838 uint32_t bits[MAX_FIXED_ORDER+1]; | 838 uint32_t bits[MAX_FIXED_ORDER+1]; |
839 if (max_order > MAX_FIXED_ORDER) | 839 if (max_order > MAX_FIXED_ORDER) |
840 max_order = MAX_FIXED_ORDER; | 840 max_order = MAX_FIXED_ORDER; |
841 opt_order = 0; | 841 opt_order = 0; |
842 bits[0] = UINT32_MAX; | 842 bits[0] = UINT32_MAX; |
857 } | 857 } |
858 return bits[sub->order]; | 858 return bits[sub->order]; |
859 } | 859 } |
860 | 860 |
861 /* LPC */ | 861 /* LPC */ |
862 opt_order = ff_lpc_calc_coefs(&ctx->dsp, smp, n, min_order, max_order, | 862 opt_order = ff_lpc_calc_coefs(&s->dsp, smp, n, min_order, max_order, |
863 precision, coefs, shift, ctx->options.lpc_type, | 863 precision, coefs, shift, s->options.lpc_type, |
864 ctx->options.lpc_passes, omethod, | 864 s->options.lpc_passes, omethod, |
865 MAX_LPC_SHIFT, 0); | 865 MAX_LPC_SHIFT, 0); |
866 | 866 |
867 if (omethod == ORDER_METHOD_2LEVEL || | 867 if (omethod == ORDER_METHOD_2LEVEL || |
868 omethod == ORDER_METHOD_4LEVEL || | 868 omethod == ORDER_METHOD_4LEVEL || |
869 omethod == ORDER_METHOD_8LEVEL) { | 869 omethod == ORDER_METHOD_8LEVEL) { |
934 return calc_rice_params_lpc(&sub->rc, min_porder, max_porder, res, n, | 934 return calc_rice_params_lpc(&sub->rc, min_porder, max_porder, res, n, |
935 sub->order, sub->obits, precision); | 935 sub->order, sub->obits, precision); |
936 } | 936 } |
937 | 937 |
938 | 938 |
939 static int encode_residual_v(FlacEncodeContext *ctx, int ch) | 939 static int encode_residual_v(FlacEncodeContext *s, int ch) |
940 { | 940 { |
941 int i, n; | 941 int i, n; |
942 FlacFrame *frame; | 942 FlacFrame *frame; |
943 FlacSubframe *sub; | 943 FlacSubframe *sub; |
944 int32_t *res, *smp; | 944 int32_t *res, *smp; |
945 | 945 |
946 frame = &ctx->frame; | 946 frame = &s->frame; |
947 sub = &frame->subframes[ch]; | 947 sub = &frame->subframes[ch]; |
948 res = sub->residual; | 948 res = sub->residual; |
949 smp = sub->samples; | 949 smp = sub->samples; |
950 n = frame->blocksize; | 950 n = frame->blocksize; |
951 | 951 |
1014 | 1014 |
1015 | 1015 |
1016 /** | 1016 /** |
1017 * Perform stereo channel decorrelation. | 1017 * Perform stereo channel decorrelation. |
1018 */ | 1018 */ |
1019 static void channel_decorrelation(FlacEncodeContext *ctx) | 1019 static void channel_decorrelation(FlacEncodeContext *s) |
1020 { | 1020 { |
1021 FlacFrame *frame; | 1021 FlacFrame *frame; |
1022 int32_t *left, *right; | 1022 int32_t *left, *right; |
1023 int i, n; | 1023 int i, n; |
1024 | 1024 |
1025 frame = &ctx->frame; | 1025 frame = &s->frame; |
1026 n = frame->blocksize; | 1026 n = frame->blocksize; |
1027 left = frame->subframes[0].samples; | 1027 left = frame->subframes[0].samples; |
1028 right = frame->subframes[1].samples; | 1028 right = frame->subframes[1].samples; |
1029 | 1029 |
1030 if (ctx->channels != 2) { | 1030 if (s->channels != 2) { |
1031 frame->ch_mode = FLAC_CHMODE_INDEPENDENT; | 1031 frame->ch_mode = FLAC_CHMODE_INDEPENDENT; |
1032 return; | 1032 return; |
1033 } | 1033 } |
1034 | 1034 |
1035 frame->ch_mode = estimate_stereo_mode(left, right, n); | 1035 frame->ch_mode = estimate_stereo_mode(left, right, n); |
1127 put_sbits(&s->pb, sub->obits, res); | 1127 put_sbits(&s->pb, sub->obits, res); |
1128 } | 1128 } |
1129 } | 1129 } |
1130 | 1130 |
1131 | 1131 |
1132 static void output_residual(FlacEncodeContext *ctx, int ch) | 1132 static void output_residual(FlacEncodeContext *s, int ch) |
1133 { | 1133 { |
1134 int i, j, p, n, parts; | 1134 int i, j, p, n, parts; |
1135 int k, porder, psize, res_cnt; | 1135 int k, porder, psize, res_cnt; |
1136 FlacFrame *frame; | 1136 FlacFrame *frame; |
1137 FlacSubframe *sub; | 1137 FlacSubframe *sub; |
1138 int32_t *res; | 1138 int32_t *res; |
1139 | 1139 |
1140 frame = &ctx->frame; | 1140 frame = &s->frame; |
1141 sub = &frame->subframes[ch]; | 1141 sub = &frame->subframes[ch]; |
1142 res = sub->residual; | 1142 res = sub->residual; |
1143 n = frame->blocksize; | 1143 n = frame->blocksize; |
1144 | 1144 |
1145 /* rice-encoded block */ | 1145 /* rice-encoded block */ |
1146 put_bits(&ctx->pb, 2, 0); | 1146 put_bits(&s->pb, 2, 0); |
1147 | 1147 |
1148 /* partition order */ | 1148 /* partition order */ |
1149 porder = sub->rc.porder; | 1149 porder = sub->rc.porder; |
1150 psize = n >> porder; | 1150 psize = n >> porder; |
1151 parts = (1 << porder); | 1151 parts = (1 << porder); |
1152 put_bits(&ctx->pb, 4, porder); | 1152 put_bits(&s->pb, 4, porder); |
1153 res_cnt = psize - sub->order; | 1153 res_cnt = psize - sub->order; |
1154 | 1154 |
1155 /* residual */ | 1155 /* residual */ |
1156 j = sub->order; | 1156 j = sub->order; |
1157 for (p = 0; p < parts; p++) { | 1157 for (p = 0; p < parts; p++) { |
1158 k = sub->rc.params[p]; | 1158 k = sub->rc.params[p]; |
1159 put_bits(&ctx->pb, 4, k); | 1159 put_bits(&s->pb, 4, k); |
1160 if (p == 1) | 1160 if (p == 1) |
1161 res_cnt = psize; | 1161 res_cnt = psize; |
1162 for (i = 0; i < res_cnt && j < n; i++, j++) | 1162 for (i = 0; i < res_cnt && j < n; i++, j++) |
1163 set_sr_golomb_flac(&ctx->pb, res[j], k, INT32_MAX, 0); | 1163 set_sr_golomb_flac(&s->pb, res[j], k, INT32_MAX, 0); |
1164 } | 1164 } |
1165 } | 1165 } |
1166 | 1166 |
1167 | 1167 |
1168 static void output_subframe_fixed(FlacEncodeContext *ctx, int ch) | 1168 static void output_subframe_fixed(FlacEncodeContext *s, int ch) |
1169 { | 1169 { |
1170 int i; | 1170 int i; |
1171 FlacFrame *frame; | 1171 FlacFrame *frame; |
1172 FlacSubframe *sub; | 1172 FlacSubframe *sub; |
1173 | 1173 |
1174 frame = &ctx->frame; | 1174 frame = &s->frame; |
1175 sub = &frame->subframes[ch]; | 1175 sub = &frame->subframes[ch]; |
1176 | 1176 |
1177 /* warm-up samples */ | 1177 /* warm-up samples */ |
1178 for (i = 0; i < sub->order; i++) | 1178 for (i = 0; i < sub->order; i++) |
1179 put_sbits(&ctx->pb, sub->obits, sub->residual[i]); | 1179 put_sbits(&s->pb, sub->obits, sub->residual[i]); |
1180 | 1180 |
1181 /* residual */ | 1181 /* residual */ |
1182 output_residual(ctx, ch); | 1182 output_residual(s, ch); |
1183 } | 1183 } |
1184 | 1184 |
1185 | 1185 |
1186 static void output_subframe_lpc(FlacEncodeContext *ctx, int ch) | 1186 static void output_subframe_lpc(FlacEncodeContext *s, int ch) |
1187 { | 1187 { |
1188 int i, cbits; | 1188 int i, cbits; |
1189 FlacFrame *frame; | 1189 FlacFrame *frame; |
1190 FlacSubframe *sub; | 1190 FlacSubframe *sub; |
1191 | 1191 |
1192 frame = &ctx->frame; | 1192 frame = &s->frame; |
1193 sub = &frame->subframes[ch]; | 1193 sub = &frame->subframes[ch]; |
1194 | 1194 |
1195 /* warm-up samples */ | 1195 /* warm-up samples */ |
1196 for (i = 0; i < sub->order; i++) | 1196 for (i = 0; i < sub->order; i++) |
1197 put_sbits(&ctx->pb, sub->obits, sub->residual[i]); | 1197 put_sbits(&s->pb, sub->obits, sub->residual[i]); |
1198 | 1198 |
1199 /* LPC coefficients */ | 1199 /* LPC coefficients */ |
1200 cbits = ctx->options.lpc_coeff_precision; | 1200 cbits = s->options.lpc_coeff_precision; |
1201 put_bits( &ctx->pb, 4, cbits-1); | 1201 put_bits( &s->pb, 4, cbits-1); |
1202 put_sbits(&ctx->pb, 5, sub->shift); | 1202 put_sbits(&s->pb, 5, sub->shift); |
1203 for (i = 0; i < sub->order; i++) | 1203 for (i = 0; i < sub->order; i++) |
1204 put_sbits(&ctx->pb, cbits, sub->coefs[i]); | 1204 put_sbits(&s->pb, cbits, sub->coefs[i]); |
1205 | 1205 |
1206 /* residual */ | 1206 /* residual */ |
1207 output_residual(ctx, ch); | 1207 output_residual(s, ch); |
1208 } | 1208 } |
1209 | 1209 |
1210 | 1210 |
1211 static void output_subframes(FlacEncodeContext *s) | 1211 static void output_subframes(FlacEncodeContext *s) |
1212 { | 1212 { |