57 #define ALAC_EXTRADATA_SIZE 36
107 int sign_modifier = 0;
117 k =
av_log2((history >> 9) + 3);
122 output_buffer[i] = (x >> 1) ^ -(x & 1);
128 history += x * rice_history_mult -
129 ((history * rice_history_mult) >> 9);
132 if ((history < 128) && (i + 1 < nb_samples)) {
136 k = 7 -
av_log2(history) + ((history + 16) >> 6);
140 if (block_size > 0) {
141 if (block_size >= nb_samples - i) {
143 "invalid zero block size of %d %d %d\n", block_size,
145 block_size = nb_samples - i - 1;
147 memset(&output_buffer[i + 1], 0,
148 block_size *
sizeof(*output_buffer));
151 if (block_size <= 0xffff)
166 int lpc_order,
int lpc_quant)
172 *buffer_out = *error_buffer;
178 memcpy(&buffer_out[1], &error_buffer[1],
179 (nb_samples - 1) *
sizeof(*buffer_out));
183 if (lpc_order == 31) {
186 buffer_out[i] =
sign_extend(buffer_out[i - 1] + error_buffer[i],
193 for (i = 1; i <= lpc_order && i <
nb_samples; i++)
194 buffer_out[i] =
sign_extend(buffer_out[i - 1] + error_buffer[i], bps);
201 int error_val = error_buffer[i];
206 for (j = 0; j < lpc_order; j++)
207 val += (pred[j] - d) * lpc_coefs[j];
208 val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
209 val += d + error_val;
215 for (j = 0; j < lpc_order && error_val * error_sign > 0; j++) {
219 lpc_coefs[j] -= sign;
221 error_val -= (val >> lpc_quant) * (j + 1);
228 int decorr_shift,
int decorr_left_weight)
238 a -= (b * decorr_left_weight) >> decorr_shift;
251 for (ch = 0; ch < channels; ch++)
253 buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i];
260 int has_size,
bps, is_compressed, decorr_shift, decorr_left_weight, ret;
261 uint32_t output_samples;
296 }
else if (output_samples != alac->
nb_samples) {
303 for (ch = 0; ch < channels; ch++)
308 int16_t lpc_coefs[2][32];
310 int prediction_type[2];
312 int rice_history_mult[2];
317 for (ch = 0; ch < channels; ch++) {
320 rice_history_mult[ch] =
get_bits(&alac->
gb, 3);
324 for (i = lpc_order[ch] - 1; i >= 0; i--)
332 for (ch = 0; ch < channels; ch++)
336 for (ch = 0; ch < channels; ch++) {
344 if (prediction_type[ch] == 15) {
355 }
else if (prediction_type[ch] > 0) {
357 prediction_type[ch]);
361 bps, lpc_coefs[ch], lpc_order[ch], lpc_quant[ch]);
368 for (ch = 0; ch < channels; ch++) {
375 decorr_left_weight = 0;
378 if (channels == 2 && decorr_left_weight) {
380 decorr_shift, decorr_left_weight);
391 for (ch = 0; ch < channels; ch++) {
392 int16_t *outbuffer = (int16_t *)frame->
extended_data[ch_index + ch];
398 for (ch = 0; ch < channels; ch++) {
407 int16_t *outbuffer = ((int16_t *)frame->
extended_data[0]) + ch_index;
409 for (ch = 0; ch < channels; ch++)
411 outbuffer += alac->
channels - channels;
418 for (ch = 0; ch < channels; ch++)
420 outbuffer += alac->
channels - channels;
427 for (ch = 0; ch < channels; ch++)
429 outbuffer += alac->
channels - channels;
440 int *got_frame_ptr,
AVPacket *avpkt)
446 int ch, ret, got_end;
464 channels = (element ==
TYPE_CPE) ? 2 : 1;
521 buf_size, buf_alloc_fail);
526 buf_size, buf_alloc_fail);
530 buf_size, buf_alloc_fail);
557 alac->
rice_limit = bytestream2_get_byteu(&gb);
558 alac->
channels = bytestream2_get_byteu(&gb);
559 bytestream2_get_be16u(&gb);
560 bytestream2_get_be32u(&gb);
561 bytestream2_get_be32u(&gb);
562 bytestream2_get_be32u(&gb);