Revision 8c5b5683

View differences:

libavcodec/mpegaudiodec.c
310 310
    static int init=0;
311 311
    int i, j, k;
312 312

  
313
    if(!init) {
313
    if (!init && !avctx->parse_only) {
314 314
        /* scale factors table for layer 1/2 */
315 315
        for(i=0;i<64;i++) {
316 316
            int shift, mod;
......
737 737

  
738 738
#if FRAC_BITS <= 15
739 739

  
740
#define OUT_SAMPLE(sum)\
741
{\
742
    int sum1;\
743
    sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;\
744
    if (sum1 < -32768)\
745
        sum1 = -32768;\
746
    else if (sum1 > 32767)\
747
        sum1 = 32767;\
748
    *samples = sum1;\
749
    samples += incr;\
740
static inline int round_sample(int sum)
741
{
742
    int sum1;
743
    sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;
744
    if (sum1 < -32768)
745
        sum1 = -32768;
746
    else if (sum1 > 32767)
747
        sum1 = 32767;
748
    return sum1;
750 749
}
751 750

  
752
#define SUM8(off, op)                           \
753
{                                               \
754
    sum op w[0 * 64 + off] * p[0 * 64];\
755
    sum op w[1 * 64 + off] * p[1 * 64];\
756
    sum op w[2 * 64 + off] * p[2 * 64];\
757
    sum op w[3 * 64 + off] * p[3 * 64];\
758
    sum op w[4 * 64 + off] * p[4 * 64];\
759
    sum op w[5 * 64 + off] * p[5 * 64];\
760
    sum op w[6 * 64 + off] * p[6 * 64];\
761
    sum op w[7 * 64 + off] * p[7 * 64];\
762
}
751
#if defined(ARCH_POWERPC_405)
752

  
753
/* signed 16x16 -> 32 multiply add accumulate */
754
#define MACS(rt, ra, rb) \
755
    asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
756

  
757
/* signed 16x16 -> 32 multiply */
758
#define MULS(ra, rb) \
759
    ({ int __rt; asm ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); __rt; })
763 760

  
764 761
#else
765 762

  
766
#define OUT_SAMPLE(sum)\
767
{\
768
    int sum1;\
769
    sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);\
770
    if (sum1 < -32768)\
771
        sum1 = -32768;\
772
    else if (sum1 > 32767)\
773
        sum1 = 32767;\
774
    *samples = sum1;\
775
    samples += incr;\
763
/* signed 16x16 -> 32 multiply add accumulate */
764
#define MACS(rt, ra, rb) rt += (ra) * (rb)
765

  
766
/* signed 16x16 -> 32 multiply */
767
#define MULS(ra, rb) ((ra) * (rb))
768

  
769
#endif
770

  
771
#else
772

  
773
static inline int round_sample(int64_t sum) 
774
{
775
    int sum1;
776
    sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);
777
    if (sum1 < -32768)
778
        sum1 = -32768;
779
    else if (sum1 > 32767)
780
        sum1 = 32767;
781
    return sum1;
776 782
}
777 783

  
778
#define SUM8(off, op)                           \
784
#define MULS(ra, rb) MUL64(ra, rb)
785

  
786
#endif
787

  
788
#define SUM8(sum, op, w, p) \
779 789
{                                               \
780
    sum op MUL64(w[0 * 64 + off], p[0 * 64]);\
781
    sum op MUL64(w[1 * 64 + off], p[1 * 64]);\
782
    sum op MUL64(w[2 * 64 + off], p[2 * 64]);\
783
    sum op MUL64(w[3 * 64 + off], p[3 * 64]);\
784
    sum op MUL64(w[4 * 64 + off], p[4 * 64]);\
785
    sum op MUL64(w[5 * 64 + off], p[5 * 64]);\
786
    sum op MUL64(w[6 * 64 + off], p[6 * 64]);\
787
    sum op MUL64(w[7 * 64 + off], p[7 * 64]);\
790
    sum op MULS((w)[0 * 64], p[0 * 64]);\
791
    sum op MULS((w)[1 * 64], p[1 * 64]);\
792
    sum op MULS((w)[2 * 64], p[2 * 64]);\
793
    sum op MULS((w)[3 * 64], p[3 * 64]);\
794
    sum op MULS((w)[4 * 64], p[4 * 64]);\
795
    sum op MULS((w)[5 * 64], p[5 * 64]);\
796
    sum op MULS((w)[6 * 64], p[6 * 64]);\
797
    sum op MULS((w)[7 * 64], p[7 * 64]);\
798
}
799

  
800
#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
801
{                                               \
802
    int tmp;\
803
    tmp = p[0 * 64];\
804
    sum1 op1 MULS((w1)[0 * 64], tmp);\
805
    sum2 op2 MULS((w2)[0 * 64], tmp);\
806
    tmp = p[1 * 64];\
807
    sum1 op1 MULS((w1)[1 * 64], tmp);\
808
    sum2 op2 MULS((w2)[1 * 64], tmp);\
809
    tmp = p[2 * 64];\
810
    sum1 op1 MULS((w1)[2 * 64], tmp);\
811
    sum2 op2 MULS((w2)[2 * 64], tmp);\
812
    tmp = p[3 * 64];\
813
    sum1 op1 MULS((w1)[3 * 64], tmp);\
814
    sum2 op2 MULS((w2)[3 * 64], tmp);\
815
    tmp = p[4 * 64];\
816
    sum1 op1 MULS((w1)[4 * 64], tmp);\
817
    sum2 op2 MULS((w2)[4 * 64], tmp);\
818
    tmp = p[5 * 64];\
819
    sum1 op1 MULS((w1)[5 * 64], tmp);\
820
    sum2 op2 MULS((w2)[5 * 64], tmp);\
821
    tmp = p[6 * 64];\
822
    sum1 op1 MULS((w1)[6 * 64], tmp);\
823
    sum2 op2 MULS((w2)[6 * 64], tmp);\
824
    tmp = p[7 * 64];\
825
    sum1 op1 MULS((w1)[7 * 64], tmp);\
826
    sum2 op2 MULS((w2)[7 * 64], tmp);\
788 827
}
789 828

  
790
#endif
791 829

  
792 830
/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
793 831
   32 samples. */
......
797 835
                         int32_t sb_samples[SBLIMIT])
798 836
{
799 837
    int32_t tmp[32];
800
    register MPA_INT *synth_buf, *p;
801
    register MPA_INT *w;
838
    register MPA_INT *synth_buf;
839
    const register MPA_INT *w, *w2, *p;
802 840
    int j, offset, v;
841
    int16_t *samples2;
803 842
#if FRAC_BITS <= 15
804
    int sum;
843
    int sum, sum2;
805 844
#else
806
    int64_t sum;
845
    int64_t sum, sum2;
807 846
#endif
808

  
847
    
809 848
    dct32(tmp, sb_samples);
810 849
    
811 850
    offset = s1->synth_buf_offset[ch];
......
826 865
    /* copy to avoid wrap */
827 866
    memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
828 867

  
868
    samples2 = samples + 31 * incr;
829 869
    w = window;
830
    for(j=0;j<16;j++) {
831
        sum = 0;
832
        p = synth_buf + 16 + j;    /* 0-15  */
833
        SUM8(0, +=);
834
        p = synth_buf + 48 - j;    /* 32-47 */
835
        SUM8(32, -=);
836
        OUT_SAMPLE(sum);
837
        w++;
838
    }
839
    
840
    p = synth_buf + 32; /* 48 */
870
    w2 = window + 31;
871

  
841 872
    sum = 0;
842
    SUM8(32, -=);
843
    OUT_SAMPLE(sum);
873
    p = synth_buf + 16;
874
    SUM8(sum, +=, w, p);
875
    p = synth_buf + 48;
876
    SUM8(sum, -=, w + 32, p);
877
    *samples = round_sample(sum);
878
    samples += incr;
844 879
    w++;
845 880

  
846
    for(j=17;j<32;j++) {
881
    /* we calculate two samples at the same time to avoid one memory
882
       access per two sample */
883
    for(j=1;j<16;j++) {
847 884
        sum = 0;
848
        p = synth_buf + 48 - j; /* 17-31 */
849
        SUM8(0, -=);
850
        p = synth_buf + 16 + j; /* 49-63 */
851
        SUM8(32, -=);
852
        OUT_SAMPLE(sum);
885
        sum2 = 0;
886
        p = synth_buf + 16 + j;
887
        SUM8P2(sum, +=, sum2, -=, w, w2, p);
888
        p = synth_buf + 48 - j;
889
        SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
890

  
891
        *samples = round_sample(sum);
892
        samples += incr;
893
        *samples2 = round_sample(sum2);
894
        samples2 -= incr;
853 895
        w++;
896
        w2--;
854 897
    }
898
    
899
    p = synth_buf + 32;
900
    sum = 0;
901
    SUM8(sum, -=, w + 32, p);
902
    *samples = round_sample(sum);
903

  
855 904
    offset = (offset - 32) & 511;
856 905
    s1->synth_buf_offset[ch] = offset;
857 906
}
......
1157 1206
    return 0;
1158 1207
}
1159 1208

  
1209
/* useful helper to get mpeg audio stream infos. Return -1 if error in
1210
   header */
1211
int mp_decode_header(int *sample_rate_ptr,
1212
                     int *nb_channels_ptr, 
1213
                     int *coded_frame_size_ptr,
1214
                     int *decoded_frame_size_ptr,
1215
                     uint32_t head)
1216
{
1217
    MPADecodeContext s1, *s = &s1;
1218
    int decoded_frame_size;
1219

  
1220
    if (check_header(head) != 0)
1221
        return -1;
1222

  
1223
    if (decode_header(s, head) != 0) {
1224
        return -1;
1225
    }
1226

  
1227
    switch(s->layer) {
1228
    case 1:
1229
        decoded_frame_size = 384;
1230
        break;
1231
    case 2:
1232
        decoded_frame_size = 1152;
1233
        break;
1234
    default:
1235
    case 3:
1236
        if (s->lsf)
1237
            decoded_frame_size = 576;
1238
        else
1239
            decoded_frame_size = 1152;
1240
        break;
1241
    }
1242

  
1243
    *sample_rate_ptr = s->sample_rate;
1244
    *nb_channels_ptr = s->nb_channels;
1245
    *coded_frame_size_ptr = s->frame_size;
1246
    *decoded_frame_size_ptr = decoded_frame_size * 2 * s->nb_channels;
1247
    return 0;
1248
}
1249

  
1160 1250
/* return the number of decoded frames */
1161 1251
static int mp_decode_layer1(MPADecodeContext *s)
1162 1252
{
......
2391 2481
                    avctx->sample_rate = s->sample_rate;
2392 2482
                    avctx->channels = s->nb_channels;
2393 2483
                    avctx->bit_rate = s->bit_rate;
2394
                    avctx->frame_size = s->frame_size;
2484
                    switch(s->layer) {
2485
                    case 1:
2486
                        avctx->frame_size = 384;
2487
                        break;
2488
                    case 2:
2489
                        avctx->frame_size = 1152;
2490
                        break;
2491
                    case 3:
2492
                        if (s->lsf)
2493
                            avctx->frame_size = 576;
2494
                        else
2495
                            avctx->frame_size = 1152;
2496
                        break;
2497
                    }
2395 2498
		}
2396 2499
	    }
