MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_block

Function encode_block

libavcodec/nellymoserenc.c:278–349  ·  view source on GitHub ↗

* Encodes NELLY_SAMPLES samples. It assumes, that samples contains 3 * NELLY_BUF_LEN values * @param s encoder context * @param output output buffer * @param output_size size of output buffer */

Source from the content-addressed store, hash-verified

276 * @param output_size size of output buffer
277 */
278static void encode_block(NellyMoserEncodeContext *s, unsigned char *output, int output_size)
279{
280 PutBitContext pb;
281 int i, j, band, block, best_idx, power_idx = 0;
282 float power_val, coeff, coeff_sum;
283 float pows[NELLY_FILL_LEN];
284 int bits[NELLY_BUF_LEN], idx_table[NELLY_BANDS];
285 float cand[NELLY_BANDS];
286
287 apply_mdct(s);
288
289 init_put_bits(&pb, output, output_size * 8);
290
291 i = 0;
292 for (band = 0; band < NELLY_BANDS; band++) {
293 coeff_sum = 0;
294 for (j = 0; j < ff_nelly_band_sizes_table[band]; i++, j++) {
295 coeff_sum += s->mdct_out[i ] * s->mdct_out[i ]
296 + s->mdct_out[i + NELLY_BUF_LEN] * s->mdct_out[i + NELLY_BUF_LEN];
297 }
298 cand[band] =
299 log(FFMAX(1.0, coeff_sum / (ff_nelly_band_sizes_table[band] << 7))) * 1024.0 / M_LN2;
300 }
301
302 if (s->avctx->trellis) {
303 get_exponent_dynamic(s, cand, idx_table);
304 } else {
305 get_exponent_greedy(s, cand, idx_table);
306 }
307
308 i = 0;
309 for (band = 0; band < NELLY_BANDS; band++) {
310 if (band) {
311 power_idx += ff_nelly_delta_table[idx_table[band]];
312 put_bits(&pb, 5, idx_table[band]);
313 } else {
314 power_idx = ff_nelly_init_table[idx_table[0]];
315 put_bits(&pb, 6, idx_table[0]);
316 }
317 power_val = pow_table[power_idx & 0x7FF] / (1 << ((power_idx >> 11) + POW_TABLE_OFFSET));
318 for (j = 0; j < ff_nelly_band_sizes_table[band]; i++, j++) {
319 s->mdct_out[i] *= power_val;
320 s->mdct_out[i + NELLY_BUF_LEN] *= power_val;
321 pows[i] = power_idx;
322 }
323 }
324
325 ff_nelly_get_sample_bits(pows, bits);
326
327 for (block = 0; block < 2; block++) {
328 for (i = 0; i < NELLY_FILL_LEN; i++) {
329 if (bits[i] > 0) {
330 const float *table = ff_nelly_dequantization_table + (1 << bits[i]) - 1;
331 coeff = s->mdct_out[block * NELLY_BUF_LEN + i];
332 best_idx =
333 quant_lut[av_clip (
334 coeff * quant_lut_mul[bits[i]] + quant_lut_add[bits[i]],
335 quant_lut_offset[bits[i]],

Callers 1

encode_frameFunction · 0.70

Calls 8

apply_mdctFunction · 0.85
init_put_bitsFunction · 0.85
get_exponent_dynamicFunction · 0.85
get_exponent_greedyFunction · 0.85
ff_nelly_get_sample_bitsFunction · 0.85
av_clipFunction · 0.85
put_bits_countFunction · 0.85
flush_put_bitsFunction · 0.85

Tested by

no test coverage detected