📄 mp3_common.h
字号:
unsigned int buf_bit_idx; int prevblck[MAX_NUM_CHANNELS][SBLIMIT][SSLIMIT];} LayerIII_State;#endiftypedef union{#if INCLUDE_LAYER==LAYER1 LayerI_Scratch *lay1;#endif#if INCLUDE_LAYER==LAYER2 LayerII_Scratch *lay2;#endif#if INCLUDE_LAYER==LAYER3 LayerIII_Scratch *lay3;#endif void *ptr;} layer_scratch_p;typedef union{#if INCLUDE_LAYER==LAYER1 LayerI_State lay1;#endif#if INCLUDE_LAYER==LAYER2 LayerII_State lay2;#endif#if INCLUDE_LAYER==LAYER3 LayerIII_State lay3;#endif} layer_state;/* * Decoder instance data * * Note: Left and right channels have independent v_bufOfs values. This * may not be strictly necessary, but as implemented it allows the * bitstream to switch between mono and stereo modes with less-noticeable * artifacts. * */typedef struct tagMPEGInstance{#if INCLUDE_LAYER==LAYER3 unsigned short hbitbucket[BITBUCKET_SIZE/2];#endif unsigned int arm_v[MAX_NUM_CHANNELS][HAN_SIZE]; /* Referenced from assembly */ unsigned char v_bufOfs[MAX_NUM_CHANNELS]; /* Referenced from assembly */ unsigned short pad1; int freeform_length;#if ENABLECRC unsigned int crc_hdr_data;#endif unsigned int samples_buffered; /* used when returning less than a frame of PCM samples */#ifdef TRADEOFF int sblimit;#endif #if INCLUDE_LAYER == LAYER3 int *hybridin[2]; /* spare pointer to internal buffers so synthesis can be deferred */#endif#if INCLUDE_LAYER == LAYER3 int nSlots;#endif int gr; tOutputFormats outputFormats; frame_params fr_ps; layer_scratch_p scratch; /* * layer_data MUST be at the end of the structure. This is so that a decoder that * is capable of decoding more than one layer only requires the amount of RAM used * be the current layer. * * Also, note that the above data in the structure is all state. The workspace is * in layer_data, so it must be at the end so we can guarantee that the workspace * is at the end of tMPEGInstance. */ layer_state layer;} tMPEGInstance;typedef struct{ unsigned short l[MAX_LONG_SCALEFACTORS]; // MAX_LONG_SCALEFACTORS = 23 unsigned char s[MAX_SHORT_SCALEFACTORS]; // MAX_SHORT_SCALEFACTORS = 14} tsfBandType;extern const tsfBandType sfBandIndex[];/************************************************************************* Global Variable External Declarations************************************************************************//* [layer][samplerate]*/extern const unsigned short s_freq_short[3][4];/* [MPEG1/2][samplerate][bitrate] */extern const unsigned char bitrate_div_2[2][3][15];extern const int synthesis_win[256];#if INCLUDE_LAYER==LAYER2 #ifdef __APCS_ROPI extern const short deqb_tables[5]; #else extern const int deqb_tables[5]; #endifextern const char sblim_tab[5];#endif#if INCLUDE_LAYER==LAYER3extern const unsigned int power4_3tab[1039+15]; // see powertab.c//extern const int *const imdct_windows[4];extern const int imdct_windows[4];extern const int imdct_win_0[36*3];#endif/************************************************************************* Global Function Prototype Declarations************************************************************************//* Internal functions */extern unsigned int getbits(Bit_stream_struc*, int);extern void skipbits(Bit_stream_struc*, int);extern void rewindbits(Bit_stream_struc*, int);extern unsigned int sstell(Bit_stream_struc*, const unsigned char *bs_buf);extern int I_CRC_calc(tMPEGInstance *, sDecoderBitstream *bs);extern int II_CRC_calc(tMPEGInstance *);extern void clear_unused_samps(tMPEGInstance *);#if INCLUDE_LAYER==LAYER3extern unsigned int hgetbits(tMPEGInstance*, int);extern void hskipbits(tMPEGInstance *Instance, int N);extern unsigned int hssize(tMPEGInstance*);extern unsigned int hsbits(tMPEGInstance*);extern void hfillbuffer(tMPEGInstance*, sDecoderBitstream*, int nbytes);extern void rewindNbits(tMPEGInstance*, int N );#endif /* LAYER3 */typedef struct{ unsigned int holdreg; unsigned int bit_idx; unsigned int buf_ptr; unsigned int value;} fast_getbits_struc;__inline fast_getbits_struc initfastgetbits(sDecoderBitstream* bitstream){ unsigned int addr; unsigned int data;#ifndef __BIG_ENDIAN unsigned int temp;#endif fast_getbits_struc x; addr = (unsigned int)(bitstream->data + bitstream->dataOffset); x.buf_ptr = addr & ~3; data = *((unsigned int *)x.buf_ptr);#ifndef __BIG_ENDIAN temp = data ^ ((data << 16) | (data >> 16)); // EOR temp, data, data, ROR #16 temp &= ~0xFF0000; // BIC temp, temp, #0xFF0000 data = (data << 24) | (data >> 8); // MOV data, data, ROR #8 data = data ^ (temp >> 8); // EOR data, data, temp, LSR#8#endif x.holdreg = data; x.bit_idx = 32 - (8*(addr&3)); return x;}__inline void finfastgetbits(fast_getbits_struc x){ unsigned int addr; sDecoderBitstream *bitstream = (sDecoderBitstream *)x.value; addr = x.buf_ptr + ((32-x.bit_idx)>>3); bitstream->dataOffset = (char *)addr - bitstream->data;}extern __value_in_regs fast_getbits_struc fastgetbits(fast_getbits_struc);extern __value_in_regs fast_getbits_struc fastget1bit(fast_getbits_struc);#if 0// -------------------------------------------------------------- // The following obsolete code assumes big-endian bitstream input./* Declare and initialise local bitstream variables */#define INIT_GETBITS_INLINE(b) unsigned int holdreg = b->hold_reg; int bit_idx = b->buf_bit_idx, *buf_ptr = (int*)b->buf_ptr/* Resynchronise bitstream after inline access */#define FIN_GETBITS_INLINE(b) { Bit_stream_struc *bb=b; bb->hold_reg = holdreg; bb->buf_bit_idx = bit_idx; bb->buf_ptr = (unsigned char*)buf_ptr; }/* Extract and sign-extend n bits to target variable. */#ifndef __thumb/* Optimal ARM implementation */#define GETBITS_INLINE(target, n) \{ \ int tmp, tmp2;\\ __asm \ { \ RSB tmp, bit_idx, 32; \ MOV target, holdreg, LSL tmp; \ SUBS bit_idx, bit_idx, n; \\ RSB tmp2, n, 32; /* NOTE: may produce 2 instructions if n is numeric */ \\ LDRLT holdreg, [buf_ptr, 4]!; \ ADDLT bit_idx, bit_idx, 32; \ SUBLT tmp, bit_idx, tmp2; \ ORRLT target, target, holdreg, LSR tmp; \ } \ target >>= tmp2; \}#else/* The following produces equivalent code, but is slightly less efficient. */#define GETBITS_INLINE(target, n) \{ \ int tmp; \ \ bit_idx = 32 - bit_idx; \ target = holdreg << bit_idx; \ tmp = 32 - n; \ if ( (bit_idx = tmp - bit_idx) < 0 ) \ { \ holdreg = *(++buf_ptr); \ bit_idx += 32; \ target |= (holdreg >> (bit_idx - tmp)); \ } \ target >>= tmp; \}#endif/* Extract n bits into top of target variable. */#ifndef __thumb/* Optimal ARM implementation */#define GETBITS_INLINE_L1(target, n) \{ \ int tmp, tmp2;\\ __asm \ { \ RSB tmp, bit_idx, 32; \ MOV target, holdreg, LSL tmp; \ SUBS bit_idx, bit_idx, n; \\ RSB tmp2, n, 32; /* NOTE: may produce 2 instructions if n is numeric */ \\ LDRLT holdreg, [buf_ptr, 4]!; \ ADDLT bit_idx, bit_idx, 32; \ SUBLT tmp, bit_idx, tmp2; \ ORRLT target, target, holdreg, LSR tmp; \ } \ target >>= tmp2; \ target++; \ target <<= tmp2; \}#else/* The following produces equivalent code, but is slightly less efficient. */#define GETBITS_INLINE_L1(target, n) \{ \ int tmp; \ \ bit_idx = 32 - bit_idx; \ target = holdreg << bit_idx; \ tmp = 32 - n; \ if ( (bit_idx = tmp - bit_idx) < 0 ) \ { \ holdreg = *(++buf_ptr); \ bit_idx += 32; \ target |= (holdreg >> (bit_idx - tmp)); \ } \ target >>= tmp; \ target++; \ target <<= tmp; \}#endif#else// -------------------------------------------------------------- // -- Endian independent bitstream functions.// It may be possible to achieve higher performance by updating the// disabled big-endian inline functions (above). However, the likely improvement// is small and the code size would suffer.#define GETBITS_INLINE(target, n) { target = getbits(bb, n); }#define GETBITS_INLINE_L1(target, n) { target = (getbits(bb, n)+1)<<(32-(n)); }#define INIT_GETBITS_INLINE(b) Bit_stream_struc *bb=b#define FIN_GETBITS_INLINE(b)// --#endif // -------------------------------------------------------------- Common API#define INIT_GETBITS(b) fbsp = initfastgetbits(b)#define FIN_GETBITS(b) fbsp.value=(int)b, finfastgetbits(fbsp)#define GETBITS(n) (fbsp.value=n,fbsp=fastgetbits(fbsp),fbsp.value)#define GET1BIT() (fbsp=fastget1bit(fbsp),fbsp.value)typedef struct { int quotient; int remainder; } tQuotient;#if USE_C_LIBRARY_DIVIDE == 0__value_in_regs tQuotient udivide (int denominator, int numerator);#else__inline tQuotient udivide(unsigned int d, unsigned int n){ tQuotient q; q.quotient = n / d; q.remainder = n % d; return q;}#endif#endif /* COMMON_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -