57 #define ALAC_EXTRADATA_SIZE 36
101 int nb_samples,
int bps,
int rice_history_mult)
105 int sign_modifier = 0;
107 for (i = 0; i < nb_samples; i++) {
112 k =
av_log2((history >> 9) + 3);
117 output_buffer[i] = (x >> 1) ^ -(x & 1);
123 history += x * rice_history_mult -
124 ((history * rice_history_mult) >> 9);
127 if ((history < 128) && (i + 1 < nb_samples)) {
131 k = 7 -
av_log2(history) + ((history + 16) >> 6);
135 if (block_size > 0) {
136 if (block_size >= nb_samples - i) {
138 "invalid zero block size of %d %d %d\n", block_size,
140 block_size = nb_samples - i - 1;
142 memset(&output_buffer[i + 1], 0,
143 block_size *
sizeof(*output_buffer));
146 if (block_size <= 0xffff)
159 int nb_samples,
int bps, int16_t *lpc_coefs,
160 int lpc_order,
int lpc_quant)
166 *buffer_out = *error_buffer;
172 memcpy(&buffer_out[1], &error_buffer[1],
173 (nb_samples - 1) *
sizeof(*buffer_out));
177 if (lpc_order == 31) {
179 for (i = 1; i < nb_samples; i++) {
180 buffer_out[i] =
sign_extend(buffer_out[i - 1] + error_buffer[i],
187 for (i = 1; i <= lpc_order; i++)
188 buffer_out[i] =
sign_extend(buffer_out[i - 1] + error_buffer[i], bps);
192 for (; i < nb_samples; i++) {
195 int error_val = error_buffer[i];
200 for (j = 0; j < lpc_order; j++)
201 val += (pred[j] - d) * lpc_coefs[j];
202 val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
203 val += d + error_val;
209 for (j = 0; j < lpc_order && error_val * error_sign > 0; j++) {
213 lpc_coefs[j] -= sign;
215 error_val -= (val >> lpc_quant) * (j + 1);
222 int decorr_shift,
int decorr_left_weight)
226 for (i = 0; i < nb_samples; i++) {
232 a -= (b * decorr_left_weight) >> decorr_shift;
245 for (ch = 0; ch < channels; ch++)
246 for (i = 0; i < nb_samples; i++)
247 buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i];
254 int has_size,
bps, is_compressed, decorr_shift, decorr_left_weight, ret;
255 uint32_t output_samples;
290 }
else if (output_samples != alac->
nb_samples) {
297 for (ch = 0; ch < channels; ch++)
302 int16_t lpc_coefs[2][32];
304 int prediction_type[2];
306 int rice_history_mult[2];
310 "Compression with rice limit 0");
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--)
333 for (ch = 0; ch < channels; ch++)
337 for (ch = 0; ch < channels; ch++) {
343 if (prediction_type[ch] == 15) {
354 }
else if (prediction_type[ch] > 0) {
356 prediction_type[ch]);
360 bps, lpc_coefs[ch], lpc_order[ch], lpc_quant[ch]);
365 for (ch = 0; ch < channels; ch++) {
372 decorr_left_weight = 0;
375 if (channels == 2 && decorr_left_weight) {
377 decorr_shift, decorr_left_weight);
387 for (ch = 0; ch < channels; ch++) {
388 int16_t *outbuffer = (int16_t *)frame->
extended_data[ch_index + ch];
394 for (ch = 0; ch < channels; ch++) {
405 int *got_frame_ptr,
AVPacket *avpkt)
411 int ch, ret, got_end;
429 channels = (element ==
TYPE_CPE) ? 2 : 1;
430 if (ch + channels > alac->
channels ||
481 buf_size, buf_alloc_fail);
485 buf_size, buf_alloc_fail);
489 buf_size, buf_alloc_fail);
517 alac->
rice_limit = bytestream2_get_byteu(&gb);
518 alac->
channels = bytestream2_get_byteu(&gb);
519 bytestream2_get_be16u(&gb);
520 bytestream2_get_be32u(&gb);
521 bytestream2_get_be32u(&gb);
522 bytestream2_get_be32u(&gb);