Revision a7a85899 libavcodec/mpegaudiodec.c

View differences:

libavcodec/mpegaudiodec.c
99 99
#endif
100 100
    void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
101 101
    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
102
    unsigned int dither_state;
102 103
} MPADecodeContext;
103 104

  
104 105
/* layer 3 "granule" */
......
749 750

  
750 751
#if FRAC_BITS <= 15
751 752

  
752
static inline int round_sample(int sum)
753
static inline int round_sample(int *sum)
753 754
{
754 755
    int sum1;
755
    sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;
756
    sum1 = (*sum) >> OUT_SHIFT;
757
    *sum &= (1<<OUT_SHIFT)-1;
756 758
    if (sum1 < -32768)
757 759
        sum1 = -32768;
758 760
    else if (sum1 > 32767)
......
782 784

  
783 785
#else
784 786

  
785
static inline int round_sample(int64_t sum) 
787
static inline int round_sample(int64_t *sum) 
786 788
{
787 789
    int sum1;
788
    sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);
790
    sum1 = (int)((*sum) >> OUT_SHIFT);
791
    *sum &= (1<<OUT_SHIFT)-1;
789 792
    if (sum1 < -32768)
790 793
        sum1 = -32768;
791 794
    else if (sum1 > 32767)
......
900 903
    w = window;
901 904
    w2 = window + 31;
902 905

  
903
    sum = 0;
906
    sum = s1->dither_state;
904 907
    p = synth_buf + 16;
905 908
    SUM8(sum, +=, w, p);
906 909
    p = synth_buf + 48;
907 910
    SUM8(sum, -=, w + 32, p);
908
    *samples = round_sample(sum);
911
    *samples = round_sample(&sum);
909 912
    samples += incr;
910 913
    w++;
911 914

  
912 915
    /* we calculate two samples at the same time to avoid one memory
913 916
       access per two sample */
914 917
    for(j=1;j<16;j++) {
915
        sum = 0;
916 918
        sum2 = 0;
917 919
        p = synth_buf + 16 + j;
918 920
        SUM8P2(sum, +=, sum2, -=, w, w2, p);
919 921
        p = synth_buf + 48 - j;
920 922
        SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
921 923

  
922
        *samples = round_sample(sum);
924
        *samples = round_sample(&sum);
923 925
        samples += incr;
924
        *samples2 = round_sample(sum2);
926
        sum += sum2;
927
        *samples2 = round_sample(&sum);
925 928
        samples2 -= incr;
926 929
        w++;
927 930
        w2--;
928 931
    }
929 932
    
930 933
    p = synth_buf + 32;
931
    sum = 0;
932 934
    SUM8(sum, -=, w + 32, p);
933
    *samples = round_sample(sum);
935
    *samples = round_sample(&sum);
936
    s1->dither_state= sum;
934 937

  
935 938
    offset = (offset - 32) & 511;
936 939
    *synth_buf_offset = offset;
......
1115 1118
    out[8 - 4] = t1;
1116 1119
}
1117 1120

  
1118
/* fast header check for resync */
1119
static int check_header(uint32_t header)
1120
{
1121
    /* header */
1122
    if ((header & 0xffe00000) != 0xffe00000)
1123
	return -1;
1124
    /* layer check */
1125
    if (((header >> 17) & 3) == 0)
1126
	return -1;
1127
    /* bit rate */
1128
    if (((header >> 12) & 0xf) == 0xf)
1129
	return -1;
1130
    /* frequency */
1131
    if (((header >> 10) & 3) == 3)
1132
	return -1;
1133
    return 0;
1134
}
1135

  
1136
/* header + layer + bitrate + freq + lsf/mpeg25 */
1137
#define SAME_HEADER_MASK \
1138
   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
1139

  
1140 1121
/* header decoding. MUST check the header before because no
1141 1122
   consistency check is done there. Return 1 if free format found and
1142 1123
   that the frame size must be computed externally */
......
1244 1225
    MPADecodeContext s1, *s = &s1;
1245 1226
    memset( s, 0, sizeof(MPADecodeContext) );
1246 1227

  
1247
    if (check_header(head) != 0)
1228
    if (ff_mpa_check_header(head) != 0)
1248 1229
        return -1;
1249 1230

  
1250 1231
    if (decode_header(s, head) != 0) {
......
2566 2547
		header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
2567 2548
		    (s->inbuf[2] << 8) | s->inbuf[3];
2568 2549

  
2569
		if (check_header(header) < 0) {
2550
		if (ff_mpa_check_header(header) < 0) {
2570 2551
		    /* no sync found : move by one byte (inefficient, but simple!) */
2571 2552
		    memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
2572 2553
		    s->inbuf_ptr--;
......
2712 2693
    header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
2713 2694
              (s->inbuf[2] << 8) | s->inbuf[3] | 0xffe00000;
2714 2695

  
2715
    if (check_header(header) < 0) { // Bad header, discard frame
2696
    if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
2716 2697
        *data_size = 0;
2717 2698
        return buf_size;
2718 2699
    }

Also available in: Unified diff