4 #include <a52dec/a52.h>
5 #include "mpeg3private.h"
6 #include "mpeg3protos.h"
11 mpeg3_ac3_t
* mpeg3_new_ac3()
13 mpeg3_ac3_t
*result
= calloc(1, sizeof(mpeg3_ac3_t
));
14 result
->stream
= mpeg3bits_new_stream(0, 0);
15 result
->state
= a52_init(0);
16 result
->output
= a52_samples(result
->state
);
20 void mpeg3_delete_ac3(mpeg3_ac3_t
*audio
)
22 mpeg3bits_delete_stream(audio
->stream
);
23 a52_free(audio
->state
);
28 /* Return 1 if it isn't an AC3 header */
29 int mpeg3_ac3_check(unsigned char *header
)
31 int flags
, samplerate
, bitrate
;
32 return !a52_syncinfo(header
,
38 /* Decode AC3 header */
39 int mpeg3_ac3_header(mpeg3_ac3_t
*audio
, unsigned char *header
)
44 //printf("mpeg3_ac3_header %02x%02x%02x%02x%02x%02x%02x%02x\n", header[0], header[1], header[2], header[3], header[4], header[5], header[6], header[7]);
45 result
= a52_syncinfo(header
,
53 //printf("%d\n", result);
54 audio
->framesize
= result
;
57 if(audio
->flags
& A52_LFE
)
60 * printf("mpeg3_ac3_header %08x %08x\n",
61 * audio->flags & A52_LFE,
62 * audio->flags & A52_CHANNEL_MASK);
64 switch(audio
->flags
& A52_CHANNEL_MASK
)
94 printf("mpeg3_ac3_header: unknown channel code: %p\n", audio
->flags
& A52_CHANNEL_MASK
);
98 //printf("mpeg3_ac3_header 1 %d\n", audio->channels);
103 int mpeg3audio_doac3(mpeg3_ac3_t
*audio
,
109 int output_position
= 0;
113 //printf("mpeg3audio_doac3 1\n");
114 a52_frame(audio
->state
,
119 //printf("mpeg3audio_doac3 2\n");
120 a52_dynrng(audio
->state
, NULL
, NULL
);
121 //printf("mpeg3audio_doac3 3\n");
122 for(i
= 0; i
< 6; i
++)
124 if(!a52_block(audio
->state
))
129 // Remap the channels to conform to encoders.
130 for(j
= 0; j
< audio
->channels
; j
++)
134 // Make LFE last channel.
135 // Shift all other channels down 1.
136 if((audio
->flags
& A52_LFE
))
139 dst_channel
= audio
->channels
- 1;
144 // Swap front left and center for certain configurations
145 switch(audio
->flags
& A52_CHANNEL_MASK
)
150 if(dst_channel
== 0) dst_channel
= 1;
152 if(dst_channel
== 1) dst_channel
= 0;
156 for(k
= 0; k
< 256; k
++)
158 output
[dst_channel
][output_position
+ k
] = ((sample_t
*)audio
->output
)[l
];
163 output_position
+= 256;
168 return output_position
;