58 #define ALAC_EXTRADATA_SIZE 36
104 int nb_samples,
int bps,
int rice_history_mult)
108 int sign_modifier = 0;
110 for (i = 0; i < nb_samples; i++) {
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)
166 int nb_samples,
int bps, int16_t *lpc_coefs,
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) {
186 for (i = 1; i < nb_samples; i++) {
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);
199 for (; i < nb_samples; i++) {
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)
233 for (i = 0; i < nb_samples; i++) {
239 a -= (b * decorr_left_weight) >> decorr_shift;
252 for (ch = 0; ch < channels; ch++)
253 for (i = 0; i < nb_samples; i++)
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;
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);
327 for (i = lpc_order[ch] - 1; i >= 0; i--)
335 for (ch = 0; ch < channels; ch++)
339 for (ch = 0; ch < channels; ch++) {
347 if (prediction_type[ch] == 15) {
358 }
else if (prediction_type[ch] > 0) {
360 prediction_type[ch]);
364 bps, lpc_coefs[ch], lpc_order[ch], lpc_quant[ch]);
371 for (ch = 0; ch < channels; ch++) {
378 decorr_left_weight = 0;
381 if (channels == 2 && decorr_left_weight) {
383 decorr_shift, decorr_left_weight);
394 for (ch = 0; ch < channels; ch++) {
395 int16_t *outbuffer = (int16_t *)frame->
extended_data[ch_index + ch];
401 for (ch = 0; ch < channels; ch++) {
410 int16_t *outbuffer = ((int16_t *)frame->
extended_data[0]) + ch_index;
412 for (ch = 0; ch < channels; ch++)
414 outbuffer += alac->
channels - channels;
421 for (ch = 0; ch < channels; ch++)
423 outbuffer += alac->
channels - channels;
430 for (ch = 0; ch < channels; ch++)
432 outbuffer += alac->
channels - channels;
443 int *got_frame_ptr,
AVPacket *avpkt)
449 int ch,
ret, got_end;
468 channels = (element ==
TYPE_CPE) ? 2 : 1;
469 if (ch + channels > alac->
channels ||
523 buf_size, buf_alloc_fail);
528 buf_size, buf_alloc_fail);
532 buf_size, buf_alloc_fail);
560 alac->
rice_limit = bytestream2_get_byteu(&gb);
561 alac->
channels = bytestream2_get_byteu(&gb);
562 bytestream2_get_be16u(&gb);
563 bytestream2_get_be32u(&gb);
564 bytestream2_get_be32u(&gb);
565 bytestream2_get_be32u(&gb);