123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
-
- #ifndef _AACCOMMON_H
- #define _AACCOMMON_H
- #ifdef ESP8266
- # include "pgmspace.h"
- #elif defined(ESP_PLATFORM) && __has_include(<pgm_space.h>)
- # include <pgm_space.h>
- #else
- # define PROGMEM
- # define pgm_read_byte(addr) (*(const unsigned char *)(addr))
- # define pgm_read_word(addr) (*(const unsigned short *)(addr))
- #endif
- #ifndef ESP8266
- #define AAC_ENABLE_SBR 1
- #endif
- #pragma GCC optimize ("O3")
- #include "aacdec.h"
- #include "statname.h"
- #define SYNCWORDH 0xff
- #define SYNCWORDL 0xf0
- #define MAX_NCHANS_ELEM 2
- #define ADTS_HEADER_BYTES 7
- #define NUM_SAMPLE_RATES 12
- #define NUM_DEF_CHAN_MAPS 8
- #define NUM_ELEMENTS 8
- #define MAX_NUM_PCE_ADIF 16
- #define MAX_WIN_GROUPS 8
- #define MAX_SFB_SHORT 15
- #define MAX_SF_BANDS (MAX_SFB_SHORT*MAX_WIN_GROUPS)
- #define MAX_MS_MASK_BYTES ((MAX_SF_BANDS + 7) >> 3)
- #define MAX_PRED_SFB 41
- #define MAX_TNS_FILTERS 8
- #define MAX_TNS_COEFS 60
- #define MAX_TNS_ORDER 20
- #define MAX_PULSES 4
- #define MAX_GAIN_BANDS 3
- #define MAX_GAIN_WIN 8
- #define MAX_GAIN_ADJUST 7
- #define NSAMPS_LONG 1024
- #define NSAMPS_SHORT 128
- #define NUM_SYN_ID_BITS 3
- #define NUM_INST_TAG_BITS 4
- #define EXT_SBR_DATA 0x0d
- #define EXT_SBR_DATA_CRC 0x0e
- #define IS_ADIF(p) ((p)[0] == 'A' && (p)[1] == 'D' && (p)[2] == 'I' && (p)[3] == 'F')
- #define GET_ELE_ID(p) ((AACElementID)(*(p) >> (8-NUM_SYN_ID_BITS)))
- enum {
- AAC_FF_Unknown = 0,
- AAC_FF_ADTS = 1,
- AAC_FF_ADIF = 2,
- AAC_FF_RAW = 3
- };
- enum {
- AAC_ID_INVALID = -1,
- AAC_ID_SCE = 0,
- AAC_ID_CPE = 1,
- AAC_ID_CCE = 2,
- AAC_ID_LFE = 3,
- AAC_ID_DSE = 4,
- AAC_ID_PCE = 5,
- AAC_ID_FIL = 6,
- AAC_ID_END = 7
- };
- typedef struct _AACDecInfo {
-
- void *psInfoBase;
- void *psInfoSBR;
-
-
- void *rawSampleBuf[AAC_MAX_NCHANS];
- int rawSampleBytes;
- int rawSampleFBits;
-
- unsigned char *fillBuf;
- int fillCount;
- int fillExtType;
-
- int prevBlockID;
- int currBlockID;
- int currInstTag;
- int sbDeinterleaveReqd[MAX_NCHANS_ELEM];
- int adtsBlocksLeft;
-
- int bitRate;
- int nChans;
- int sampRate;
- int profile;
- int format;
- int sbrEnabled;
- int tnsUsed;
- int pnsUsed;
- int frameCount;
- } AACDecInfo;
- AACDecInfo *AllocateBuffers(void);
- AACDecInfo *AllocateBuffersPre(void **space, int *len);
- void FreeBuffers(AACDecInfo *aacDecInfo);
- void ClearBuffer(void *buf, int nBytes);
- int UnpackADTSHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail);
- int GetADTSChannelMapping(AACDecInfo *aacDecInfo, unsigned char *buf, int bitOffset, int bitsAvail);
- int UnpackADIFHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail);
- int SetRawBlockParams(AACDecInfo *aacDecInfo, int copyLast, int nChans, int sampRate, int profile);
- int PrepareRawBlock(AACDecInfo *aacDecInfo);
- int FlushCodec(AACDecInfo *aacDecInfo);
- int DecodeNextElement(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail);
- int DecodeNoiselessData(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail, int ch);
- int Dequantize(AACDecInfo *aacDecInfo, int ch);
- int StereoProcess(AACDecInfo *aacDecInfo);
- int DeinterleaveShortBlocks(AACDecInfo *aacDecInfo, int ch);
- int PNS(AACDecInfo *aacDecInfo, int ch);
- int TNSFilter(AACDecInfo *aacDecInfo, int ch);
- int IMDCT(AACDecInfo *aacDecInfo, int ch, int chBase, short *outbuf);
- int InitSBR(AACDecInfo *aacDecInfo);
- int InitSBRPre(AACDecInfo *aacDecInfo, void **ptr, int *sz);
- void FreeSBR(AACDecInfo *aacDecInfo);
- int DecodeSBRBitstream(AACDecInfo *aacDecInfo, int chBase);
- int DecodeSBRData(AACDecInfo *aacDecInfo, int chBase, short *outbuf);
- int FlushCodecSBR(AACDecInfo *aacDecInfo);
- extern const int sampRateTab[NUM_SAMPLE_RATES];
- extern const int predSFBMax[NUM_SAMPLE_RATES];
- extern const int channelMapTab[NUM_DEF_CHAN_MAPS];
- extern const int elementNumChans[NUM_ELEMENTS];
- extern const unsigned int sfBandTotalShort[NUM_SAMPLE_RATES];
- extern const unsigned int sfBandTotalLong[NUM_SAMPLE_RATES];
- extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES];
- extern const int sfBandTabShort[76];
- extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES];
- extern const int sfBandTabLong[325];
- extern const int tnsMaxBandsShortOffset[AAC_NUM_PROFILES];
- extern const unsigned int tnsMaxBandsShort[2*NUM_SAMPLE_RATES];
- extern const unsigned int tnsMaxOrderShort[AAC_NUM_PROFILES];
- extern const int tnsMaxBandsLongOffset[AAC_NUM_PROFILES];
- extern const unsigned int tnsMaxBandsLong[2*NUM_SAMPLE_RATES];
- extern const unsigned int tnsMaxOrderLong[AAC_NUM_PROFILES];
- #endif
|