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

Function encode_block

libavcodec/nellymoserenc.c:307–379  ·  view source on GitHub ↗

* Encode 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

305 * @param output_size size of output buffer
306 */
307static void encode_block(NellyMoserEncodeContext *s, unsigned char *output, int output_size)
308{
309 PutBitContext pb;
310 int i, j, band, block, best_idx, power_idx = 0;
311 float power_val, coeff, coeff_sum;
312 float pows[NELLY_FILL_LEN];
313 int bits[NELLY_BUF_LEN], idx_table[NELLY_BANDS];
314 float cand[NELLY_BANDS];
315
316 apply_mdct(s);
317
318 init_put_bits(&pb, output, output_size);
319
320 i = 0;
321 for (band = 0; band < NELLY_BANDS; band++) {
322 coeff_sum = 0;
323 for (j = 0; j < ff_nelly_band_sizes_table[band]; i++, j++) {
324 coeff_sum += s->mdct_out[i ] * s->mdct_out[i ]
325 + s->mdct_out[i + NELLY_BUF_LEN] * s->mdct_out[i + NELLY_BUF_LEN];
326 }
327 cand[band] =
328 log2(FFMAX(1.0, coeff_sum / (ff_nelly_band_sizes_table[band] << 7))) * 1024.0;
329 }
330
331 if (s->avctx->trellis) {
332 get_exponent_dynamic(s, cand, idx_table);
333 } else {
334 get_exponent_greedy(s, cand, idx_table);
335 }
336
337 i = 0;
338 for (band = 0; band < NELLY_BANDS; band++) {
339 if (band) {
340 power_idx += ff_nelly_delta_table[idx_table[band]];
341 put_bits(&pb, 5, idx_table[band]);
342 } else {
343 power_idx = ff_nelly_init_table[idx_table[0]];
344 put_bits(&pb, 6, idx_table[0]);
345 }
346 power_val = pow_table[power_idx & 0x7FF] / (1 << ((power_idx >> 11) + POW_TABLE_OFFSET));
347 for (j = 0; j < ff_nelly_band_sizes_table[band]; i++, j++) {
348 s->mdct_out[i] *= power_val;
349 s->mdct_out[i + NELLY_BUF_LEN] *= power_val;
350 pows[i] = power_idx;
351 }
352 }
353
354 ff_nelly_get_sample_bits(pows, bits);
355
356 for (block = 0; block < 2; block++) {
357 for (i = 0; i < NELLY_FILL_LEN; i++) {
358 if (bits[i] > 0) {
359 const float *table = ff_nelly_dequantization_table + (1 << bits[i]) - 1;
360 coeff = s->mdct_out[block * NELLY_BUF_LEN + i];
361 best_idx =
362 quant_lut[av_clip (
363 coeff * quant_lut_mul[bits[i]] + quant_lut_add[bits[i]],
364 quant_lut_offset[bits[i]],

Callers 1

encode_frameFunction · 0.70

Calls 10

init_put_bitsFunction · 0.85
get_exponent_dynamicFunction · 0.85
get_exponent_greedyFunction · 0.85
ff_nelly_get_sample_bitsFunction · 0.85
fabsFunction · 0.85
put_bits_countFunction · 0.85
flush_put_bitsFunction · 0.85
put_bits_ptrFunction · 0.85
apply_mdctFunction · 0.70
put_bitsFunction · 0.70

Tested by

no test coverage detected