2397 2500
        } else if (s->frame_size == -1) {
......
2457 2560
	    buf_ptr += len;
2458 2561
	    s->inbuf_ptr += len;
2459 2562
	    buf_size -= len;
2460
	} else {
2461
            out_size = mp_decode_frame(s, out_samples);
2563
	}
2564
    next_data:
2565
        if (s->frame_size > 0 && 
2566
            (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
2567
            if (avctx->parse_only) {
2568
                /* simply return the frame data */
2569
                *(uint8_t **)data = s->inbuf;
2570
                out_size = s->inbuf_ptr - s->inbuf;
2571
            } else {
2572
                out_size = mp_decode_frame(s, out_samples);
2573
            }
2462 2574
	    s->inbuf_ptr = s->inbuf;
2463 2575
	    s->frame_size = 0;
2464 2576
	    *data_size = out_size;
2465 2577
	    break;
2466 2578
	}
2467
    next_data:
2468
	;
2469 2579
    }
2470 2580
    return buf_ptr - buf;
2471 2581
}
......
2480 2590
    NULL,
2481 2591
    NULL,
2482 2592
    decode_frame,
2593
    CODEC_CAP_PARSE_ONLY,
2483 2594
};
2484 2595

  
2485 2596
AVCodec mp3_decoder =
......
2492 2603
    NULL,
2493 2604
    NULL,
2494 2605
    decode_frame,
2606
    CODEC_CAP_PARSE_ONLY,
2495 2607
};
2496

  
2497
#undef C1
2498
#undef C2
2499
#undef C3
2500
#undef C4
2501
#undef C5
2502
#undef C6
2503
#undef C7
2504
#undef C8
2505
#undef FRAC_BITS
2506
#undef HEADER_SIZE

Also available in: Unified diff