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

Function sonic_encode_frame

libavcodec/sonic.c:351–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
352 const AVFrame *frame, int *got_packet_ptr)
353{
354 SonicContext *s = avctx->priv_data;
355 RangeCoder c;
356 int i, j, ch, quant = 0, x = 0;
357 int ret;
358 const short *samples = (const int16_t*)frame->data[0];
359 uint8_t state[32];
360
361 if ((ret = ff_alloc_packet(avctx, avpkt, s->frame_size * 5 + 1000)) < 0)
362 return ret;
363
364 ff_init_range_encoder(&c, avpkt->data, avpkt->size);
365 ff_build_rac_states(&c, 0.05*(1LL<<32), 256-8);
366 memset(state, 128, sizeof(state));
367
368 // short -> internal
369 for (i = 0; i < s->frame_size; i++)
370 s->int_samples[i] = samples[i];
371
372 if (!s->lossless)
373 for (i = 0; i < s->frame_size; i++)
374 s->int_samples[i] = s->int_samples[i] << SAMPLE_SHIFT;
375
376 switch(s->decorrelation)
377 {
378 case MID_SIDE:
379 for (i = 0; i < s->frame_size; i += s->channels)
380 {
381 s->int_samples[i] += s->int_samples[i+1];
382 s->int_samples[i+1] -= shift(s->int_samples[i], 1);
383 }
384 break;
385 case LEFT_SIDE:
386 for (i = 0; i < s->frame_size; i += s->channels)
387 s->int_samples[i+1] -= s->int_samples[i];
388 break;
389 case RIGHT_SIDE:
390 for (i = 0; i < s->frame_size; i += s->channels)
391 s->int_samples[i] -= s->int_samples[i+1];
392 break;
393 }
394
395 memset(s->window, 0, s->window_size * sizeof(*s->window));
396
397 for (i = 0; i < s->tail_size; i++)
398 s->window[x++] = s->tail[i];
399
400 for (i = 0; i < s->frame_size; i++)
401 s->window[x++] = s->int_samples[i];
402
403 for (i = 0; i < s->tail_size; i++)
404 s->window[x++] = 0;
405
406 for (i = 0; i < s->tail_size; i++)
407 s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
408

Callers

nothing calls this directly

Calls 9

ff_alloc_packetFunction · 0.85
ff_init_range_encoderFunction · 0.85
ff_build_rac_statesFunction · 0.85
modified_levinson_durbinFunction · 0.85
intlist_writeFunction · 0.85
fabsFunction · 0.85
ff_rac_terminateFunction · 0.85
shiftFunction · 0.70
put_symbolFunction · 0.70

Tested by

no test coverage detected