Revision 0187178e libavcodec/flac.c

View differences:

libavcodec/flac.c
296 296

  
297 297
static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
298 298
{
299
    int sum, i, j;
299
    int i, j;
300 300
    int coeff_prec, qlevel;
301 301
    int coeffs[pred_order];
302 302

  
......
334 334
    if (decode_residuals(s, channel, pred_order) < 0)
335 335
        return -1;
336 336

  
337
    for (i = pred_order; i < s->blocksize; i++)
338
    {
339
        sum = 0;
340
        for (j = 0; j < pred_order; j++)
341
            sum += coeffs[j] * s->decoded[channel][i-j-1];
342
        s->decoded[channel][i] += sum >> qlevel;
337
    if (s->bps > 16) {
338
        int64_t sum;
339
        for (i = pred_order; i < s->blocksize; i++)
340
        {
341
            sum = 0;
342
            for (j = 0; j < pred_order; j++)
343
                sum += (int64_t)coeffs[j] * s->decoded[channel][i-j-1];
344
            s->decoded[channel][i] += sum >> qlevel;
345
        }
346
    } else {
347
        int sum;
348
        for (i = pred_order; i < s->blocksize; i++)
349
        {
350
            sum = 0;
351
            for (j = 0; j < pred_order; j++)
352
                sum += coeffs[j] * s->decoded[channel][i-j-1];
353
            s->decoded[channel][i] += sum >> qlevel;
354
        }
343 355
    }
344 356

  
345 357
    return 0;
......
538 550
    return 0;
539 551
}
540 552

  
553
static inline int16_t shift_to_16_bits(int32_t data, int bps)
554
{
555
    if (bps == 24) {
556
        return (data >> 8);
557
    } else if (bps == 20) {
558
        return (data >> 4);
559
    } else {
560
        return data;
561
    }
562
}
563

  
541 564
static int flac_decode_frame(AVCodecContext *avctx,
542 565
                            void *data, int *data_size,
543 566
                            uint8_t *buf, int buf_size)
......
680 703
            for (j = 0; j < s->blocksize; j++)
681 704
            {
682 705
                for (i = 0; i < s->channels; i++)
683
                    *(samples++) = s->decoded[i][j];
706
                    *(samples++) = shift_to_16_bits(s->decoded[i][j], s->bps);
684 707
            }
685 708
            break;
686 709
        case LEFT_SIDE:
687 710
            assert(s->channels == 2);
688 711
            for (i = 0; i < s->blocksize; i++)
689 712
            {
690
                *(samples++) = s->decoded[0][i];
691
                *(samples++) = s->decoded[0][i] - s->decoded[1][i];
713
                *(samples++) = shift_to_16_bits(s->decoded[0][i], s->bps);
714
                *(samples++) = shift_to_16_bits(s->decoded[0][i]
715
                                              - s->decoded[1][i], s->bps);
692 716
            }
693 717
            break;
694 718
        case RIGHT_SIDE:
695 719
            assert(s->channels == 2);
696 720
            for (i = 0; i < s->blocksize; i++)
697 721
            {
698
                *(samples++) = s->decoded[0][i] + s->decoded[1][i];
699
                *(samples++) = s->decoded[1][i];
722
                *(samples++) = shift_to_16_bits(s->decoded[0][i]
723
                                              + s->decoded[1][i], s->bps);
724
                *(samples++) = shift_to_16_bits(s->decoded[1][i], s->bps);
700 725
            }
701 726
            break;
702 727
        case MID_SIDE:
......
709 734

  
710 735
#if 1 //needs to be checked but IMHO it should be binary identical
711 736
                mid -= side>>1;
712
                *(samples++) = mid + side;
713
                *(samples++) = mid;
737
                *(samples++) = shift_to_16_bits(mid + side, s->bps);
738
                *(samples++) = shift_to_16_bits(mid, s->bps);
714 739
#else
715 740

  
716 741
                mid <<= 1;

Also available in: Unified diff