📄 mp3_common.h
字号:
/* * $Copyright: * ---------------------------------------------------------------- * This confidential and proprietary software may be used only as * authorised by a licensing agreement from ARM Limited * (C) COPYRIGHT 2001,2002,2003 ARM Limited * ALL RIGHTS RESERVED * The entire notice above must be reproduced on all authorised * copies and copies may only be made to the extent permitted * by a licensing agreement from ARM Limited. * ---------------------------------------------------------------- * File: common.h,v * Revision: 1.29 * ---------------------------------------------------------------- * $ * * ISO MPEG Audio Subgroup Software Simulation Group (1996) * ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension * */#ifndef COMMON_H#define COMMON_H#include "mp3_options_c.h"#include "audiodec.h"/* * Define the XP bandwidth reduction control type. */typedef enum tagCutoffMode { eNormal, eReduced, eTest} tCutoffMode;/* * Define the sample rate type. */typedef enum tagSampleRate{ SR_11_025kHz, SR_12kHz, SR_8kHz, SR_ReservedMPEG2_5, SR_22_05kHz, SR_24kHz, SR_16kHz, SR_ReservedLSF, SR_44_1kHz, SR_48kHz, SR_32kHz, SR_Reserved} tSampleRate ;typedef struct tagMPEGHeader tMPEGHeader ;typedef tMPEGHeader *ptMPEGHeader ;struct tagMPEGHeader{ tSampleRate sample_rate ; unsigned int samplesperchannel; unsigned int numchans; unsigned int packed_info; unsigned int bits_required; unsigned int free_format;} ;/************************************************************************* Global Include Files************************************************************************/#include <stdio.h>#include <string.h>/************************************************************************* Global Definitions************************************************************************//* General Definitions */#define LAY1 3#define LAY2 2#define LAY3 1//#define FALSE 0//#define TRUE 1#define MONO 1#define STEREO 2#define SBLIMIT 32#define SSLIMIT 18#define GRANULE_SAMPLES_PER_CH 576 /* Layer III */#define MPEG1_NUM_GRANULES 2 /* MPEG-1 : number of granules (layer III) */#define MPEG2_LSF_NUM_GRANULES 1 /* MPEG-2 LSF : number of granules (layer III) */#define MAX_NUM_GRANULES 2 /* maximum number of granules (layer III) */#define MAX_NUM_CHANNELS 2#define FFT_SIZE 1024#define HAN_SIZE (512+15)#define SCALE_BLOCK 12#define SCALE_RANGE 64#define MIN_OUTPUT_SAMPLES 96#define MAX_LONG_SCALEFACTORS 23#define MAX_SHORT_SCALEFACTORS 14/* MPEG Header Definitions - ID Bit Values */#define MPEG_AUDIO_ID 1#define MPEG_VERSION_LSF_BIT 1#define MPEG_VERSION_2_5_BIT 2/* MPEG Header Definitions - Mode Values */#define MPG_MD_STEREO 0#define MPG_MD_JOINT_STEREO 1#define MPG_MD_DUAL_CHANNEL 2#define MPG_MD_MONO 3/* Mode Extension */#define MPG_MD_LR_LR 0#define MPG_MD_LR_I 1#define MPG_MD_MS_LR 2#define MPG_MD_MS_I 3#define ALIGNING 8#define BUFFER_SIZE 4096//#define MIN(A, B) ((A) < (B) ? (A) : (B))#define MAX(A, B) ((A) > (B) ? (A) : (B))/************************************************************************* Global Type Definitions************************************************************************//* Header Information Structure */typedef struct { /* do not reorder elements of this */ char version; /* structure--hardwired into */ char rlay; /* decode_packed_info() */ char error_protection; char bitrate_index; char sampling_frequency; char padding; char mode; char mode_ext;} layer;/* Parent Structure Interpreting some Frame Parameters in Header */typedef struct { layer header; /* raw header information */ char stereo; /* 1 for mono, 2 for stereo */#if INCLUDE_LAYER==LAYER1 || INCLUDE_LAYER==LAYER2 char jsbound; /* first band of joint stereo coding */#endif short samples_per_channel; int bytes_required;} frame_params;/* "bit_stream.h" Type Definitions *//* WARNING: This structure is hardwired into the optimized ARM getbits functions *//* If you change the order here, you will need to keep the assembler consistent. */typedef struct bit_stream_struc { int hold_reg; /* 32-bit bit stream holding register */ int buf_bit_idx; /* pointer to top bit of top byte in buffer */ unsigned char *buf_ptr; /* pointer within buffer (ARM code only) */} Bit_stream_struc;/* Layer III side information. */#if INCLUDE_LAYER==LAYER3#define MPEG_MISC0_LOG_PREFLAG 2#define MPEG_MISC0_LOG_SCALEFAC_SCALE 1#define MPEG_MISC0_LOG_COUNT1TABLE_SELECT 0#define MPEG_MISC0_PREFLAG 0x04#define MPEG_MISC0_SCALEFAC_SCALE 0x02#define MPEG_MISC0_COUNT1TABLE_SELECT 0x01typedef struct gr_info_s { unsigned short part2_3_length; /* 12 bits */ unsigned short big_values; /* 9 bits */ unsigned short scalefac_compress; /* MPEG-1: 4 bits, MPEG-2: 9 bits */ unsigned char global_gain; /* 8 bits */ unsigned char block_type; /* 2 bits */ unsigned char mixed_block_flag; /* 1 bit */ unsigned char pad0; unsigned short table_sel; /* 15 bits */ unsigned short subblk_gain; /* 9 bits */ unsigned char region0_count; /* 4 bits */ unsigned char region1_count; /* 3 bits */ unsigned char misc0; /* 3 bits (preflag+scalefac_scale+count1table_select) */ unsigned char pad1; unsigned short pad2; } my_gr_info;typedef struct { unsigned short main_data_begin; /* MPEG-1: 9 bits, MPEG-1: 8 bits */ unsigned char private_bits_ignore; /* MPEG-2: 5 or 3 bits, MPEG-2: 1 or 2 bits */ unsigned char pad2; struct { unsigned char scfsi3; unsigned char pad2; unsigned char pad3; unsigned char pad4; struct gr_info_s gr[MAX_NUM_GRANULES]; } ch[MAX_NUM_CHANNELS]; } III_side_info_t;/* Layer III scale factors. *//* * Scalefactor value type. * * The type III_scalefac_1 holds the scalefactor data for a single * channel. * * The format is: * * long blocks (MPEG-1) - values 0..20 are the 21 scalefactor values (including the * final zero value) * long blocks (MPEG-2) - values 0..21 are the 22 scalefactor values (including the * final zero value) * short blocks (MPEG-1) - values 0..35 are the 12x3 scalefactor values * arranged in order [sfbnum*3 + win] * (including last 3 zero values) * short blocks (MPEG-2) - values 0..38 are the 13x3 scalefactor values * arranged in order [sfbnum*3 + win] * (including last 3 zero values) * mixed blocks (MPEG-1) - values 0..7 are the 8 long scalefactor values * values 8..34 are the 9x3 short scalefactor values * (including last 3 zero values) * mixed blocks (MPEG-2) - values 0..5 are the 6 long scalefactor values * values 6..35 are the 10x3 short scalefactor values * (including last 3 zero values) */typedef struct { char z[40]; } III_scalefac_1; #endif /* LAYER3 */ /* * Overlap reorder input and output buffers. * * This assumes that channel 0 is decoded first (which it is) * because the reorder output overlays channel 0. * * Maximum overlap depends on properties of the reorder function * which depends on the sampling frequency and MPEG version. The * worst case is 48kHz whith a maximum acceptable overlap of 448 * samples. This saves 1.75k. * */#define OVERLAP_REORDER 448#if INCLUDE_LAYER==LAYER1typedef struct{ // Layer I dequantisation uses the same code as layer II, which is coded in triplets. // Hence the size of the least-significant dimension is 3. int arm_sample_out[SBLIMIT * MAX_NUM_CHANNELS][3]; } LayerI_Scratch;typedef struct{ unsigned char bit_alloc[SBLIMIT * MAX_NUM_CHANNELS]; unsigned short scale_index[SBLIMIT * MAX_NUM_CHANNELS]; char bit_position;} LayerI_State;#endif#if INCLUDE_LAYER==LAYER2typedef struct{ const char *bs_beginCRC; const char *bs_endCRC; unsigned int bs_endCRC_bitidx;} LayerII_Scratch;typedef struct{ char tab_num; char sblimit; char prev_sblimit; char bit_position; char block_i; char padding[3]; unsigned char bit_alloc[SBLIMIT+2][MAX_NUM_CHANNELS]; unsigned short scale_index[SBLIMIT][MAX_NUM_CHANNELS][3]; // coded in triplets int arm_sample_out[SBLIMIT * MAX_NUM_CHANNELS][3]; // coded in triplets} LayerII_State;#endif#if INCLUDE_LAYER==LAYER3typedef struct{ III_scalefac_1 III_scalefac1[2]; III_side_info_t III_side_info; int inre_buf[GRANULE_SAMPLES_PER_CH-OVERLAP_REORDER + GRANULE_SAMPLES_PER_CH*2];} LayerIII_Scratch;typedef struct{ unsigned int offset; unsigned int buf_byte_idx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -