30 #define DEFAULT_FRAME_SIZE 4096
31 #define ALAC_EXTRADATA_SIZE 36
32 #define ALAC_FRAME_HEADER_SIZE 55
33 #define ALAC_FRAME_FOOTER_SIZE 3
35 #define ALAC_ESCAPE_CODE 0x1FF
36 #define ALAC_MAX_LPC_ORDER 30
37 #define DEFAULT_MAX_PRED_ORDER 6
38 #define DEFAULT_MIN_PRED_ORDER 4
39 #define ALAC_MAX_LPC_PRECISION 9
40 #define ALAC_MAX_LPC_SHIFT 9
42 #define ALAC_CHMODE_LEFT_RIGHT 0
43 #define ALAC_CHMODE_LEFT_SIDE 1
44 #define ALAC_CHMODE_RIGHT_SIDE 2
45 #define ALAC_CHMODE_MID_SIDE 3
88 #define COPY_SAMPLES(type) do { \
89 for (ch = 0; ch < channels; ch++) { \
90 int32_t *bptr = s->sample_buf[ch]; \
91 const type *sptr = (const type *)samples[ch]; \
92 for (i = 0; i < s->frame_size; i++) \
93 bptr[i] = sptr[i] >> shift; \
104 int k,
int write_sample_size)
109 divisor = (1<<k) - 1;
176 memcpy(s->
lpc[ch].
lpc_coeff, coefs[opt_order-1], opt_order*
sizeof(
int));
188 sum[0] = sum[1] = sum[2] = sum[3] = 0;
189 for (i = 2; i < n; i++) {
190 lt = left_ch[i] - 2 * left_ch[i - 1] + left_ch[i - 2];
191 rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];
192 sum[2] +=
FFABS((lt + rt) >> 1);
193 sum[3] +=
FFABS(lt - rt);
199 score[0] = sum[0] + sum[1];
200 score[1] = sum[0] + sum[3];
201 score[2] = sum[1] + sum[3];
202 score[3] = sum[2] + sum[3];
206 for (i = 1; i < 4; i++) {
207 if (score[i] < score[best])
227 for (i = 0; i < n; i++)
228 right[i] = left[i] - right[i];
233 for (i = 0; i < n; i++) {
235 right[i] = left[i] - right[i];
236 left[i] = tmp + (right[i] >> 31);
242 for (i = 0; i < n; i++) {
244 left[i] = (tmp + right[i]) >> 1;
245 right[i] = tmp - right[i];
276 residual[0] = samples[0];
278 residual[i] = samples[i] - samples[i-1];
282 int sum = 1 << (lpc.
lpc_quant - 1), res_val, j;
285 sum += (samples[lpc.
lpc_order-j] - samples[0]) *
293 res_val = residual[i];
297 int neg = (res_val < 0);
299 while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {
301 int sign = (val ?
FFSIGN(val) : 0);
320 int sign_modifier = 0, i, k;
326 k =
av_log2((history >> 9) + 3);
328 x = -2 * (*samples) -1;
344 unsigned int block_size = 0;
346 k = 7 -
av_log2(history) + ((history + 16) >> 6);
348 while (*samples == 0 && i < s->frame_size) {
354 sign_modifier = (block_size <= 0xFFFF);
367 int prediction_type = 0;
370 channels = element ==
TYPE_CPE ? 2 : 1;
380 for (j = 0; j < channels; j++)
382 samples_s32[j][i] >> shift);
384 int16_t
const *samples_s16[2] = { (
const int16_t *)samples0,
385 (
const int16_t *)samples1 };
387 for (j = 0; j < channels; j++)
405 for (i = 0; i < channels; i++) {
422 for (j = 0; j < channels; j++) {
430 for (i = 0; i < channels; i++) {
434 if (prediction_type == 15) {
450 int ch, element, sce, cpe;
454 ch = element = sce = cpe = 0;
455 while (ch < s->avctx->channels) {
456 if (ch_elements[element] ==
TYPE_CPE) {
458 samples[ch_map[ch + 1]]);
478 return FFALIGN(header_bits + bps * ch * frame_size + 3, 8) / 8;
577 "invalid prediction orders: min=%d max=%d\n",
607 int out_bytes, max_frame_size, ret;
631 if (out_bytes > max_frame_size) {
638 avpkt->
size = out_bytes;