1 #include "../libzmpeg3.h"
3 #ifndef MM_ACCEL_DJBFFT
4 #define MM_ACCEL_DJBFFT 0x00000001
10 stream = new bits_t(0, 0);
11 state = a52_init(MM_ACCEL_DJBFFT);
12 output = a52_samples(state);
15 zaudio_decoder_ac3_t::
16 ~audio_decoder_ac3_t()
23 /* Return 1 if it isn't an AC3 header */
24 int zaudio_decoder_ac3_t::
25 ac3_check(uint8_t *header)
27 int flags, samplerate, bitrate;
28 return !a52_syncinfo(header, &flags, &samplerate, &bitrate);
31 /* Decode AC3 header */
32 int zaudio_decoder_ac3_t::
33 ac3_header(uint8_t *header)
37 //zmsgs("%02x%02x%02x%02x%02x%02x%02x%02x\n",
38 // header[0], header[1], header[2], header[3],
39 // header[4], header[5], header[6], header[7]);
40 result = a52_syncinfo(header, &flags, &samplerate, &bitrate);
43 //zmsgs("%d\n", result);
47 if( (flags & A52_LFE) != 0 )
49 //zmsgs("%08x %08x\n", (flags & A52_LFE), (flags & A52_CHANNEL_MASK));
50 switch( (flags & A52_CHANNEL_MASK) ) {
51 case A52_CHANNEL: ++channels; break;
52 case A52_MONO: ++channels; break;
53 case A52_STEREO: channels += 2; break;
54 case A52_3F: channels += 3; break;
55 case A52_2F1R: channels += 3; break;
56 case A52_3F1R: channels += 4; break;
57 case A52_2F2R: channels += 4; break;
58 case A52_3F2R: channels += 5; break;
59 case A52_DOLBY: channels += 2; break;
61 zmsgs("unknown channel code: %08x\n", (flags & A52_CHANNEL_MASK));
65 //zmsgs("1 %d\n", channels);
70 int zaudio_decoder_ac3_t::
71 do_ac3(uint8_t *zframe, int zframe_size, float **zoutput, int render)
73 int output_position = 0;
77 a52_frame(state, zframe, &flags, &level, 0);
79 a52_dynrng(state, NULL, NULL);
81 for( i=0; i < 6; ++i ) {
82 if( !a52_block(state) ) {
85 /* Remap the channels to conform to encoders. */
86 for( j=0; j < channels; ++j ) {
88 /* Make LFE last channel. */
89 /* Shift all other channels down 1. */
90 if( (flags & A52_LFE) != 0 )
91 dst_channel = j == 0 ? channels-1 : dst_channel-1;
92 /* Swap front left and center for certain configurations */
93 switch( (flags & A52_CHANNEL_MASK) ) {
97 if( dst_channel == 0 ) dst_channel = 1;
98 else if( dst_channel == 1 ) dst_channel = 0;
102 memmove(zoutput[dst_channel]+output_position,
103 output+l, 256*sizeof(float));
107 output_position += 256;
111 return output_position;