//#define DEBUG_BITALLOC
#include "avcodec.h"
#include "bitstream.h"
+#include "crc.h"
#include "ac3.h"
typedef struct AC3EncodeContext {
#define EXP_DIFF_THRESHOLD 1000
static void fft_init(int ln);
-static void ac3_crc_init(void);
static inline int16_t fix15(float a)
{
xsin1[i] = fix15(-sin(alpha));
}
- ac3_crc_init();
-
avctx->coded_frame= avcodec_alloc_frame();
avctx->coded_frame->key_frame= 1;
}
}
-/* compute the ac3 crc */
-
#define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16))
-static void ac3_crc_init(void)
-{
- unsigned int c, n, k;
-
- for(n=0;n<256;n++) {
- c = n << 8;
- for (k = 0; k < 8; k++) {
- if (c & (1 << 15))
- c = ((c << 1) & 0xffff) ^ (CRC16_POLY & 0xffff);
- else
- c = c << 1;
- }
- crc_table[n] = c;
- }
-}
-
-static unsigned int ac3_crc(uint8_t *data, int n, unsigned int crc)
-{
- int i;
- for(i=0;i<n;i++) {
- crc = (crc_table[data[i] ^ (crc >> 8)] ^ (crc << 8)) & 0xffff;
- }
- return crc;
-}
-
static unsigned int mul_poly(unsigned int a, unsigned int b, unsigned int poly)
{
unsigned int c;
/* Now we must compute both crcs : this is not so easy for crc1
because it is at the beginning of the data... */
frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
- crc1 = ac3_crc(frame + 4, (2 * frame_size_58) - 4, 0);
+ crc1 = bswap_16(av_crc(av_crc8005, 0, frame + 4, 2 * frame_size_58 - 4));
/* XXX: could precompute crc_inv */
crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
frame[2] = crc1 >> 8;
frame[3] = crc1;
- crc2 = ac3_crc(frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2, 0);
+ crc2 = bswap_16(av_crc(av_crc8005, 0, frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2));
frame[2*frame_size - 2] = crc2 >> 8;
frame[2*frame_size - 1] = crc2;
static void init_crcs(void){
av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257);
+ av_crc8005 = av_mallocz_static(sizeof(AVCRC) * 257);
av_crc_init(av_crc04C11DB7, 0, 32, 0x04c11db7, sizeof(AVCRC)*257);
+ av_crc_init(av_crc8005 , 0, 16, 0x8005 , sizeof(AVCRC)*257);
}
/* must be called before any other functions */