Mercurial > libavcodec.hg
comparison flacenc.c @ 12310:eba0e28f6dbc libavcodec
Combine and simplify output_residual() and output_subframe_lpc().
author | jbr |
---|---|
date | Fri, 30 Jul 2010 20:53:02 +0000 |
parents | 0a496c73c434 |
children | 1a4351501522 |
comparison
equal
deleted
inserted
replaced
12309:0a496c73c434 | 12310:eba0e28f6dbc |
---|---|
1111 put_sbits(&s->pb, sub->obits, sub->residual[i]); | 1111 put_sbits(&s->pb, sub->obits, sub->residual[i]); |
1112 } | 1112 } |
1113 } | 1113 } |
1114 | 1114 |
1115 | 1115 |
1116 static void output_residual(FlacEncodeContext *s, FlacSubframe *sub) | |
1117 { | |
1118 int i, j, p, n, parts; | |
1119 int k, porder, psize, res_cnt; | |
1120 FlacFrame *frame; | |
1121 int32_t *res; | |
1122 | |
1123 frame = &s->frame; | |
1124 res = sub->residual; | |
1125 n = frame->blocksize; | |
1126 | |
1127 /* rice-encoded block */ | |
1128 put_bits(&s->pb, 2, 0); | |
1129 | |
1130 /* partition order */ | |
1131 porder = sub->rc.porder; | |
1132 psize = n >> porder; | |
1133 parts = (1 << porder); | |
1134 put_bits(&s->pb, 4, porder); | |
1135 res_cnt = psize - sub->order; | |
1136 | |
1137 /* residual */ | |
1138 j = sub->order; | |
1139 for (p = 0; p < parts; p++) { | |
1140 k = sub->rc.params[p]; | |
1141 put_bits(&s->pb, 4, k); | |
1142 if (p == 1) | |
1143 res_cnt = psize; | |
1144 for (i = 0; i < res_cnt && j < n; i++, j++) | |
1145 set_sr_golomb_flac(&s->pb, res[j], k, INT32_MAX, 0); | |
1146 } | |
1147 } | |
1148 | |
1149 | |
1150 static void output_subframe_lpc(FlacEncodeContext *s, FlacSubframe *sub) | 1116 static void output_subframe_lpc(FlacEncodeContext *s, FlacSubframe *sub) |
1151 { | 1117 { |
1152 int i; | 1118 int i, p, porder, psize; |
1119 int32_t *res, *part_end, *frame_end; | |
1153 | 1120 |
1154 /* warm-up samples */ | 1121 /* warm-up samples */ |
1122 res = sub->residual; | |
1155 for (i = 0; i < sub->order; i++) | 1123 for (i = 0; i < sub->order; i++) |
1156 put_sbits(&s->pb, sub->obits, sub->residual[i]); | 1124 put_sbits(&s->pb, sub->obits, *res++); |
1157 | 1125 |
1158 /* LPC coefficients */ | 1126 /* LPC coefficients */ |
1159 if (sub->type == FLAC_SUBFRAME_LPC) { | 1127 if (sub->type == FLAC_SUBFRAME_LPC) { |
1160 int cbits = s->options.lpc_coeff_precision; | 1128 int cbits = s->options.lpc_coeff_precision; |
1161 put_bits( &s->pb, 4, cbits-1); | 1129 put_bits( &s->pb, 4, cbits-1); |
1162 put_sbits(&s->pb, 5, sub->shift); | 1130 put_sbits(&s->pb, 5, sub->shift); |
1163 for (i = 0; i < sub->order; i++) | 1131 for (i = 0; i < sub->order; i++) |
1164 put_sbits(&s->pb, cbits, sub->coefs[i]); | 1132 put_sbits(&s->pb, cbits, sub->coefs[i]); |
1165 } | 1133 } |
1166 | 1134 |
1135 /* rice-encoded block */ | |
1136 put_bits(&s->pb, 2, 0); | |
1137 | |
1138 /* partition order */ | |
1139 porder = sub->rc.porder; | |
1140 psize = s->frame.blocksize >> porder; | |
1141 put_bits(&s->pb, 4, porder); | |
1142 | |
1167 /* residual */ | 1143 /* residual */ |
1168 output_residual(s, sub); | 1144 part_end = &sub->residual[psize ]; |
1145 frame_end = &sub->residual[s->frame.blocksize]; | |
1146 for (p = 0; p < 1 << porder; p++) { | |
1147 int k = sub->rc.params[p]; | |
1148 put_bits(&s->pb, 4, k); | |
1149 while (res < part_end) | |
1150 set_sr_golomb_flac(&s->pb, *res++, k, INT32_MAX, 0); | |
1151 part_end = FFMIN(frame_end, part_end + psize); | |
1152 } | |
1169 } | 1153 } |
1170 | 1154 |
1171 | 1155 |
1172 static void output_subframes(FlacEncodeContext *s) | 1156 static void output_subframes(FlacEncodeContext *s) |
1173 { | 1157 { |