29 #define DEFAULT_FRAME_SIZE 4096
30 #define ALAC_EXTRADATA_SIZE 36
31 #define ALAC_FRAME_HEADER_SIZE 55
32 #define ALAC_FRAME_FOOTER_SIZE 3
34 #define ALAC_ESCAPE_CODE 0x1FF
35 #define ALAC_MAX_LPC_ORDER 30
36 #define DEFAULT_MAX_PRED_ORDER 6
37 #define DEFAULT_MIN_PRED_ORDER 4
38 #define ALAC_MAX_LPC_PRECISION 9
39 #define ALAC_MAX_LPC_SHIFT 9
41 #define ALAC_CHMODE_LEFT_RIGHT 0
42 #define ALAC_CHMODE_LEFT_SIDE 1
43 #define ALAC_CHMODE_RIGHT_SIDE 2
44 #define ALAC_CHMODE_MID_SIDE 3
87 #define COPY_SAMPLES(type) do { \
88 for (ch = 0; ch < channels; ch++) { \
89 int32_t *bptr = s->sample_buf[ch]; \
90 const type *sptr = (const type *)samples[ch]; \
91 for (i = 0; i < s->frame_size; i++) \
92 bptr[i] = sptr[i] >> shift; \
103 int k,
int write_sample_size)
108 divisor = (1<<k) - 1;
175 memcpy(s->
lpc[ch].
lpc_coeff, coefs[opt_order-1], opt_order*
sizeof(
int));
187 sum[0] = sum[1] = sum[2] = sum[3] = 0;
188 for (i = 2; i <
n; i++) {
189 lt = left_ch[i] - 2 * left_ch[i - 1] + left_ch[i - 2];
190 rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];
191 sum[2] +=
FFABS((lt + rt) >> 1);
192 sum[3] +=
FFABS(lt - rt);
198 score[0] = sum[0] + sum[1];
199 score[1] = sum[0] + sum[3];
200 score[2] = sum[1] + sum[3];
201 score[3] = sum[2] + sum[3];
205 for (i = 1; i < 4; i++) {
206 if (score[i] < score[best])
226 for (i = 0; i <
n; i++)
227 right[i] = left[i] - right[i];
232 for (i = 0; i <
n; i++) {
234 right[i] = left[i] - right[i];
235 left[i] = tmp + (right[i] >> 31);
241 for (i = 0; i <
n; i++) {
243 left[i] = (tmp + right[i]) >> 1;
244 right[i] = tmp - right[i];
275 residual[0] = samples[0];
281 int sum = 1 << (lpc.
lpc_quant - 1), res_val, j;
284 sum += (samples[lpc.
lpc_order-j] - samples[0]) *
292 res_val = residual[i];
296 int neg = (res_val < 0);
298 while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {
300 int sign = (val ?
FFSIGN(val) : 0);
319 int sign_modifier = 0, i, k;
325 k =
av_log2((history >> 9) + 3);
327 x = -2 * (*samples) -1;
343 unsigned int block_size = 0;
345 k = 7 -
av_log2(history) + ((history + 16) >> 6);
347 while (*samples == 0 && i < s->frame_size) {
353 sign_modifier = (block_size <= 0xFFFF);
364 uint8_t const *samples[2] = { samples0, samples1 };
366 int prediction_type = 0;
369 channels = element ==
TYPE_CPE ? 2 : 1;
379 for (j = 0; j < channels; j++)
381 samples_s32[j][i] >> shift);
383 int16_t
const *samples_s16[2] = { (
const int16_t *)samples0,
384 (
const int16_t *)samples1 };
386 for (j = 0; j < channels; j++)
400 for (j = 0; j < channels; j++) {
404 extra[i] = smp[i] &
mask;
417 for (i = 0; i < channels; i++) {
433 for (j = 0; j < channels; j++) {
440 for (i = 0; i < channels; i++) {
444 if (prediction_type == 15) {
448 residual[j] -= residual[j - 1];
461 int ch, element, sce, cpe;
465 ch = element = sce = cpe = 0;
466 while (ch < s->avctx->channels) {
467 if (ch_elements[element] ==
TYPE_CPE) {
469 samples[ch_map[ch + 1]]);
489 return FFALIGN(header_bits + bps * ch * frame_size + 3, 8) / 8;
587 "invalid prediction orders: min=%d max=%d\n",
611 int out_bytes, max_frame_size,
ret;
635 if (out_bytes > max_frame_size) {
642 avpkt->
size = out_bytes;