57 #define ALAC_EXTRADATA_SIZE 36
108 int sign_modifier = 0;
118 k =
av_log2((history >> 9) + 3);
123 output_buffer[i] = (x >> 1) ^ -(x & 1);
129 history += x * rice_history_mult -
130 ((history * rice_history_mult) >> 9);
133 if ((history < 128) && (i + 1 < nb_samples)) {
137 k = 7 -
av_log2(history) + ((history + 16) >> 6);
141 if (block_size > 0) {
142 if (block_size >= nb_samples - i) {
144 "invalid zero block size of %d %d %d\n", block_size,
146 block_size = nb_samples - i - 1;
148 memset(&output_buffer[i + 1], 0,
149 block_size *
sizeof(*output_buffer));
152 if (block_size <= 0xffff)
167 int lpc_order,
int lpc_quant)
173 *buffer_out = *error_buffer;
179 memcpy(&buffer_out[1], &error_buffer[1],
180 (nb_samples - 1) *
sizeof(*buffer_out));
184 if (lpc_order == 31) {
187 buffer_out[i] =
sign_extend(buffer_out[i - 1] + error_buffer[i],
194 for (i = 1; i <= lpc_order && i <
nb_samples; i++)
195 buffer_out[i] =
sign_extend(buffer_out[i - 1] + error_buffer[i], bps);
202 int error_val = error_buffer[i];
207 for (j = 0; j < lpc_order; j++)
208 val += (pred[j] - d) * lpc_coefs[j];
209 val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
210 val += d + error_val;
216 for (j = 0; j < lpc_order && error_val * error_sign > 0; j++) {
220 lpc_coefs[j] -= sign;
222 error_val -= (val >> lpc_quant) * (j + 1);
229 int decorr_shift,
int decorr_left_weight)
239 a -= (b * decorr_left_weight) >> decorr_shift;
252 for (ch = 0; ch < channels; ch++)
254 buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i];
261 int has_size,
bps, is_compressed, decorr_shift, decorr_left_weight, ret;
262 uint32_t output_samples;
297 }
else if (output_samples != alac->
nb_samples) {
304 for (ch = 0; ch < channels; ch++)
309 int16_t lpc_coefs[2][32];
311 int prediction_type[2];
313 int rice_history_mult[2];
318 for (ch = 0; ch < channels; ch++) {
321 rice_history_mult[ch] =
get_bits(&alac->
gb, 3);
325 for (i = lpc_order[ch] - 1; i >= 0; i--)
333 for (ch = 0; ch < channels; ch++)
337 for (ch = 0; ch < channels; ch++) {
345 if (prediction_type[ch] == 15) {
356 }
else if (prediction_type[ch] > 0) {
358 prediction_type[ch]);
362 bps, lpc_coefs[ch], lpc_order[ch], lpc_quant[ch]);
369 for (ch = 0; ch < channels; ch++) {
376 decorr_left_weight = 0;
379 if (channels == 2 && decorr_left_weight) {
381 decorr_shift, decorr_left_weight);
392 for (ch = 0; ch < channels; ch++) {
399 for (ch = 0; ch < channels; ch++) {
410 for (ch = 0; ch < channels; ch++)
412 outbuffer += alac->
channels - channels;
419 for (ch = 0; ch < channels; ch++)
421 outbuffer += alac->
channels - channels;
428 for (ch = 0; ch < channels; ch++)
430 outbuffer += alac->
channels - channels;
441 int *got_frame_ptr,
AVPacket *avpkt)
446 int ch, ret, got_end;
464 channels = (element ==
TYPE_CPE) ? 2 : 1;
522 buf_size, buf_alloc_fail);
527 buf_size, buf_alloc_fail);
531 buf_size, buf_alloc_fail);
558 alac->
rice_limit = bytestream2_get_byteu(&gb);
559 alac->
channels = bytestream2_get_byteu(&gb);
560 bytestream2_get_be16u(&gb);
561 bytestream2_get_be32u(&gb);
562 bytestream2_get_be32u(&gb);
563 bytestream2_get_be32u(&gb);