FFmpeg
Loading...
Searching...
No Matches
alacenc.c
Go to the documentation of this file.
1/*
2 * ALAC audio encoder
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "libavutil/mem.h"
23#include "libavutil/opt.h"
24
25#include "avcodec.h"
26#include "codec_internal.h"
27#include "encode.h"
28#include "put_bits.h"
29#include "lpc.h"
30#include "mathops.h"
31#include "alac_data.h"
32
33#define DEFAULT_FRAME_SIZE 4096
34#define ALAC_EXTRADATA_SIZE 36
35#define ALAC_FRAME_HEADER_SIZE 55
36#define ALAC_FRAME_FOOTER_SIZE 3
37
38#define ALAC_ESCAPE_CODE 0x1FF
39#define ALAC_MAX_LPC_ORDER 30
40#define DEFAULT_MAX_PRED_ORDER 6
41#define DEFAULT_MIN_PRED_ORDER 4
42#define ALAC_MAX_LPC_PRECISION 9
43#define ALAC_MIN_LPC_SHIFT 0
44#define ALAC_MAX_LPC_SHIFT 9
45
46#define ALAC_CHMODE_LEFT_RIGHT 0
47#define ALAC_CHMODE_LEFT_SIDE 1
48#define ALAC_CHMODE_RIGHT_SIDE 2
49#define ALAC_CHMODE_MID_SIDE 3
50
57
63
84
85
87 const uint8_t *samples[2])
88{
89 int ch, i;
90 int shift = av_get_bytes_per_sample(s->avctx->sample_fmt) * 8 -
91 s->avctx->bits_per_raw_sample;
92
93#define COPY_SAMPLES(type) do { \
94 for (ch = 0; ch < channels; ch++) { \
95 int32_t *bptr = s->sample_buf[ch]; \
96 const type *sptr = (const type *)samples[ch]; \
97 for (i = 0; i < s->frame_size; i++) \
98 bptr[i] = sptr[i] >> shift; \
99 } \
100 } while (0)
101
102 if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S32P)
104 else
105 COPY_SAMPLES(int16_t);
106}
107
109 int k, int write_sample_size)
110{
111 int divisor, q, r;
112
113 k = FFMIN(k, s->rc.k_modifier);
114 divisor = (1<<k) - 1;
115 q = x / divisor;
116 r = x % divisor;
117
118 if (q > 8) {
119 // write escape code and sample value directly
120 put_bits(&s->pbctx, 9, ALAC_ESCAPE_CODE);
121 put_bits(&s->pbctx, write_sample_size, x);
122 } else {
123 if (q)
124 put_bits(&s->pbctx, q, (1<<q) - 1);
125 put_bits(&s->pbctx, 1, 0);
126
127 if (k != 1) {
128 if (r > 0)
129 put_bits(&s->pbctx, k, r+1);
130 else
131 put_bits(&s->pbctx, k-1, 0);
132 }
133 }
134}
135
137 enum AlacRawDataBlockType element,
138 int instance)
139{
140 int encode_fs = 0;
141
142 if (s->frame_size < DEFAULT_FRAME_SIZE)
143 encode_fs = 1;
144
145 put_bits(&s->pbctx, 3, element); // element type
146 put_bits(&s->pbctx, 4, instance); // element instance
147 put_bits(&s->pbctx, 12, 0); // unused header bits
148 put_bits(&s->pbctx, 1, encode_fs); // Sample count is in the header
149 put_bits(&s->pbctx, 2, s->extra_bits >> 3); // Extra bytes (for 24-bit)
150 put_bits(&s->pbctx, 1, s->verbatim); // Audio block is verbatim
151 if (encode_fs)
152 put_bits32(&s->pbctx, s->frame_size); // No. of samples in the frame
153}
154
156{
158 int shift[MAX_LPC_ORDER];
159 int opt_order;
160
161 if (s->compression_level == 1) {
162 s->lpc[ch].lpc_order = 6;
163 s->lpc[ch].lpc_quant = 6;
164 s->lpc[ch].lpc_coeff[0] = 160;
165 s->lpc[ch].lpc_coeff[1] = -190;
166 s->lpc[ch].lpc_coeff[2] = 170;
167 s->lpc[ch].lpc_coeff[3] = -130;
168 s->lpc[ch].lpc_coeff[4] = 80;
169 s->lpc[ch].lpc_coeff[5] = -25;
170 } else {
171 opt_order = ff_lpc_calc_coefs(&s->lpc_ctx, s->sample_buf[ch],
172 s->frame_size,
173 s->min_prediction_order,
174 s->max_prediction_order,
179
180 s->lpc[ch].lpc_order = opt_order;
181 s->lpc[ch].lpc_quant = shift[opt_order-1];
182 memcpy(s->lpc[ch].lpc_coeff, coefs[opt_order-1], opt_order*sizeof(int));
183 }
184}
185
186static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
187{
188 int i, best;
189 int32_t lt, rt;
190 uint64_t sum[4];
191 uint64_t score[4];
192
193 /* calculate sum of 2nd order residual for each channel */
194 sum[0] = sum[1] = sum[2] = sum[3] = 0;
195 for (i = 2; i < n; i++) {
196 lt = left_ch[i] - 2 * left_ch[i - 1] + left_ch[i - 2];
197 rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];
198 sum[2] += FFABS((lt + rt) >> 1);
199 sum[3] += FFABS(lt - rt);
200 sum[0] += FFABS(lt);
201 sum[1] += FFABS(rt);
202 }
203
204 /* calculate score for each mode */
205 score[0] = sum[0] + sum[1];
206 score[1] = sum[0] + sum[3];
207 score[2] = sum[1] + sum[3];
208 score[3] = sum[2] + sum[3];
209
210 /* return mode with lowest score */
211 best = 0;
212 for (i = 1; i < 4; i++) {
213 if (score[i] < score[best])
214 best = i;
215 }
216 return best;
217}
218
220{
221 int32_t *left = s->sample_buf[0], *right = s->sample_buf[1];
222 int i, mode, n = s->frame_size;
223 int32_t tmp;
224
225 mode = estimate_stereo_mode(left, right, n);
226
227 switch (mode) {
229 s->interlacing_leftweight = 0;
230 s->interlacing_shift = 0;
231 break;
233 for (i = 0; i < n; i++)
234 right[i] = left[i] - right[i];
235 s->interlacing_leftweight = 1;
236 s->interlacing_shift = 0;
237 break;
239 for (i = 0; i < n; i++) {
240 tmp = right[i];
241 right[i] = left[i] - right[i];
242 left[i] = tmp + (right[i] >> 31);
243 }
244 s->interlacing_leftweight = 1;
245 s->interlacing_shift = 31;
246 break;
247 default:
248 for (i = 0; i < n; i++) {
249 tmp = left[i];
250 left[i] = (tmp + right[i]) >> 1;
251 right[i] = tmp - right[i];
252 }
253 s->interlacing_leftweight = 1;
254 s->interlacing_shift = 1;
255 break;
256 }
257}
258
260{
261 int i;
262 AlacLPCContext lpc = s->lpc[ch];
263 int32_t *residual = s->predictor_buf[ch];
264
265 if (lpc.lpc_order == 31) {
266 residual[0] = s->sample_buf[ch][0];
267
268 for (i = 1; i < s->frame_size; i++) {
269 residual[i] = s->sample_buf[ch][i ] -
270 s->sample_buf[ch][i - 1];
271 }
272
273 return;
274 }
275
276 // generalised linear predictor
277
278 if (lpc.lpc_order > 0) {
279 int32_t *samples = s->sample_buf[ch];
280
281 // generate warm-up samples
282 residual[0] = samples[0];
283 for (i = 1; i <= lpc.lpc_order; i++)
284 residual[i] = sign_extend(samples[i] - samples[i-1], s->write_sample_size);
285
286 // perform lpc on remaining samples
287 for (i = lpc.lpc_order + 1; i < s->frame_size; i++) {
288 int sum = 1 << (lpc.lpc_quant - 1), res_val, j;
289
290 for (j = 0; j < lpc.lpc_order; j++) {
291 sum += (samples[lpc.lpc_order-j] - samples[0]) *
292 lpc.lpc_coeff[j];
293 }
294
295 sum >>= lpc.lpc_quant;
296 sum += samples[0];
297 residual[i] = sign_extend(samples[lpc.lpc_order+1] - sum,
298 s->write_sample_size);
299 res_val = residual[i];
300
301 if (res_val) {
302 int index = lpc.lpc_order - 1;
303 int neg = (res_val < 0);
304
305 while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {
306 int val = samples[0] - samples[lpc.lpc_order - index];
307 int sign = (val ? FFSIGN(val) : 0);
308
309 if (neg)
310 sign *= -1;
311
312 lpc.lpc_coeff[index] -= sign;
313 val *= sign;
314 res_val -= (val >> lpc.lpc_quant) * (lpc.lpc_order - index);
315 index--;
316 }
317 }
318 samples++;
319 }
320 }
321}
322
324{
325 unsigned int history = s->rc.initial_history;
326 int sign_modifier = 0, i, k;
327 int32_t *samples = s->predictor_buf[ch];
328
329 for (i = 0; i < s->frame_size;) {
330 int x;
331
332 k = av_log2((history >> 9) + 3);
333
334 x = -2 * (*samples) -1;
335 x ^= x >> 31;
336
337 samples++;
338 i++;
339
340 encode_scalar(s, x - sign_modifier, k, s->write_sample_size);
341
342 history += x * s->rc.history_mult -
343 ((history * s->rc.history_mult) >> 9);
344
345 sign_modifier = 0;
346 if (x > 0xFFFF)
347 history = 0xFFFF;
348
349 if (history < 128 && i < s->frame_size) {
350 unsigned int block_size = 0;
351
352 k = 7 - av_log2(history) + ((history + 16) >> 6);
353
354 while (*samples == 0 && i < s->frame_size) {
355 samples++;
356 i++;
357 block_size++;
358 }
359 encode_scalar(s, block_size, k, 16);
360 sign_modifier = (block_size <= 0xFFFF);
361 history = 0;
362 }
363
364 }
365}
366
368 enum AlacRawDataBlockType element, int instance,
369 const uint8_t *samples0, const uint8_t *samples1)
370{
371 const uint8_t *samples[2] = { samples0, samples1 };
372 int i, j, channels;
373 int prediction_type = 0;
374 PutBitContext *pb = &s->pbctx;
375
376 channels = element == TYPE_CPE ? 2 : 1;
377
378 if (s->verbatim) {
379 write_element_header(s, element, instance);
380 /* samples are channel-interleaved in verbatim mode */
381 if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S32P) {
382 int shift = 32 - s->avctx->bits_per_raw_sample;
383 const int32_t *samples_s32[2] = { (const int32_t *)samples0,
384 (const int32_t *)samples1 };
385 for (i = 0; i < s->frame_size; i++)
386 for (j = 0; j < channels; j++)
387 put_sbits(pb, s->avctx->bits_per_raw_sample,
388 samples_s32[j][i] >> shift);
389 } else {
390 const int16_t *samples_s16[2] = { (const int16_t *)samples0,
391 (const int16_t *)samples1 };
392 for (i = 0; i < s->frame_size; i++)
393 for (j = 0; j < channels; j++)
394 put_sbits(pb, s->avctx->bits_per_raw_sample,
395 samples_s16[j][i]);
396 }
397 } else {
398 s->write_sample_size = s->avctx->bits_per_raw_sample - s->extra_bits +
399 channels - 1;
400
401 init_sample_buffers(s, channels, samples);
402 write_element_header(s, element, instance);
403
404 // extract extra bits if needed
405 if (s->extra_bits) {
406 uint32_t mask = (1 << s->extra_bits) - 1;
407 for (j = 0; j < channels; j++) {
408 int32_t *extra = s->predictor_buf[j];
409 int32_t *smp = s->sample_buf[j];
410 for (i = 0; i < s->frame_size; i++) {
411 extra[i] = smp[i] & mask;
412 smp[i] >>= s->extra_bits;
413 }
414 }
415 }
416
417 if (channels == 2)
419 else
420 s->interlacing_shift = s->interlacing_leftweight = 0;
421 put_bits(pb, 8, s->interlacing_shift);
422 put_bits(pb, 8, s->interlacing_leftweight);
423
424 for (i = 0; i < channels; i++) {
426
427 put_bits(pb, 4, prediction_type);
428 put_bits(pb, 4, s->lpc[i].lpc_quant);
429
430 put_bits(pb, 3, s->rc.rice_modifier);
431 put_bits(pb, 5, s->lpc[i].lpc_order);
432 // predictor coeff. table
433 for (j = 0; j < s->lpc[i].lpc_order; j++)
434 put_sbits(pb, 16, s->lpc[i].lpc_coeff[j]);
435 }
436
437 // write extra bits if needed
438 if (s->extra_bits) {
439 for (i = 0; i < s->frame_size; i++) {
440 for (j = 0; j < channels; j++) {
441 put_bits(pb, s->extra_bits, s->predictor_buf[j][i]);
442 }
443 }
444 }
445
446 // apply lpc and entropy coding to audio samples
447 for (i = 0; i < channels; i++) {
449
450 // TODO: determine when this will actually help. for now it's not used.
451 if (prediction_type == 15) {
452 // 2nd pass 1st order filter
453 int32_t *residual = s->predictor_buf[i];
454 for (j = s->frame_size - 1; j > 0; j--)
455 residual[j] -= residual[j - 1];
456 }
458 }
459 }
460}
461
463 uint8_t * const *samples)
464{
465 PutBitContext *pb = &s->pbctx;
466 int channels = s->avctx->ch_layout.nb_channels;
467 const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[channels - 1];
468 const uint8_t *ch_map = ff_alac_channel_layout_offsets[channels - 1];
469 int ch, element, sce, cpe;
470
471 init_put_bits(pb, avpkt->data, avpkt->size);
472
473 ch = element = sce = cpe = 0;
474 while (ch < channels) {
475 if (ch_elements[element] == TYPE_CPE) {
476 write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]],
477 samples[ch_map[ch + 1]]);
478 cpe++;
479 ch += 2;
480 } else {
481 write_element(s, TYPE_SCE, sce, samples[ch_map[ch]], NULL);
482 sce++;
483 ch++;
484 }
485 element++;
486 }
487
488 put_bits(pb, 3, TYPE_END);
489 flush_put_bits(pb);
490
491 return put_bytes_output(pb);
492}
493
495{
496 int header_bits = 23 + 32 * (frame_size < DEFAULT_FRAME_SIZE);
497 return FFALIGN(header_bits + bps * ch * frame_size + 3, 8) / 8;
498}
499
501{
502 AlacEncodeContext *s = avctx->priv_data;
503 ff_lpc_end(&s->lpc_ctx);
504 return 0;
505}
506
508{
509 AlacEncodeContext *s = avctx->priv_data;
510 int ret;
511 uint8_t *alac_extradata;
512
513 avctx->frame_size = s->frame_size = DEFAULT_FRAME_SIZE;
514
515 if (avctx->sample_fmt == AV_SAMPLE_FMT_S32P) {
516 if (avctx->bits_per_raw_sample != 24)
517 av_log(avctx, AV_LOG_WARNING, "encoding as 24 bits-per-sample\n");
518 avctx->bits_per_raw_sample = 24;
519 } else {
520 avctx->bits_per_raw_sample = 16;
521 s->extra_bits = 0;
522 }
523
524 // Set default compression level
526 s->compression_level = 2;
527 else
528 s->compression_level = av_clip(avctx->compression_level, 0, 2);
529
530 // Initialize default Rice parameters
531 s->rc.history_mult = 40;
532 s->rc.initial_history = 10;
533 s->rc.k_modifier = 14;
534 s->rc.rice_modifier = 4;
535
536 s->max_coded_frame_size = get_max_frame_size(avctx->frame_size,
537 avctx->ch_layout.nb_channels,
538 avctx->bits_per_raw_sample);
539
541 if (!avctx->extradata)
542 return AVERROR(ENOMEM);
544
545 alac_extradata = avctx->extradata;
546 AV_WB32(alac_extradata, ALAC_EXTRADATA_SIZE);
547 AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c'));
548 AV_WB32(alac_extradata+12, avctx->frame_size);
549 AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample);
550 AV_WB8 (alac_extradata+21, avctx->ch_layout.nb_channels);
551 AV_WB32(alac_extradata+24, s->max_coded_frame_size);
552 AV_WB32(alac_extradata+28,
553 avctx->sample_rate * avctx->ch_layout.nb_channels * avctx->bits_per_raw_sample); // average bitrate
554 AV_WB32(alac_extradata+32, avctx->sample_rate);
555
556 // Set relevant extradata fields
557 if (s->compression_level > 0) {
558 AV_WB8(alac_extradata+18, s->rc.history_mult);
559 AV_WB8(alac_extradata+19, s->rc.initial_history);
560 AV_WB8(alac_extradata+20, s->rc.k_modifier);
561 }
562
563 if (s->max_prediction_order < s->min_prediction_order) {
564 av_log(avctx, AV_LOG_ERROR,
565 "invalid prediction orders: min=%d max=%d\n",
566 s->min_prediction_order, s->max_prediction_order);
567 return AVERROR(EINVAL);
568 }
569
570 s->avctx = avctx;
571
572 if ((ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size,
573 s->max_prediction_order,
574 FF_LPC_TYPE_LEVINSON)) < 0) {
575 return ret;
576 }
577
578 return 0;
579}
580
581static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
582 const AVFrame *frame, int *got_packet_ptr)
583{
584 AlacEncodeContext *s = avctx->priv_data;
585 int out_bytes, max_frame_size, ret;
586
587 s->frame_size = frame->nb_samples;
588
589 if (frame->nb_samples < DEFAULT_FRAME_SIZE)
590 max_frame_size = get_max_frame_size(s->frame_size, avctx->ch_layout.nb_channels,
591 avctx->bits_per_raw_sample);
592 else
593 max_frame_size = s->max_coded_frame_size;
594
595 if ((ret = ff_alloc_packet(avctx, avpkt, 4 * max_frame_size)) < 0)
596 return ret;
597
598 /* use verbatim mode for compression_level 0 */
599 if (s->compression_level) {
600 s->verbatim = 0;
601 s->extra_bits = avctx->bits_per_raw_sample - 16;
602 } else {
603 s->verbatim = 1;
604 s->extra_bits = 0;
605 }
606
607 out_bytes = write_frame(s, avpkt, frame->extended_data);
608
609 if (out_bytes > max_frame_size) {
610 /* frame too large. use verbatim mode */
611 s->verbatim = 1;
612 s->extra_bits = 0;
613 out_bytes = write_frame(s, avpkt, frame->extended_data);
614 }
615
616 avpkt->size = out_bytes;
617 *got_packet_ptr = 1;
618 return 0;
619}
620
621#define OFFSET(x) offsetof(AlacEncodeContext, x)
622#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
623static const AVOption options[] = {
624 { "min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MIN_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
625 { "max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MAX_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
626
627 { NULL },
628};
629
630static const AVClass alacenc_class = {
631 .class_name = "alacenc",
632 .item_name = av_default_item_name,
633 .option = options,
634 .version = LIBAVUTIL_VERSION_INT,
635};
636
638 .p.name = "alac",
639 CODEC_LONG_NAME("ALAC (Apple Lossless Audio Codec)"),
640 .p.type = AVMEDIA_TYPE_AUDIO,
641 .p.id = AV_CODEC_ID_ALAC,
644 .priv_data_size = sizeof(AlacEncodeContext),
645 .p.priv_class = &alacenc_class,
646 .init = alac_encode_init,
648 .close = alac_encode_close,
651};
@ TYPE_CPE
Definition aac.h:45
@ TYPE_SCE
Definition aac.h:44
@ TYPE_END
Definition aac.h:51
static double val(void *priv, double ch)
Definition aeval.c:77
static const int ch_map[SC_NB]
Definition af_surround.c:37
#define ALAC_EXTRADATA_SIZE
Definition alac.c:63
enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5]
Definition alac_data.c:47
const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS+1]
Definition alac_data.c:35
const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS]
Definition alac_data.c:24
AlacRawDataBlockType
Definition alac_data.h:28
#define ALAC_CHMODE_LEFT_RIGHT
Definition alacenc.c:46
#define AE
Definition alacenc.c:622
#define COPY_SAMPLES(type)
#define ALAC_MAX_LPC_ORDER
Definition alacenc.c:39
const FFCodec ff_alac_encoder
Definition alacenc.c:637
static int write_frame(AlacEncodeContext *s, AVPacket *avpkt, uint8_t *const *samples)
Definition alacenc.c:462
static const AVClass alacenc_class
Definition alacenc.c:630
static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
Definition alacenc.c:186
static av_always_inline int get_max_frame_size(int frame_size, int ch, int bps)
Definition alacenc.c:494
static void calc_predictor_params(AlacEncodeContext *s, int ch)
Definition alacenc.c:155
static av_cold int alac_encode_init(AVCodecContext *avctx)
Definition alacenc.c:507
#define DEFAULT_MIN_PRED_ORDER
Definition alacenc.c:41
static void write_element(AlacEncodeContext *s, enum AlacRawDataBlockType element, int instance, const uint8_t *samples0, const uint8_t *samples1)
Definition alacenc.c:367
static void init_sample_buffers(AlacEncodeContext *s, int channels, const uint8_t *samples[2])
Definition alacenc.c:86
static void alac_stereo_decorrelation(AlacEncodeContext *s)
Definition alacenc.c:219
static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition alacenc.c:581
static void write_element_header(AlacEncodeContext *s, enum AlacRawDataBlockType element, int instance)
Definition alacenc.c:136
static av_cold int alac_encode_close(AVCodecContext *avctx)
Definition alacenc.c:500
#define ALAC_MAX_LPC_SHIFT
Definition alacenc.c:44
static void alac_linear_predictor(AlacEncodeContext *s, int ch)
Definition alacenc.c:259
static void alac_entropy_coder(AlacEncodeContext *s, int ch)
Definition alacenc.c:323
#define ALAC_CHMODE_LEFT_SIDE
Definition alacenc.c:47
#define OFFSET(x)
Definition alacenc.c:621
#define DEFAULT_MAX_PRED_ORDER
Definition alacenc.c:40
static void encode_scalar(AlacEncodeContext *s, int x, int k, int write_sample_size)
Definition alacenc.c:108
#define ALAC_MIN_LPC_SHIFT
Definition alacenc.c:43
#define DEFAULT_FRAME_SIZE
Definition alacenc.c:33
#define ALAC_MAX_LPC_PRECISION
Definition alacenc.c:42
#define ALAC_CHMODE_RIGHT_SIDE
Definition alacenc.c:48
#define ALAC_ESCAPE_CODE
Definition alacenc.c:38
channels
Definition aptx.h:31
int32_t
Libavcodec external API header.
#define FF_COMPRESSION_DEFAULT
Definition avcodec.h:1242
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
#define CODEC_CH_LAYOUTS_ARRAY(array)
#define av_clip
Definition common.h:100
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define FFSIGN(a)
Definition common.h:75
#define NULL
Definition coverity.c:32
static AVFrame * frame
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition encode.c:62
static const uint8_t frame_size[4]
Definition g723_1.h:222
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition codec.h:84
@ AV_CODEC_ID_ALAC
Definition codec_id.h:469
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:108
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition samplefmt.h:64
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition samplefmt.h:65
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int index
Definition gxfenc.c:90
#define r
Definition input.c:42
#define av_log2
Definition intmath.h:84
#define AV_WB32(p, v)
#define AV_WB8(p, d)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154
static int shift(int a, int b)
Definition bonk.c:261
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
Definition lpc.c:367
int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int min_shift, int max_shift, int zero_shift)
Calculate LPC coefficients for multiple orders.
Definition lpc.c:240
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
Definition lpc.c:342
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
#define ORDER_METHOD_EST
Definition lpc.h:29
#define MAX_LPC_ORDER
Definition lpc.h:37
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
Definition lpc.h:46
#define MIN_LPC_ORDER
Definition lpc.h:36
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMIN(a, b)
Definition macros.h:49
#define MKBETAG(a, b, c, d)
Definition macros.h:56
#define FFALIGN(x, a)
Definition macros.h:78
static av_const int sign_extend(int val, unsigned bits)
Definition mathops.h:135
Memory handling functions.
unsigned bps
Definition movenc.c:2074
AVOptions.
bitstream writer API
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition put_bits.h:291
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition put_bits.h:62
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition put_bits.h:153
static int put_bytes_output(const PutBitContext *s)
Definition put_bits.h:99
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition put_bits.h:301
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1047
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
int sample_rate
samples per second
Definition avcodec.h:1040
int compression_level
Definition avcodec.h:1241
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
int extradata_size
Definition avcodec.h:527
int frame_size
Number of samples per channel in an audio frame.
Definition avcodec.h:1068
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
AlacLPCContext lpc[2]
Definition alacenc.c:81
int interlacing_leftweight
Definition alacenc.c:78
int frame_size
current frame size
Definition alacenc.c:67
LPCContext lpc_ctx
Definition alacenc.c:82
int write_sample_size
Definition alacenc.c:73
int compression_level
Definition alacenc.c:69
int max_prediction_order
Definition alacenc.c:71
AVCodecContext * avctx
Definition alacenc.c:66
int interlacing_shift
Definition alacenc.c:77
PutBitContext pbctx
Definition alacenc.c:79
int min_prediction_order
Definition alacenc.c:70
int verbatim
current frame verbatim mode flag
Definition alacenc.c:68
int32_t predictor_buf[2][DEFAULT_FRAME_SIZE]
Definition alacenc.c:76
int max_coded_frame_size
Definition alacenc.c:72
RiceContext rc
Definition alacenc.c:80
int32_t sample_buf[2][DEFAULT_FRAME_SIZE]
Definition alacenc.c:75
int lpc_coeff[ALAC_MAX_LPC_ORDER+1]
Definition alacenc.c:60
int initial_history
Definition alacenc.c:53
int history_mult
Definition alacenc.c:52
int k_modifier
Definition alacenc.c:54
int rice_modifier
Definition alacenc.c:55
Definition swscale.c:71
#define av_mallocz(s)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52