diff --git a/lib/libesp32/berry/generate/be_const_bytes.h b/lib/libesp32/berry/generate/be_const_bytes.h index 26cfc1f195af..4dd3f29b0bb7 100644 --- a/lib/libesp32/berry/generate/be_const_bytes.h +++ b/lib/libesp32/berry/generate/be_const_bytes.h @@ -1,21 +1,21 @@ /* extern binary arrays */ extern const binstance_arg3 be_const_instance_; -extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000010002FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD; diff --git a/lib/libesp32/berry/generate/be_const_bytes_def.h b/lib/libesp32/berry/generate/be_const_bytes_def.h index dfe5c73cb44a..647049ef32a6 100644 --- a/lib/libesp32/berry/generate/be_const_bytes_def.h +++ b/lib/libesp32/berry/generate/be_const_bytes_def.h @@ -1,21 +1,21 @@ /* binary arrays */ be_define_const_bytes_empty(); -be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000010002FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x0F, 0x00, 0x11, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x0B, 0x40, 0x0C, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x09, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x01, 0x40, 0x0A, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); diff --git a/tasmota/Plugins/Audio/MP3/mp3_decoder.h b/tasmota/Plugins/Audio/MP3/mp3_decoder.h index ac8e8c80f672..b6fc408cc4aa 100644 --- a/tasmota/Plugins/Audio/MP3/mp3_decoder.h +++ b/tasmota/Plugins/Audio/MP3/mp3_decoder.h @@ -51,25 +51,25 @@ enum { }; typedef struct MP3FrameInfo { - int bitrate; - int nChans; - int samprate; - int bitsPerSample; - int outputSamps; - int layer; - int version; + int32_t bitrate; + int32_t nChans; + int32_t samprate; + int32_t bitsPerSample; + int32_t outputSamps; + int32_t layer; + int32_t version; } MP3FrameInfo_t; typedef struct SFBandTable { - int/*short*/ l[23]; - int/*short*/ s[14]; + int32_t/*short*/ l[23]; + int32_t/*short*/ s[14]; } SFBandTable_t; typedef struct BitStreamInfo { - unsigned char *bytePtr; - unsigned int iCache; - int cachedBits; - int nBytes; + uint8_t *bytePtr; + uint32_t iCache; + int32_t cachedBits; + int32_t nBytes; } BitStreamInfo_t; typedef enum { /* map these to the corresponding 2-bit values in the frame header */ @@ -86,57 +86,57 @@ typedef enum { /* map to 0,1,2 to make table indexing easier */ } MPEGVersion_t; typedef struct FrameHeader { - int layer; /* layer index (1, 2, or 3) */ - int crc; /* CRC flag: 0 = disabled, 1 = enabled */ - int brIdx; /* bitrate index (0 - 15) */ - int srIdx; /* sample rate index (0 - 2) */ - int paddingBit; /* padding flag: 0 = no padding, 1 = single pad byte */ - int privateBit; /* unused */ - int modeExt; /* used to decipher joint stereo mode */ - int copyFlag; /* copyright flag: 0 = no, 1 = yes */ - int origFlag; /* original flag: 0 = copy, 1 = original */ - int emphasis; /* deemphasis mode */ - int CRCWord; /* CRC word (16 bits, 0 if crc not enabled) */ + int32_t layer; /* layer index (1, 2, or 3) */ + int32_t crc; /* CRC flag: 0 = disabled, 1 = enabled */ + int32_t brIdx; /* bitrate index (0 - 15) */ + int32_t srIdx; /* sample rate index (0 - 2) */ + int32_t paddingBit; /* padding flag: 0 = no padding, 1 = single pad byte */ + int32_t privateBit; /* unused */ + int32_t modeExt; /* used to decipher joint stereo mode */ + int32_t copyFlag; /* copyright flag: 0 = no, 1 = yes */ + int32_t origFlag; /* original flag: 0 = copy, 1 = original */ + int32_t emphasis; /* deemphasis mode */ + int32_t CRCWord; /* CRC word (16 bits, 0 if crc not enabled) */ } FrameHeader_t; typedef struct SideInfoSub { - int part23Length; /* number of bits in main data */ - int nBigvals; /* 2x this = first set of Huffman cw's (maximum amplitude can be > 1) */ - int globalGain; /* overall gain for dequantizer */ - int sfCompress; /* unpacked to figure out number of bits in scale factors */ - int winSwitchFlag; /* window switching flag */ - int blockType; /* block type */ - int mixedBlock; /* 0 = regular block (all short or long), 1 = mixed block */ - int tableSelect[3]; /* index of Huffman tables for the big values regions */ - int subBlockGain[3]; /* subblock gain offset, relative to global gain */ - int region0Count; /* 1+region0Count = num scale factor bands in first region of bigvals */ - int region1Count; /* 1+region1Count = num scale factor bands in second region of bigvals */ - int preFlag; /* for optional high frequency boost */ - int sfactScale; /* scaling of the scalefactors */ - int count1TableSelect; /* index of Huffman table for quad codewords */ + int32_t part23Length; /* number of bits in main data */ + int32_t nBigvals; /* 2x this = first set of Huffman cw's (maximum amplitude can be > 1) */ + int32_t globalGain; /* overall gain for dequantizer */ + int32_t sfCompress; /* unpacked to figure out number of bits in scale factors */ + int32_t winSwitchFlag; /* window switching flag */ + int32_t blockType; /* block type */ + int32_t mixedBlock; /* 0 = regular block (all short or long), 1 = mixed block */ + int32_t tableSelect[3]; /* index of Huffman tables for the big values regions */ + int32_t subBlockGain[3]; /* subblock gain offset, relative to global gain */ + int32_t region0Count; /* 1+region0Count = num scale factor bands in first region of bigvals */ + int32_t region1Count; /* 1+region1Count = num scale factor bands in second region of bigvals */ + int32_t preFlag; /* for optional high frequency boost */ + int32_t sfactScale; /* scaling of the scalefactors */ + int32_t count1TableSelect; /* index of Huffman table for quad codewords */ } SideInfoSub_t; typedef struct SideInfo { - int mainDataBegin; - int privateBits; - int scfsi[m_MAX_NCHAN][m_MAX_SCFBD]; /* 4 scalefactor bands per channel */ + int32_t mainDataBegin; + int32_t privateBits; + int32_t scfsi[m_MAX_NCHAN][m_MAX_SCFBD]; /* 4 scalefactor bands per channel */ } SideInfo_t; typedef struct { - int cbType; /* pure long = 0, pure short = 1, mixed = 2 */ - int cbEndS[3]; /* number nonzero short cb's, per subbblock */ - int cbEndSMax; /* max of cbEndS[] */ - int cbEndL; /* number nonzero long cb's */ + int32_t cbType; /* pure long = 0, pure short = 1, mixed = 2 */ + int32_t cbEndS[3]; /* number nonzero short cb's, per subbblock */ + int32_t cbEndSMax; /* max of cbEndS[] */ + int32_t cbEndL; /* number nonzero long cb's */ } CriticalBandInfo_t; typedef struct DequantInfo { - int workBuf[m_MAX_REORDER_SAMPS]; /* workbuf for reordering short blocks */ + int32_t workBuf[m_MAX_REORDER_SAMPS]; /* workbuf for reordering short blocks */ } DequantInfo_t; typedef struct HuffmanInfo { - int huffDecBuf[m_MAX_NCHAN][m_MAX_NSAMP]; /* used both for decoded Huffman values and dequantized coefficients */ - int nonZeroBound[m_MAX_NCHAN]; /* number of coeffs in huffDecBuf[ch] which can be > 0 */ - int gb[m_MAX_NCHAN]; /* minimum number of guard bits in huffDecBuf[ch] */ + int32_t huffDecBuf[m_MAX_NCHAN][m_MAX_NSAMP]; /* used both for decoded Huffman values and dequantized coefficients */ + int32_t nonZeroBound[m_MAX_NCHAN]; /* number of coeffs in huffDecBuf[ch] which can be > 0 */ + int32_t gb[m_MAX_NCHAN]; /* minimum number of guard bits in huffDecBuf[ch] */ } HuffmanInfo_t; typedef enum HuffTabType { @@ -150,28 +150,28 @@ typedef enum HuffTabType { } HuffTabType_t; typedef struct HuffTabLookup { - int linBits; - int tabType; /*HuffTabType*/ + int32_t linBits; + int32_t tabType; /*HuffTabType*/ } HuffTabLookup_t; typedef struct IMDCTInfo { - int outBuf[m_MAX_NCHAN][m_BLOCK_SIZE][m_NBANDS]; /* output of IMDCT */ - int overBuf[m_MAX_NCHAN][m_MAX_NSAMP / 2]; /* overlap-add buffer (by symmetry, only need 1/2 size) */ - int numPrevIMDCT[m_MAX_NCHAN]; /* how many IMDCT's calculated in this channel on prev. granule */ - int prevType[m_MAX_NCHAN]; - int prevWinSwitch[m_MAX_NCHAN]; - int gb[m_MAX_NCHAN]; + int32_t outBuf[m_MAX_NCHAN][m_BLOCK_SIZE][m_NBANDS]; /* output of IMDCT */ + int32_t overBuf[m_MAX_NCHAN][m_MAX_NSAMP / 2]; /* overlap-add buffer (by symmetry, only need 1/2 size) */ + int32_t numPrevIMDCT[m_MAX_NCHAN]; /* how many IMDCT's calculated in this channel on prev. granule */ + int32_t prevType[m_MAX_NCHAN]; + int32_t prevWinSwitch[m_MAX_NCHAN]; + int32_t gb[m_MAX_NCHAN]; } IMDCTInfo_t; typedef struct BlockCount { - int nBlocksLong; - int nBlocksTotal; - int nBlocksPrev; - int prevType; - int prevWinSwitch; - int currWinSwitch; - int gbIn; - int gbOut; + int32_t nBlocksLong; + int32_t nBlocksTotal; + int32_t nBlocksPrev; + int32_t prevType; + int32_t prevWinSwitch; + int32_t currWinSwitch; + int32_t gbIn; + int32_t gbOut; } BlockCount_t; typedef struct ScaleFactorInfoSub { /* max bits in scalefactors = 5, so use char's to save space */ @@ -180,9 +180,9 @@ typedef struct ScaleFactorInfoSub { /* max bits in scalefactors = 5, so use c } ScaleFactorInfoSub_t; typedef struct ScaleFactorJS { /* used in MPEG 2, 2.5 intensity (joint) stereo only */ - int intensityScale; - int slen[4]; - int nr[4]; + int32_t intensityScale; + int32_t slen[4]; + int32_t nr[4]; } ScaleFactorJS_t; /* NOTE - could get by with smaller vbuf if memory is more important than speed @@ -190,28 +190,28 @@ typedef struct ScaleFactorJS { /* used in MPEG 2, 2.5 intensity (joint) stereo o * last 15 blocks to shift them down one, a hardware style FIFO) */ typedef struct SubbandInfo { - int vbuf[m_MAX_NCHAN * m_VBUF_LENGTH]; /* vbuf for fast DCT-based synthesis PQMF - double size for speed (no modulo indexing) */ - int vindex; /* internal index for tracking position in vbuf */ + int32_t vbuf[m_MAX_NCHAN * m_VBUF_LENGTH]; /* vbuf for fast DCT-based synthesis PQMF - double size for speed (no modulo indexing) */ + int32_t vindex; /* internal index for tracking position in vbuf */ } SubbandInfo_t; typedef struct MP3DecInfo { /* buffer which must be large enough to hold largest possible main_data section */ - unsigned char mainBuf[m_MAINBUF_SIZE]; + uint8_t mainBuf[m_MAINBUF_SIZE]; /* special info for "free" bitrate files */ - int freeBitrateFlag; - int freeBitrateSlots; + int32_t freeBitrateFlag; + int32_t freeBitrateSlots; /* user-accessible info */ - int bitrate; - int nChans; - int samprate; - int nGrans; /* granules per frame */ - int nGranSamps; /* samples per granule */ - int nSlots; - int layer; - - int mainDataBegin; - int mainDataBytes; - int part23Length[m_MAX_NGRAN][m_MAX_NCHAN]; + int32_t bitrate; + int32_t nChans; + int32_t samprate; + int32_t nGrans; /* granules per frame */ + int32_t nGranSamps; /* samples per granule */ + int32_t nSlots; + int32_t layer; + + int32_t mainDataBegin; + int32_t mainDataBytes; + int32_t part23Length[m_MAX_NGRAN][m_MAX_NCHAN]; } MP3DecInfo_t; @@ -225,9 +225,9 @@ typedef struct MP3DecInfo { * float c4 = sin(2*u); */ -const int c9_x[] PROGMEM = {0x6ed9eba1, 0x620dbe8b, 0x163a1a7e, 0x5246dd49, 0x7e0e2e32 }; -const int c3_0[] PROGMEM = {0x6ed9eba1}; -const int c6[3] PROGMEM = { 0x7ba3751d, 0x5a82799a, 0x2120fb83 }; +const int32_t c9_x[] PROGMEM = {0x6ed9eba1, 0x620dbe8b, 0x163a1a7e, 0x5246dd49, 0x7e0e2e32 }; +const int32_t c3_0[] PROGMEM = {0x6ed9eba1}; +const int32_t c6[3] PROGMEM = { 0x7ba3751d, 0x5a82799a, 0x2120fb83 }; const uint32_t c18[9] PROGMEM = { 0x7f834ed0, 0x7ba3751d, 0x7401e4c1, 0x68d9f964, 0x5a82799a, 0x496af3e2, 0x36185aee, 0x2120fb83, 0x0b27eb5c}; /* @@ -275,7 +275,7 @@ const char NRTab[6][3][4] PROGMEM = { const char preTab[22] PROGMEM = { 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0 }; /* pow(2,-i/4) for i=0..3, Q31 format */ -const int pow14[4] PROGMEM = { +const int32_t pow14[4] PROGMEM = { 0x7fffffff, 0x6ba27e65, 0x5a82799a, 0x4c1bf829 }; @@ -289,13 +289,13 @@ const uint64_t ulconst[1] PROGMEM = { 1 }; * Relative error < 1E-7 * Coefs are scaled by 4, 2, 1, 0.5, 0.25 */ -const unsigned int poly43lo[5] PROGMEM = { 0x29a0bda9, 0xb02e4828, 0x5957aa1b, 0x236c498d, 0xff581859 }; -const unsigned int poly43hi[5] PROGMEM = { 0x10852163, 0xd333f6a4, 0x46e9408b, 0x27c2cef0, 0xfef577b4 }; +const uint32_t poly43lo[5] PROGMEM = { 0x29a0bda9, 0xb02e4828, 0x5957aa1b, 0x236c498d, 0xff581859 }; +const uint32_t poly43hi[5] PROGMEM = { 0x10852163, 0xd333f6a4, 0x46e9408b, 0x27c2cef0, 0xfef577b4 }; /* pow(2, i*4/3) as exp and frac */ -const int pow2exp[8] PROGMEM = { 14, 13, 11, 10, 9, 7, 6, 5 }; +const int32_t pow2exp[8] PROGMEM = { 14, 13, 11, 10, 9, 7, 6, 5 }; -const int pow2frac[8] PROGMEM = { +const int32_t pow2frac[8] PROGMEM = { 0x6597fa94, 0x50a28be6, 0x7fffffff, 0x6597fa94, 0x50a28be6, 0x7fffffff, 0x6597fa94, 0x50a28be6 }; @@ -334,7 +334,7 @@ const uint16_t m_HUFF_OFFSET_24=651 + m_HUFF_OFFSET_16; #define m_HUFF_OFFSET_24 651+m_HUFF_OFFSET_16 #endif -const int huffTabOffset[m_HUFF_PAIRTABS] PROGMEM = { +const int32_t huffTabOffset[m_HUFF_PAIRTABS] PROGMEM = { 0, m_HUFF_OFFSET_01, m_HUFF_OFFSET_02, m_HUFF_OFFSET_03, 0, m_HUFF_OFFSET_05, m_HUFF_OFFSET_06, m_HUFF_OFFSET_07, m_HUFF_OFFSET_08, m_HUFF_OFFSET_09, m_HUFF_OFFSET_10, m_HUFF_OFFSET_11, @@ -380,13 +380,13 @@ const HuffTabLookup_t huffTabLookup[m_HUFF_PAIRTABS] PROGMEM = { }; -const int quadTabOffset[2] PROGMEM = {0, 64}; -const int quadTabMaxBits[2] PROGMEM = {6, 4}; +const int32_t quadTabOffset[2] PROGMEM = {0, 64}; +const int32_t quadTabMaxBits[2] PROGMEM = {6, 4}; /* indexing = [version][samplerate index] * sample rate of frame (Hz) */ -const int samplerateTab[3][3] PROGMEM = { +const int32_t samplerateTab[3][3] PROGMEM = { { 44100, 48000, 32000 }, /* MPEG-1 */ { 22050, 24000, 16000 }, /* MPEG-2 */ { 11025, 12000, 8000 }, /* MPEG-2.5 */ @@ -397,7 +397,7 @@ const int samplerateTab[3][3] PROGMEM = { /* indexing = [version][layer] * number of samples in one frame (per channel) */ -const int/*short*/samplesPerFrameTab[3][3] PROGMEM = { { 384, 1152, 1152 }, /* MPEG1 */ +const int32_t/*short*/samplesPerFrameTab[3][3] PROGMEM = { { 384, 1152, 1152 }, /* MPEG1 */ { 384, 1152, 576 }, /* MPEG2 */ { 384, 1152, 576 }, /* MPEG2.5 */ }; @@ -408,7 +408,7 @@ const int/*short*/samplesPerFrameTab[3][3] PROGMEM = { { 384, 1152, 1152 }, /* M /* indexing = [version][mono/stereo] * number of bytes in side info section of bitstream */ -const int/*short*/sideBytesTab[3][2] PROGMEM = { { 17, 32 }, /* MPEG-1: mono, stereo */ +const int32_t/*short*/sideBytesTab[3][2] PROGMEM = { { 17, 32 }, /* MPEG-1: mono, stereo */ { 9, 17 }, /* MPEG-2: mono, stereo */ { 9, 17 }, /* MPEG-2.5: mono, stereo */ }; @@ -447,13 +447,13 @@ const SFBandTable_t sfBandTable[3][3] PROGMEM = { * * illegal intensity position scalefactors (see comments on ISFMpeg1) */ -const int ISFIIP[2][2] PROGMEM = { +const int32_t ISFIIP[2][2] PROGMEM = { {0x40000000, 0x00000000}, /* mid-side off */ {0x40000000, 0x40000000}, /* mid-side on */ }; // not used -//const unsigned char uniqueIDTab[8] = {0x5f, 0x4b, 0x43, 0x5f, 0x5f, 0x4a, 0x52, 0x5f}; +//const uint8_t uniqueIDTab[8] = {0x5f, 0x4b, 0x43, 0x5f, 0x5f, 0x4a, 0x52, 0x5f}; /* anti-alias coefficients - see spec Annex B, table 3-B.9 * csa[0][i] = CSi, csa[1][i] = CAi @@ -523,71 +523,71 @@ MODULE_PART uint32_t MP3Decoder_AllocateBuffers(void); MODULE_PART void MP3Decoder_FreeBuffers(); MODULE_PART int32_t MP3Decode( uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf, int32_t useSize); MODULE_PART void MP3GetLastFrameInfo(); -MODULE_PART int MP3GetNextFrameInfo(uint8_t *buf); -MODULE_PART int MP3FindSyncWord(uint8_t *buf, int32_t nBytes); -MODULE_PART int MP3GetSampRate(); -MODULE_PART int MP3GetChannels(); -MODULE_PART int MP3GetBitsPerSample(); -MODULE_PART int MP3GetBitrate(); -MODULE_PART int MP3GetOutputSamps(); +MODULE_PART int32_t MP3GetNextFrameInfo(uint8_t *buf); +MODULE_PART int32_t MP3FindSyncWord(uint8_t *buf, int32_t nBytes); +MODULE_PART int32_t MP3GetSampRate(); +MODULE_PART int32_t MP3GetChannels(); +MODULE_PART int32_t MP3GetBitsPerSample(); +MODULE_PART int32_t MP3GetBitrate(); +MODULE_PART int32_t MP3GetOutputSamps(); //internally used MODULE_PART void MP3Decoder_ClearBuffer(void); -MODULE_PART void PolyphaseMono(short *pcm, int *vbuf, const uint32_t *coefBase); -MODULE_PART void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase); -MODULE_PART void SetBitstreamPointer(BitStreamInfo_t *bsi, int nBytes, unsigned char *buf); -MODULE_PART unsigned int GetBits(BitStreamInfo_t *bsi, int nBits); -MODULE_PART int CalcBitsUsed(BitStreamInfo_t *bsi, unsigned char *startBuf, int startOffset); -MODULE_PART int DequantChannel(int *sampleBuf, int *workBuf, int *nonZeroBound, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi); -MODULE_PART void MidSideProc(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, int mOut[2]); -MODULE_PART void IntensityProcMPEG1(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, int midSideFlag, int mixFlag, int mOut[2]); -MODULE_PART void IntensityProcMPEG2(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, ScaleFactorJS_t *sfjs, int midSideFlag, int mixFlag, int mOut[2]); -MODULE_PART void FDCT32(int *x, int *d, int offset, int oddBlock, int gb);// __attribute__ ((section (".data"))); +MODULE_PART void PolyphaseMono(short *pcm, int32_t *vbuf, const uint32_t *coefBase); +MODULE_PART void PolyphaseStereo(short *pcm, int32_t *vbuf, const uint32_t *coefBase); +MODULE_PART void SetBitstreamPointer(BitStreamInfo_t *bsi, int32_t nBytes, uint8_t *buf); +MODULE_PART uint32_t GetBits(BitStreamInfo_t *bsi, int32_t nBits); +MODULE_PART int32_t CalcBitsUsed(BitStreamInfo_t *bsi, uint8_t *startBuf, int32_t startOffset); +MODULE_PART int32_t DequantChannel(int32_t *sampleBuf, int32_t *workBuf, int32_t *nonZeroBound, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi); +MODULE_PART void MidSideProc(int32_t x[m_MAX_NCHAN][m_MAX_NSAMP], int32_t nSamps, int32_t mOut[2]); +MODULE_PART void IntensityProcMPEG1(int32_t x[m_MAX_NCHAN][m_MAX_NSAMP], int32_t nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]); +MODULE_PART void IntensityProcMPEG2(int32_t x[m_MAX_NCHAN][m_MAX_NSAMP], int32_t nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, ScaleFactorJS_t *sfjs, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]); +MODULE_PART void FDCT32(int32_t *x, int32_t *d, int32_t offset, int32_t oddBlock, int32_t gb);// __attribute__ ((section (".data"))); MODULE_PART void FreeBuffers(); -MODULE_PART int CheckPadBit(); -MODULE_PART int UnpackFrameHeader(unsigned char *buf); -MODULE_PART int UnpackSideInfo(unsigned char *buf); -MODULE_PART int DecodeHuffman( unsigned char *buf, int *bitOffset, int huffBlockBits, int gr, int ch); -MODULE_PART int MP3Dequantize( int gr); -MODULE_PART int IMDCT( int gr, int ch); -MODULE_PART int UnpackScaleFactors( unsigned char *buf, int *bitOffset, int bitsAvail, int gr, int ch); -MODULE_PART int Subband(short *pcmBuf); -MODULE_PART short ClipToShort(int x, int fracBits); +MODULE_PART int32_t CheckPadBit(); +MODULE_PART int32_t UnpackFrameHeader(uint8_t *buf); +MODULE_PART int32_t UnpackSideInfo(uint8_t *buf); +MODULE_PART int32_t DecodeHuffman( uint8_t *buf, int32_t *bitOffset, int32_t huffBlockBits, int32_t gr, int32_t ch); +MODULE_PART int32_t MP3Dequantize( int32_t gr); +MODULE_PART int32_t IMDCT( int32_t gr, int32_t ch); +MODULE_PART int32_t UnpackScaleFactors( uint8_t *buf, int32_t *bitOffset, int32_t bitsAvail, int32_t gr, int32_t ch); +MODULE_PART int32_t Subband(short *pcmBuf); +MODULE_PART short ClipToShort(int32_t x, int32_t fracBits); MODULE_PART void RefillBitstreamCache(BitStreamInfo_t *bsi); -MODULE_PART void UnpackSFMPEG1(BitStreamInfo_t *bsi, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, int *scfsi, int gr, ScaleFactorInfoSub_t *sfisGr0); -MODULE_PART void UnpackSFMPEG2(BitStreamInfo_t *bsi, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, int gr, int ch, int modeExt, ScaleFactorJS_t *sfjs); -MODULE_PART int MP3FindFreeSync(unsigned char *buf, unsigned char firstFH[4], int nBytes); +MODULE_PART void UnpackSFMPEG1(BitStreamInfo_t *bsi, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, int32_t *scfsi, int32_t gr, ScaleFactorInfoSub_t *sfisGr0); +MODULE_PART void UnpackSFMPEG2(BitStreamInfo_t *bsi, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, int32_t gr, int32_t ch, int32_t modeExt, ScaleFactorJS_t *sfjs); +MODULE_PART int32_t MP3FindFreeSync(uint8_t *buf, uint8_t firstFH[4], int32_t nBytes); MODULE_PART void MP3ClearBadFrame( short *outbuf); -MODULE_PART int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned char *buf, int bitOffset); -MODULE_PART int DecodeHuffmanQuads(int *vwxy, int nVals, int tabIdx, int bitsLeft, unsigned char *buf, int bitOffset); -MODULE_PART int DequantBlock(int *inbuf, int *outbuf, int num, int scale); -MODULE_PART void AntiAlias(int *x, int nBfly); -MODULE_PART void WinPrevious(int *xPrev, int *xPrevWin, int btPrev); -MODULE_PART int FreqInvertRescale(int *y, int *xPrev, int blockIdx, int es); -MODULE_PART void idct9(int *x); -MODULE_PART int IMDCT36(int *xCurr, int *xPrev, int *y, int btCurr, int btPrev, int blockIdx, int gb); -MODULE_PART void imdct12(int *x, int *out); -MODULE_PART int IMDCT12x3(int *xCurr, int *xPrev, int *y, int btPrev, int blockIdx, int gb); -MODULE_PART int HybridTransform(int *xCurr, int *xPrev, int y[m_BLOCK_SIZE][m_NBANDS], SideInfoSub_t *sis, BlockCount_t *bc); +MODULE_PART int32_t DecodeHuffmanPairs(int32_t *xy, int32_t nVals, int32_t tabIdx, int32_t bitsLeft, uint8_t *buf, int32_t bitOffset); +MODULE_PART int32_t DecodeHuffmanQuads(int32_t *vwxy, int32_t nVals, int32_t tabIdx, int32_t bitsLeft, uint8_t *buf, int32_t bitOffset); +MODULE_PART int32_t DequantBlock(int32_t *inbuf, int32_t *outbuf, int32_t num, int32_t scale); +MODULE_PART void AntiAlias(int32_t *x, int32_t nBfly); +MODULE_PART void WinPrevious(int32_t *xPrev, int32_t *xPrevWin, int32_t btPrev); +MODULE_PART int32_t FreqInvertRescale(int32_t *y, int32_t *xPrev, int32_t blockIdx, int32_t es); +MODULE_PART void idct9(int32_t *x); +MODULE_PART int32_t IMDCT36(int32_t *xCurr, int32_t *xPrev, int32_t *y, int32_t btCurr, int32_t btPrev, int32_t blockIdx, int32_t gb); +MODULE_PART void imdct12(int32_t *x, int32_t *out); +MODULE_PART int32_t IMDCT12x3(int32_t *xCurr, int32_t *xPrev, int32_t *y, int32_t btPrev, int32_t blockIdx, int32_t gb); +MODULE_PART int32_t HybridTransform(int32_t *xCurr, int32_t *xPrev, int32_t y[m_BLOCK_SIZE][m_NBANDS], SideInfoSub_t *sis, BlockCount_t *bc); //MODULE_PART inline uint64_t SAR64(uint64_t x, int n) { return x >> n;} #define SAR64 __lshrdi3 -//MODULE_PART inline int MULSHIFT32(int x, int y) { int z; z = (uint64_t) x * (uint64_t) y >> 32; return z;} +//MODULE_PART inline int32_t MULSHIFT32(int32_t x, int32_t y) { int32_t z; z = (uint64_t) x * (uint64_t) y >> 32; return z;} //#define MULSHIFT32(x, y) (int)(__muldi3((uint64_t) x , (uint64_t) y) >> 32) -//MODULE_PART int MULSHIFT32(int x, int y); +//MODULE_PART int32_t MULSHIFT32(int32_t x, int32_t y); -//MODULE_PART inline uint64_t MADD64(uint64_t sum64, int x, int y) {sum64 += (uint64_t) x * (uint64_t) y; return sum64;}/* returns 64-bit value in [edx:eax] */ +//MODULE_PART inline uint64_t MADD64(uint64_t sum64, int32_t x, int32_t y) {sum64 += (uint64_t) x * (uint64_t) y; return sum64;}/* returns 64-bit value in [edx:eax] */ #define MADD64(x, y) __muldi3(x, y) MODULE_PART uint32_t my_clz(uint32_t in); //MODULE_PART -inline uint64_t xSAR64(uint64_t x, int n){return x >> n;} +inline uint64_t xSAR64(uint64_t x, int32_t n){return x >> n;} -//MODULE_PART inline int FASTABS(int x){ return __builtin_abs(x);} //xtensa has a fast abs instruction //fb -MODULE_PART int FASTABS(int x) { +//MODULE_PART inline int FASTABS(int32_t x){ return __builtin_abs(x);} //xtensa has a fast abs instruction //fb +MODULE_PART int32_t FASTABS(int32_t x) { if (x < 0) { return -x; } @@ -598,13 +598,13 @@ MODULE_PART int FASTABS(int x) { #define CLZ(x) my_clz(x) //fb #ifdef __riscv -MODULE_PART int MULSHIFT32(int x, int y) { +MODULE_PART int32_t MULSHIFT32(int32_t x, int32_t y) { SETMINREGS - int z = __muldi3((uint64_t) x , (uint64_t) y) >> 32; + int32_t z = __muldi3((uint64_t) x , (uint64_t) y) >> 32; return z; } #else - MODULE_PART static __inline int MULSHIFT32(int x, int y) { + MODULE_PART static __inline int32_t MULSHIFT32(int32_t x, int32_t y) { /* important rules for smull RdLo, RdHi, Rm, Rs: * RdHi and Rm can't be the same register * RdLo and Rm can't be the same register @@ -615,7 +615,7 @@ MODULE_PART int MULSHIFT32(int x, int y) { * which one is returned. (If this were a function call, returning y (R1) would * require an extra "mov r0, r1") */ - int ret; + int32_t ret; asm volatile ("mulsh %0, %1, %2" : "=r" (ret) : "r" (x), "r" (y)); return ret; } @@ -626,14 +626,14 @@ MODULE_PART int MULSHIFT32(int x, int y) { typedef long long Word64; -static __inline Word64 MADD64(Word64 sum64, int x, int y) +static __inline Word64 MADD64(Word64 sum64, int32_t x, int32_t y) { return (sum64 + ((long long)x * y)); } #if XCHAL_HAVE_MUL32_HIGH -static __inline int MULSHIFT32(int x, int y) +static __inline int32_t MULSHIFT32(int32_t x, int32_t y) { /* important rules for smull RdLo, RdHi, Rm, Rs: * RdHi and Rm can't be the same register @@ -645,7 +645,7 @@ static __inline int MULSHIFT32(int x, int y) * which one is returned. (If this were a function call, returning y (R1) would * require an extra "mov r0, r1") */ - int ret; + int32_t ret; asm volatile ("mulsh %0, %1, %2" : "=r" (ret) : "r" (x), "r" (y)); return ret; } @@ -658,9 +658,9 @@ static __inline int MULSHIFT32(int x, int y) #if XCHAL_HAVE_ABS -static __inline int FASTABS(int x) +static __inline int32_t FASTABS(int32_t x) { - int ret; + int32_t ret; asm volatile ("abs %0, %1" : "=r" (ret) : "r" (x)); return ret; } @@ -671,12 +671,12 @@ static __inline int FASTABS(int x) #endif -static __inline Word64 SAR64(Word64 x, int n) +static __inline Word64 SAR64(Word64 x, int32_t n) { return x >> n; } -static __inline int CLZ(int x) +static __inline int32_t CLZ(int32_t x) { return __builtin_clz(x); } diff --git a/tasmota/Plugins/Audio/MP3/mp3_decoder_c.h b/tasmota/Plugins/Audio/MP3/mp3_decoder_c.h index 8946c96b996e..202d48d6c539 100644 --- a/tasmota/Plugins/Audio/MP3/mp3_decoder_c.h +++ b/tasmota/Plugins/Audio/MP3/mp3_decoder_c.h @@ -19,22 +19,22 @@ /* clip to range [-2^n, 2^n - 1] */ #if 0 //Fast on ARM: #define CLIP_2N(y, n) { \ - int sign = (y) >> 31; \ + int32_t sign = (y) >> 31; \ if (sign != (y) >> (n)) { \ (y) = sign ^ ((1 << (n)) - 1); \ } \ } #else //on xtensa this is faster, due to asm min/max instructions: #define CLIP_2N(y, n) { \ - int x = 1 << n; \ + int32_t x = 1 << n; \ if (y < -x) y = -x; \ x--; \ if (y > x) y = x; \ } #endif -MODULE_PART int xCLIP_2N(int y, int n) { - int x = 1 << n; +MODULE_PART int32_t xCLIP_2N(int32_t y, int32_t n) { + int32_t x = 1 << n; if (y < -x) y = -x; x--; if (y > x) y = x; @@ -74,7 +74,7 @@ const uint32_t m_SQRTHALF[] PROGMEM = {0x5a82799a,0x08000000,0x20000000,0x400000 const uint32_t syncw[4] PROGMEM = {m_SYNCWORDH,m_SYNCWORDL,0b11110000,0b00001100}; -const unsigned short huffTable[4242] PROGMEM = { +const uint16_t huffTable[4242] PROGMEM = { /* huffTable01[9] */ 0xf003, 0x3112, 0x3101, 0x2011, 0x2011, 0x1000, 0x1000, 0x1000, 0x1000, /* huffTable02[65] */ @@ -453,7 +453,7 @@ const unsigned short huffTable[4242] PROGMEM = { 0xf001, 0x1a42, 0x1872, 0xf001, 0x1801, 0x1081, 0xf001, 0x1701, 0x1071, }; /* pow(2,-i/4) * pow(j,4/3) for i=0..3 j=0..15, Q25 format */ -const int pow43_14[4][16] PROGMEM = { /* Q28 */ +const int32_t pow43_14[4][16] PROGMEM = { /* Q28 */ { 0x00000000, 0x10000000, 0x285145f3, 0x453a5cdb, 0x0cb2ff53, 0x111989d6, 0x15ce31c8, 0x1ac7f203, 0x20000000, 0x257106b9, 0x2b16b4a3, 0x30ed74b4, 0x36f23fa5, 0x3d227bd3, 0x437be656, 0x49fc823c, }, @@ -472,7 +472,7 @@ const int pow43_14[4][16] PROGMEM = { /* Q28 */ }; /* pow(j,4/3) for j=16..63, Q23 format */ -const int pow43[48] PROGMEM = { +const int32_t pow43[48] PROGMEM = { 0x1428a2fa, 0x15db1bd6, 0x1796302c, 0x19598d85, 0x1b24e8bb, 0x1cf7fcfa, 0x1ed28af2, 0x20b4582a, 0x229d2e6e, 0x248cdb55, 0x26832fda, 0x28800000, 0x2a832287, 0x2c8c70a8, 0x2e9bc5d8, 0x30b0ff99, 0x32cbfd4a, 0x34eca001, @@ -532,7 +532,7 @@ const uint32_t polyCoef[264] PROGMEM = { * } * coef32[30] *= 0.5; / *** for initial back butterfly (i.e. two-point DCT) *** / */ -const int coef32[31] PROGMEM = { +const int32_t coef32[31] PROGMEM = { 0x7fd8878d, 0x7e9d55fc, 0x7c29fbee, 0x78848413, 0x73b5ebd0, 0x6dca0d14, 0x66cf811f, 0x5ed77c89, 0x55f5a4d2, 0x4c3fdff3, 0x41ce1e64, 0x36ba2013, 0x2b1f34eb, 0x1f19f97b, 0x12c8106e, 0x0647d97c, 0x7f62368f, 0x7a7d055b, 0x70e2cbc6, 0x62f201ac, 0x5133cc94, 0x3c56ba70, 0x25280c5d, 0x0c8bd35e, @@ -555,7 +555,7 @@ const uint32_t fastWin36[18] PROGMEM = { * A = length of codeword * B = codeword */ -const unsigned char quadTable[64+16] PROGMEM = { +const uint8_t quadTable[64+16] PROGMEM = { /* table A */ 0x6b, 0x6f, 0x6d, 0x6e, 0x67, 0x65, 0x59, 0x59, 0x56, 0x56, 0x53, 0x53, 0x5a, 0x5a, 0x5c, 0x5c, 0x42, 0x42, 0x42, 0x42, 0x41, 0x41, 0x41, 0x41, 0x44, 0x44, 0x44, 0x44, 0x48, 0x48, 0x48, 0x48, @@ -636,12 +636,12 @@ const uint32_t imdctWin[4][36] PROGMEM = { 0xe7dbc161, 0xef7a6275, 0xf6a09e66, 0xfd16d8dd }, }; -const int ISFMpeg1[2][7] PROGMEM = { +const int32_t ISFMpeg1[2][7] PROGMEM = { {0x00000000, 0x0d8658ba, 0x176cf5d0, 0x20000000, 0x28930a2f, 0x3279a745, 0x40000000}, {0x00000000, 0x13207f5c, 0x2120fb83, 0x2d413ccc, 0x39617e16, 0x4761fa3d, 0x5a827999} }; -const int ISFMpeg2[2][2][16] PROGMEM = { +const int32_t ISFMpeg2[2][2][16] PROGMEM = { { { /* intensityScale off, mid-side off */ 0x40000000, 0x35d13f32, 0x2d413ccc, 0x260dfc14, 0x1fffffff, 0x1ae89f99, 0x16a09e66, 0x1306fe0a, 0x0fffffff, 0x0d744fcc, 0x0b504f33, 0x09837f05, 0x07ffffff, 0x06ba27e6, 0x05a82799, 0x04c1bf82 }, @@ -694,7 +694,7 @@ const int ISFMpeg2[2][2][16] PROGMEM = { #define COS4_0 0x5a82799a /* Q31 */ // faster in ROM -static const int m_dcttab[48] PROGMEM = { +static const int32_t m_dcttab[48] PROGMEM = { /* first pass */ COS0_0, COS0_15, COS1_0, /* 31, 27, 31 */ COS0_1, COS0_14, COS1_1, /* 31, 29, 31 */ @@ -721,16 +721,16 @@ static const int m_dcttab[48] PROGMEM = { * B I T S T R E A M **********************************************************************************************************************/ -void SetBitstreamPointer(BitStreamInfo_t *bsi, int nBytes, unsigned char *buf) { +void SetBitstreamPointer(BitStreamInfo_t *bsi, int32_t nBytes, uint8_t *buf) { /* init bitstream */ bsi->bytePtr = buf; - bsi->iCache = 0; /* 4-byte unsigned int */ + bsi->iCache = 0; /* 4-byte uint32_t */ bsi->cachedBits = 0; /* i.e. zero bits in cache */ bsi->nBytes = nBytes; } //---------------------------------------------------------------------------------------------------------------------- void RefillBitstreamCache(BitStreamInfo_t *bsi) { - int nBytes = bsi->nBytes; + int32_t nBytes = bsi->nBytes; /* optimize for common case, independent of machine endian-ness */ if (nBytes >= 4) { bsi->iCache = (*bsi->bytePtr++) << 24; @@ -751,8 +751,8 @@ void RefillBitstreamCache(BitStreamInfo_t *bsi) { } } //---------------------------------------------------------------------------------------------------------------------- -unsigned int GetBits(BitStreamInfo_t *bsi, int nBits) { - unsigned int data, lowBits; +uint32_t GetBits(BitStreamInfo_t *bsi, int32_t nBits) { + uint32_t data, lowBits; nBits &= 0x1f; /* nBits mod 32 to avoid unpredictable results like >> by negative amount */ data = bsi->iCache >> (31 - nBits); /* unsigned >> so zero-extend */ @@ -769,22 +769,22 @@ unsigned int GetBits(BitStreamInfo_t *bsi, int nBits) { return data; } //---------------------------------------------------------------------------------------------------------------------- -int CalcBitsUsed(BitStreamInfo_t *bsi, unsigned char *startBuf, int startOffset){ - int bitsUsed; +int32_t CalcBitsUsed(BitStreamInfo_t *bsi, uint8_t *startBuf, int32_t startOffset) { + int32_t bitsUsed; bitsUsed = (bsi->bytePtr - startBuf) * 8; bitsUsed -= bsi->cachedBits; bitsUsed -= startOffset; return bitsUsed; } //---------------------------------------------------------------------------------------------------------------------- -int CheckPadBit(){ +int32_t CheckPadBit() { SETREGS return (mp3m.m_FrameHeader->paddingBit ? 1 : 0); } //---------------------------------------------------------------------------------------------------------------------- -int UnpackFrameHeader(unsigned char *buf){ +int32_t UnpackFrameHeader(uint8_t *buf) { SETREGS - int verIdx; + int32_t verIdx; /* validate pointers and sync word */ //const uint32_t *swp = (const uint32_t *) ((uint8_t *)syncw+EXEC_OFFSET); @@ -835,14 +835,14 @@ int UnpackFrameHeader(unsigned char *buf){ #if 0 mp3m.m_MP3DecInfo->samprate = samplerateTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->srIdx]; mp3m.m_MP3DecInfo->nGrans = (mp3m.m_MPEGVersion == MPEG1 ? m_NGRANS_MPEG1 : m_NGRANS_MPEG2); - mp3m.m_MP3DecInfo->nGranSamps = ((int) samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1])/mp3m.m_MP3DecInfo->nGrans; + mp3m.m_MP3DecInfo->nGranSamps = ((int32_t) samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1])/mp3m.m_MP3DecInfo->nGrans; mp3m.m_MP3DecInfo->layer = mp3m.m_FrameHeader->layer; #else - int *srt = (int *)&samplerateTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->srIdx]; + int32_t *srt = (int32_t *)&samplerateTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->srIdx]; srt += EXEC_OFFSET >> 2; mp3m.m_MP3DecInfo->samprate = *srt; mp3m.m_MP3DecInfo->nGrans = (mp3m.m_MPEGVersion == MPEG1 ? m_NGRANS_MPEG1 : m_NGRANS_MPEG2); - srt = (int *)&samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1]; + srt = (int32_t *)&samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1]; srt += EXEC_OFFSET >> 2; //mp3m.m_MP3DecInfo->nGranSamps = *srt / mp3m.m_MP3DecInfo->nGrans; mp3m.m_MP3DecInfo->nGranSamps = __divsi3(*srt, mp3m.m_MP3DecInfo->nGrans); @@ -857,30 +857,30 @@ int UnpackFrameHeader(unsigned char *buf){ if (mp3m.m_FrameHeader->brIdx) { #if 0 - mp3m.m_MP3DecInfo->bitrate=((int) bitrateTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1][mp3m.m_FrameHeader->brIdx]) * 1000; + mp3m.m_MP3DecInfo->bitrate=((int32_t) bitrateTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1][mp3m.m_FrameHeader->brIdx]) * 1000; /* nSlots = total frame bytes (from table) - sideInfo bytes - header - CRC (if present) + pad (if present) */ - mp3m.m_MP3DecInfo->nSlots= (int) slotTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->srIdx][mp3m.m_FrameHeader->brIdx] - - (int) sideBytesTab[mp3m.m_MPEGVersion][(mp3m.m_sMode == Mono ? 0 : 1)] - 4 + mp3m.m_MP3DecInfo->nSlots= (int32_t) slotTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->srIdx][mp3m.m_FrameHeader->brIdx] + - (int32_t) sideBytesTab[mp3m.m_MPEGVersion][(mp3m.m_sMode == Mono ? 0 : 1)] - 4 - (mp3m.m_FrameHeader->crc ? 2 : 0) + (mp3m.m_FrameHeader->paddingBit ? 1 : 0); #else short *brt = (short *)&bitrateTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->layer - 1][mp3m.m_FrameHeader->brIdx]; brt += EXEC_OFFSET >> 1; - mp3m.m_MP3DecInfo->bitrate = (int) pgm_read_word(brt) * 1000; + mp3m.m_MP3DecInfo->bitrate = (int32_t) pgm_read_word(brt) * 1000; short *slt = (short *) &slotTab[mp3m.m_MPEGVersion][mp3m.m_FrameHeader->srIdx][mp3m.m_FrameHeader->brIdx]; slt += EXEC_OFFSET >> 1; - int *stb = (int *) &sideBytesTab[mp3m.m_MPEGVersion][(mp3m.m_sMode == Mono ? 0 : 1)]; + int32_t *stb = (int32_t *) &sideBytesTab[mp3m.m_MPEGVersion][(mp3m.m_sMode == Mono ? 0 : 1)]; stb += EXEC_OFFSET >> 2; - mp3m.m_MP3DecInfo->nSlots= (int) pgm_read_word(slt) - - (int) *stb - 4 + mp3m.m_MP3DecInfo->nSlots= (int32_t) pgm_read_word(slt) + - (int32_t) *stb - 4 - (mp3m.m_FrameHeader->crc ? 2 : 0) + (mp3m.m_FrameHeader->paddingBit ? 1 : 0); #endif } /* load crc word, if enabled, and return length of frame header (in bytes) */ if (mp3m.m_FrameHeader->crc) { - mp3m.m_FrameHeader->CRCWord = ((int) buf[4] << 8 | (int) buf[5] << 0); + mp3m.m_FrameHeader->CRCWord = ((int32_t) buf[4] << 8 | (int32_t) buf[5] << 0); return 6; } else { mp3m.m_FrameHeader->CRCWord = 0; @@ -888,9 +888,9 @@ int UnpackFrameHeader(unsigned char *buf){ } } //---------------------------------------------------------------------------------------------------------------------- -int UnpackSideInfo( unsigned char *buf) { +int32_t UnpackSideInfo( uint8_t *buf) { SETREGS - int gr, ch, bd, nBytes; + int32_t gr, ch, bd, nBytes; BitStreamInfo_t bitStreamInfo, *bsi; SideInfoSub_t *sis; @@ -985,13 +985,13 @@ int UnpackSideInfo( unsigned char *buf) { * Illegal Intensity Position = 7 (always) for MPEG1 scale factors **********************************************************************************************************************/ void UnpackSFMPEG1(BitStreamInfo_t *bsi, SideInfoSub_t *sis, - ScaleFactorInfoSub_t *sfis, int *scfsi, int gr, ScaleFactorInfoSub_t *sfisGr0){ + ScaleFactorInfoSub_t *sfis, int32_t *scfsi, int32_t gr, ScaleFactorInfoSub_t *sfisGr0){ SETREGS - int sfb; - int slen0, slen1; + int32_t sfb; + int32_t slen0, slen1; /* these can be 0, so make sure GetBits(bsi, 0) returns 0 (no >> 32 or anything) */ - //slen0 = (int)m_SFLenTab[sis->sfCompress][0]; - //slen1 = (int)m_SFLenTab[sis->sfCompress][1]; + //slen0 = (int32_t)m_SFLenTab[sis->sfCompress][0]; + //slen1 = (int32_t)m_SFLenTab[sis->sfCompress][1]; const char *sfl1 = &m_SFLenTab[sis->sfCompress][0]; const char *sfl2 = &m_SFLenTab[sis->sfCompress][1]; @@ -1079,12 +1079,12 @@ void UnpackSFMPEG1(BitStreamInfo_t *bsi, SideInfoSub_t *sis, * Notes: Illegal Intensity Position = (2^slen) - 1 for MPEG2 scale factors **********************************************************************************************************************/ void UnpackSFMPEG2(BitStreamInfo_t *bsi, SideInfoSub_t *sis, - ScaleFactorInfoSub_t *sfis, int gr, int ch, int modeExt, ScaleFactorJS_t *sfjs){ + ScaleFactorInfoSub_t *sfis, int32_t gr, int32_t ch, int32_t modeExt, ScaleFactorJS_t *sfjs){ SETREGS - int i, sfb, sfcIdx, btIdx, nrIdx;// iipTest; - int slen[4], nr[4]; - int sfCompress, preFlag, intensityScale; + int32_t i, sfb, sfcIdx, btIdx, nrIdx;// iipTest; + int32_t slen[4], nr[4]; + int32_t sfCompress, preFlag, intensityScale; (void)gr; sfCompress = sis->sfCompress; preFlag = 0; @@ -1248,10 +1248,10 @@ void UnpackSFMPEG2(BitStreamInfo_t *bsi, SideInfoSub_t *sis, * * Return: length (in bytes) of scale factor data, -1 if null input pointers **********************************************************************************************************************/ -int UnpackScaleFactors( unsigned char *buf, int *bitOffset, int bitsAvail, int gr, int ch){ +int32_t UnpackScaleFactors( uint8_t *buf, int32_t *bitOffset, int32_t bitsAvail, int32_t gr, int32_t ch){ SETREGS - int bitsUsed; - unsigned char *startBuf; + int32_t bitsUsed; + uint8_t *startBuf; BitStreamInfo_t bitStreamInfo, *bsi; /* init GetBits reader */ @@ -1281,8 +1281,8 @@ int UnpackScaleFactors( unsigned char *buf, int *bitOffset, int bitsAvail, int g ****************************************************************************************************************************************************/ -MODULE_PART int findSync(unsigned char* buf, uint16_t offset, uint16_t nBytes) { // lambda, inner function - for (int i = 0; i < nBytes - 1; i++) { +MODULE_PART int32_t findSync(uint8_t* buf, uint16_t offset, uint16_t nBytes) { // lambda, inner function + for (int32_t i = 0; i < nBytes - 1; i++) { if ((buf[i + offset] & m_SYNCWORDH) == m_SYNCWORDH && (buf[i + offset + 1] & m_SYNCWORDL) == m_SYNCWORDL){ return i; } @@ -1303,7 +1303,7 @@ MODULE_PART int findSync(unsigned char* buf, uint16_t offset, uint16_t nBytes) * Return: offset to first sync word (bytes from start of buf) * -1 if sync not found after searchigng nBytes ****************************************************************************************************************************************************/ -int MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { +int32_t MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { SETREGS @@ -1314,10 +1314,10 @@ int MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { uint8_t const2 = swp[3]; const uint8_t mp3FHsize = 4; // frame header size - unsigned char firstFH[4]; + uint8_t firstFH[4]; /* //———————————————————————————————————————————————————————————————————————————————————————————————————————— - auto findSync = [&](unsigned char* buf, uint16_t offset, uint16_t len) { // lambda, inner function + auto findSync = [&](uint8_t* buf, uint16_t offset, uint16_t len) { // lambda, inner function for (int i = 0; i < nBytes - 1; i++) { //if ((buf[i + offset] & m_SYNCWORDH) == m_SYNCWORDH && (buf[i + offset + 1] & m_SYNCWORDL) == m_SYNCWORDL){ if ((buf[i + offset] & swh) == swh && (buf[i + offset + 1] & swl) == swl){ @@ -1330,7 +1330,7 @@ int MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { */ //———————————————————————————————————————————————————————————————————————————————————————————————————————— /* find byte-aligned syncword - need 12 (MPEG 1,2) or 11 (MPEG 2.5) matching bits */ - int pos = findSync(buf, 0, nBytes); + int32_t pos = findSync(buf, 0, nBytes); if (pos == -1) return pos; // syncword not found nBytes -= pos; @@ -1345,7 +1345,7 @@ int MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { //log_d("wrong bitrate index"); pos += mp3FHsize; nBytes -= mp3FHsize; - int i = findSync(buf, pos, nBytes); + int32_t i = findSync(buf, pos, nBytes); pos += i; nBytes -= i; continue; @@ -1356,7 +1356,7 @@ int MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { //log_d("wrong sampling rate"); pos += mp3FHsize; nBytes -= mp3FHsize; - int i = findSync(buf, pos, nBytes); + int32_t i = findSync(buf, pos, nBytes); pos += i; nBytes -= i; continue; @@ -1390,10 +1390,10 @@ int MP3FindSyncWord(uint8_t *buf, int32_t nBytes) { * this function once (first frame) then store the result (nSlots) * and just use it from then on ****************************************************************************************************************************************************/ -int MP3FindFreeSync(unsigned char *buf, unsigned char firstFH[4], int nBytes){ +int32_t MP3FindFreeSync(uint8_t *buf, uint8_t firstFH[4], int32_t nBytes){ SETREGS - int offset = 0; - unsigned char *bufPtr = buf; + int32_t offset = 0; + uint8_t *bufPtr = buf; /* loop until we either: * - run out of nBytes (FindMP3SyncWord() returns -1) @@ -1450,9 +1450,9 @@ void MP3GetLastFrameInfo() { mp3m.m_MP3FrameInfo->samprate=mp3m.m_MP3DecInfo->samprate; mp3m.m_MP3FrameInfo->bitsPerSample=16; #if 0 - mp3m.m_MP3FrameInfo->outputSamps=mp3m.m_MP3DecInfo->nChans * (int) samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_MP3DecInfo->layer-1]; + mp3m.m_MP3FrameInfo->outputSamps=mp3m.m_MP3DecInfo->nChans * (int32_t) samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_MP3DecInfo->layer-1]; #else - int *srt = (int *)&samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_MP3DecInfo->layer-1]; + int32_t *srt = (int32_t *)&samplesPerFrameTab[mp3m.m_MPEGVersion][mp3m.m_MP3DecInfo->layer-1]; srt += EXEC_OFFSET >> 2; mp3m.m_MP3FrameInfo->outputSamps = mp3m.m_MP3DecInfo->nChans * *srt; #endif @@ -1460,23 +1460,23 @@ void MP3GetLastFrameInfo() { mp3m.m_MP3FrameInfo->version=mp3m.m_MPEGVersion; } } -int MP3GetSampRate(){ +int32_t MP3GetSampRate(){ SETREGS return mp3m.m_MP3FrameInfo->samprate; } -int MP3GetChannels(){ +int32_t MP3GetChannels(){ SETREGS return mp3m.m_MP3FrameInfo->nChans; } -int MP3GetBitsPerSample(){ +int32_t MP3GetBitsPerSample(){ SETREGS return mp3m.m_MP3FrameInfo->bitsPerSample; } -int MP3GetBitrate(){ +int32_t MP3GetBitrate(){ SETREGS return mp3m.m_MP3FrameInfo->bitrate; } -int MP3GetOutputSamps(){ +int32_t MP3GetOutputSamps(){ SETREGS return mp3m.m_MP3FrameInfo->outputSamps; } @@ -1492,7 +1492,7 @@ int MP3GetOutputSamps(){ * * Return: error code, defined in mp3dec.h (0 means no error, < 0 means error) **********************************************************************************************************************/ -int MP3GetNextFrameInfo(uint8_t *buf) { +int32_t MP3GetNextFrameInfo(uint8_t *buf) { SETREGS if (UnpackFrameHeader( buf) == -1 || mp3m.m_MP3DecInfo->layer != 3) return ERR_MP3_INVALID_FRAMEHEADER; @@ -1515,7 +1515,7 @@ int MP3GetNextFrameInfo(uint8_t *buf) { **********************************************************************************************************************/ void MP3ClearBadFrame( short *outbuf) { SETREGS - int i; + int32_t i; for (i = 0; i < mp3m.m_MP3DecInfo->nGrans * mp3m.m_MP3DecInfo->nGranSamps * mp3m.m_MP3DecInfo->nChans; i++) outbuf[i] = 0; } @@ -1541,9 +1541,9 @@ void MP3ClearBadFrame( short *outbuf) { int32_t MP3Decode( uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf, int32_t useSize) { SETREGS - int offset, bitOffset, mainBits, gr, ch, fhBytes, siBytes, freeFrameBytes; - int prevBitOffset, sfBlockBits, huffBlockBits; - unsigned char *mainPtr; + int32_t offset, bitOffset, mainBits, gr, ch, fhBytes, siBytes, freeFrameBytes; + int32_t prevBitOffset, sfBlockBits, huffBlockBits; + uint8_t *mainPtr; uint8_t underflowCounter = 0; // http://macslons-irish-pub-radio.stream.laut.fm/macslons-irish-pub-radio /* unpack frame header */ @@ -1844,6 +1844,7 @@ uint32_t MP3Decoder_AllocateBuffers(void) { //log_e("not enough memory to allocate mp3decoder buffers"); return 0; } + MP3Decoder_ClearBuffer(); uint32_t memory = 0; @@ -1908,14 +1909,14 @@ void MP3Decoder_FreeBuffers() { * necessarily all linBits outputs for x,y > 15) **********************************************************************************************************************/ // no improvement with section=data -int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned char *buf, int bitOffset){ +int32_t DecodeHuffmanPairs(int32_t *xy, int32_t nVals, int32_t tabIdx, int32_t bitsLeft, uint8_t *buf, int32_t bitOffset) { SETREGS - int i, x, y; - int cachedBits, padBits, len, startBits, linBits, maxBits, minBits; + int32_t i, x, y; + int32_t cachedBits, padBits, len, startBits, linBits, maxBits, minBits; HuffTabType_t tabType; - unsigned short cw, *tBase, *tCurr; - unsigned int cache; - const int *ic = (const int*)((uint8_t *)iconst+EXEC_OFFSET); + uint16_t cw, *tBase, *tCurr; + uint32_t cache; + const int32_t *ic = (const int32_t*)((uint8_t *)iconst+EXEC_OFFSET); uint32_t bmask = ic[0]; if (nVals <= 0) @@ -1925,9 +1926,9 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch return -1; startBits = bitsLeft; - //tBase = (unsigned short *) (huffTable + huffTabOffset[tabIdx]); - tBase = (unsigned short *) ((uint8_t *)huffTable+EXEC_OFFSET); - const int *op = (const int *) ((uint8_t *)huffTabOffset+EXEC_OFFSET); + //tBase = (uint16_t *) (huffTable + huffTabOffset[tabIdx]); + tBase = (uint16_t *) ((uint8_t *)huffTable+EXEC_OFFSET); + const int32_t *op = (const int32_t *) ((uint8_t *)huffTabOffset+EXEC_OFFSET); tBase += op[tabIdx]; //linBits = huffTabLookup[tabIdx].linBits; @@ -1966,7 +1967,7 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch cache = 0; cachedBits = (8 - bitOffset) & 0x07; if (cachedBits) { - cache = (unsigned int) (*buf++) << (32 - cachedBits); + cache = (uint32_t) (*buf++) << (32 - cachedBits); } bitsLeft -= cachedBits; @@ -1980,15 +1981,15 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch } else if (tabType == oneShot) { /* single lookup, no escapes */ - maxBits = (int)( (((unsigned short)(pgm_read_word(&tBase[0])) >> 0) & 0x000f)); + maxBits = (int32_t)( (((uint16_t)(pgm_read_word(&tBase[0])) >> 0) & 0x000f)); tBase++; padBits = 0; while (nVals > 0) { /* refill cache - assumes cachedBits <= 16 */ if (bitsLeft >= 16) { /* load 2 new bytes into left-justified cache */ - cache |= (unsigned int) (*buf++) << (24 - cachedBits); - cache |= (unsigned int) (*buf++) << (16 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (16 - cachedBits); cachedBits += 16; bitsLeft -= 16; } else { @@ -1996,13 +1997,13 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch if (cachedBits + bitsLeft <= 0) return -1; if (bitsLeft > 0) - cache |= (unsigned int) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); if (bitsLeft > 8) - cache |= (unsigned int) (*buf++) << (16 - cachedBits); + cache |= (uint32_t) (*buf++) << (16 - cachedBits); cachedBits += bitsLeft; bitsLeft = 0; - cache &= (signed int) bmask >> (cachedBits - 1); + cache &= (int32_t) bmask >> (cachedBits - 1); padBits = 11; cachedBits += padBits; /* okay if this is > 32 (0's automatically shifted in from right) */ } @@ -2011,18 +2012,18 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch while (nVals > 0 && cachedBits >= 11) { cw = pgm_read_word(&tBase[cache >> (32 - maxBits)]); - len=(int)( (((unsigned short)(cw)) >> 12) & 0x000f); + len=(int32_t)( (((uint16_t)(cw)) >> 12) & 0x000f); cachedBits -= len; cache <<= len; - x=(int)( (((unsigned short)(cw)) >> 4) & 0x000f); + x=(int32_t)( (((uint16_t)(cw)) >> 4) & 0x000f); if (x) { (x) |= ((cache) & bmask); cache <<= 1; cachedBits--; } - y=(int)( (((unsigned short)(cw)) >> 8) & 0x000f); + y=(int32_t)( (((uint16_t)(cw)) >> 8) & 0x000f); if (y) { (y) |= ((cache) & bmask); cache <<= 1; @@ -2048,8 +2049,8 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch /* refill cache - assumes cachedBits <= 16 */ if (bitsLeft >= 16) { /* load 2 new bytes into left-justified cache */ - cache |= (unsigned int) (*buf++) << (24 - cachedBits); - cache |= (unsigned int) (*buf++) << (16 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (16 - cachedBits); cachedBits += 16; bitsLeft -= 16; } else { @@ -2058,24 +2059,24 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch return -1; } if (bitsLeft > 0) { - cache |= (unsigned int) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); } if (bitsLeft > 8) { - cache |= (unsigned int) (*buf++) << (16 - cachedBits); + cache |= (uint32_t) (*buf++) << (16 - cachedBits); } cachedBits += bitsLeft; bitsLeft = 0; - cache &= (signed int) bmask >> (cachedBits - 1); + cache &= (int32_t) bmask >> (cachedBits - 1); padBits = 11; cachedBits += padBits; /* okay if this is > 32 (0's automatically shifted in from right) */ } /* largest maxBits = 9, plus 2 for sign bits, so make sure cache has at least 11 bits */ while (nVals > 0 && cachedBits >= 11) { - maxBits = (int)( (((unsigned short)(pgm_read_word(&tCurr[0]))) >> 0) & 0x000f); + maxBits = (int32_t)( (((uint16_t)(pgm_read_word(&tCurr[0]))) >> 0) & 0x000f); cw = pgm_read_word(&tCurr[(cache >> (32 - maxBits)) + 1]); - len=(int)( (((unsigned short)(cw)) >> 12) & 0x000f); + len=(int32_t)( (((uint16_t)(cw)) >> 12) & 0x000f); if (!len) { cachedBits -= maxBits; cache <<= maxBits; @@ -2085,24 +2086,24 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch cachedBits -= len; cache <<= len; - x=(int)( (((unsigned short)(cw)) >> 4) & 0x000f); - y=(int)( (((unsigned short)(cw)) >> 8) & 0x000f); + x=(int32_t)( (((uint16_t)(cw)) >> 4) & 0x000f); + y=(int32_t)( (((uint16_t)(cw)) >> 8) & 0x000f); if (x == 15 && tabType == loopLinbits) { minBits = linBits + 1 + (y ? 1 : 0); if (cachedBits + bitsLeft < minBits) return -1; while (cachedBits < minBits) { - cache |= (unsigned int) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); cachedBits += 8; bitsLeft -= 8; } if (bitsLeft < 0) { cachedBits += bitsLeft; bitsLeft = 0; - cache &= (signed int) bmask >> (cachedBits - 1); + cache &= (int32_t) bmask >> (cachedBits - 1); } - x += (int) (cache >> (32 - linBits)); + x += (int32_t) (cache >> (32 - linBits)); cachedBits -= linBits; cache <<= linBits; } @@ -2117,16 +2118,16 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch if (cachedBits + bitsLeft < minBits) return -1; while (cachedBits < minBits) { - cache |= (unsigned int) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); cachedBits += 8; bitsLeft -= 8; } if (bitsLeft < 0) { cachedBits += bitsLeft; bitsLeft = 0; - cache &= (signed int) bmask >> (cachedBits - 1); + cache &= (int32_t) bmask >> (cachedBits - 1); } - y += (int) (cache >> (32 - linBits)); + y += (int32_t) (cache >> (32 - linBits)); cachedBits -= linBits; cache <<= linBits; } @@ -2175,32 +2176,32 @@ int DecodeHuffmanPairs(int *xy, int nVals, int tabIdx, int bitsLeft, unsigned ch * Notes: si_huff.bit tests every vwxy output in both quad tables **********************************************************************************************************************/ // no improvement with section=data -int DecodeHuffmanQuads(int *vwxy, int nVals, int tabIdx, int bitsLeft, unsigned char *buf, int bitOffset){ +int32_t DecodeHuffmanQuads(int32_t *vwxy, int32_t nVals, int32_t tabIdx, int32_t bitsLeft, uint8_t *buf, int32_t bitOffset){ SETREGS - int i, v, w, x, y; - int len, maxBits, cachedBits, padBits; - unsigned int cache; - unsigned char cw, *tBase; + int32_t i, v, w, x, y; + int32_t len, maxBits, cachedBits, padBits; + uint32_t cache; + uint8_t cw, *tBase; - const int *ic = (const int*)((uint8_t *)iconst+EXEC_OFFSET); + const int32_t *ic = (const int32_t*)((uint8_t *)iconst+EXEC_OFFSET); uint32_t bmask = ic[0]; if (bitsLeft<=0) return 0; //AddLog(LOG_LEVEL_INFO, PSTR("DecodeHuffmanQuads 1")); - //tBase = (unsigned char *) quadTable + quadTabOffset[tabIdx]; + //tBase = (uint8_t *) quadTable + quadTabOffset[tabIdx]; //maxBits = quadTabMaxBits[tabIdx]; - tBase = (unsigned char *) (const unsigned char *) ((uint8_t *)quadTable+EXEC_OFFSET); - tBase += ((const int *) ((uint8_t *)quadTabOffset+EXEC_OFFSET))[tabIdx]; + tBase = (uint8_t *) (const uint8_t *) ((uint8_t *)quadTable+EXEC_OFFSET); + tBase += ((const int32_t *) ((uint8_t *)quadTabOffset+EXEC_OFFSET))[tabIdx]; - maxBits = ((const int *) ((uint8_t *)quadTabMaxBits+EXEC_OFFSET))[tabIdx]; + maxBits = ((const int32_t *) ((uint8_t *)quadTabMaxBits+EXEC_OFFSET))[tabIdx]; /* initially fill cache with any partial byte */ cache = 0; cachedBits = (8-bitOffset) & 0x07; - if (cachedBits)cache = (unsigned int)(*buf++) << (32 - cachedBits); + if (cachedBits)cache = (uint32_t)(*buf++) << (32 - cachedBits); bitsLeft -= cachedBits; //AddLog(LOG_LEVEL_INFO, PSTR("DecodeHuffmanQuads 2")); @@ -2210,19 +2211,19 @@ int DecodeHuffmanQuads(int *vwxy, int nVals, int tabIdx, int bitsLeft, unsigned /* refill cache - assumes cachedBits <= 16 */ if (bitsLeft >= 16) { /* load 2 new bytes into left-justified cache */ - cache |= (unsigned int) (*buf++) << (24 - cachedBits); - cache |= (unsigned int) (*buf++) << (16 - cachedBits); + cache |= (uint32_t) (*buf++) << (24 - cachedBits); + cache |= (uint32_t) (*buf++) << (16 - cachedBits); cachedBits += 16; bitsLeft -= 16; } else { /* last time through, pad cache with zeros and drain cache */ if(cachedBits+bitsLeft <= 0) return i; - if(bitsLeft>0) cache |= (unsigned int)(*buf++)<<(24-cachedBits); - if (bitsLeft > 8) cache |= (unsigned int)(*buf++)<<(16 - cachedBits); + if(bitsLeft>0) cache |= (uint32_t)(*buf++)<<(24-cachedBits); + if (bitsLeft > 8) cache |= (uint32_t)(*buf++)<<(16 - cachedBits); cachedBits += bitsLeft; bitsLeft = 0; - cache &= (signed int) bmask >> (cachedBits - 1); + cache &= (int32_t) bmask >> (cachedBits - 1); padBits = 10; cachedBits += padBits; /* okay if this is > 32 (0's automatically shifted in from right) */ } @@ -2230,31 +2231,31 @@ int DecodeHuffmanQuads(int *vwxy, int nVals, int tabIdx, int bitsLeft, unsigned /* largest maxBits = 6, plus 4 for sign bits, so make sure cache has at least 10 bits */ while(i < (nVals - 3) && cachedBits >= 10){ cw = pgm_read_byte(&tBase[cache >> (32 - maxBits)]); - len=(int)( (((unsigned char)(cw)) >> 4) & 0x0f); + len=(int32_t)( (((uint8_t)(cw)) >> 4) & 0x0f); cachedBits -= len; cache <<= len; - v=(int)( (((unsigned char)(cw)) >> 3) & 0x01); + v=(int32_t)( (((uint8_t)(cw)) >> 3) & 0x01); if (v) { (v) |= ((cache) & bmask); cache <<= 1; cachedBits--; } - w=(int)( (((unsigned char)(cw)) >> 2) & 0x01); + w=(int32_t)( (((uint8_t)(cw)) >> 2) & 0x01); if (w) { (w) |= ((cache) & bmask); cache <<= 1; cachedBits--; } - x=(int)( (((unsigned char)(cw)) >> 1) & 0x01); + x=(int32_t)( (((uint8_t)(cw)) >> 1) & 0x01); if (x) { (x) |= ((cache) & bmask); cache <<= 1; cachedBits--; } - y=(int)( (((unsigned char)(cw)) >> 0) & 0x01); + y=(int32_t)( (((uint8_t)(cw)) >> 0) & 0x01); if (y) { (y) |= ((cache) & bmask); cache <<= 1; @@ -2302,12 +2303,12 @@ int DecodeHuffmanQuads(int *vwxy, int nVals, int tabIdx, int bitsLeft, unsigned * out of bits prematurely (invalid bitstream) **********************************************************************************************************************/ // .data about 1ms faster per frame -int DecodeHuffman(unsigned char *buf, int *bitOffset, int huffBlockBits, int gr, int ch){ +int32_t DecodeHuffman(uint8_t *buf, int32_t *bitOffset, int32_t huffBlockBits, int32_t gr, int32_t ch){ SETREGS - int r1Start, r2Start, rEnd[4]; /* region boundaries */ - int i, w, bitsUsed, bitsLeft; - unsigned char *startBuf = buf; + int32_t r1Start, r2Start, rEnd[4]; /* region boundaries */ + int32_t i, w, bitsUsed, bitsLeft; + uint8_t *startBuf = buf; SideInfoSub_t *sis; sis = &mp3m.m_SideInfoSub[gr][ch]; @@ -2415,8 +2416,8 @@ int DecodeHuffman(unsigned char *buf, int *bitOffset, int huffBlockBits, int gr, * Equivalently, we can think of the dequantized coefficients as * Q(DQ_FRACBITS_OUT - 15) with no implicit bias. **********************************************************************************************************************/ -int MP3Dequantize(int gr){ - int i, ch, nSamps, mOut[2]; +int32_t MP3Dequantize(int32_t gr){ + int32_t i, ch, nSamps, mOut[2]; SETREGS CriticalBandInfo_t *cbi; cbi = &mp3m.m_CriticalBandInfo[0]; @@ -2440,9 +2441,9 @@ int MP3Dequantize(int gr){ * in practice this may never happen */ - const int *ic = (const int*)((uint8_t *)iconst+EXEC_OFFSET); - const int x3f = ic[1]; // 0x3fffffff - const int mx3f = 0-ic[1]; // -0x3fffffff + const int32_t *ic = (const int32_t*)((uint8_t *)iconst+EXEC_OFFSET); + const int32_t x3f = ic[1]; // 0x3fffffff + const int32_t mx3f = 0-ic[1]; // -0x3fffffff if (mp3m.m_FrameHeader->modeExt && (mp3m.m_HuffmanInfo->gb[0] < 1 || mp3m.m_HuffmanInfo->gb[1] < 1)) { for (i = 0; i < mp3m.m_HuffmanInfo->nonZeroBound[0]; i++) { @@ -2523,17 +2524,17 @@ int MP3Dequantize(int gr){ * * Return: bitwise-OR of the unsigned outputs (for guard bit calculations) **********************************************************************************************************************/ -int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { +int32_t DequantBlock(int32_t *inbuf, int32_t *outbuf, int32_t num, int32_t scale) { SETREGS //.literal .LC65, 1073741808 // 3ffffff0 - int tab4[4]; - int scalef, scalei, shift; - int sx, x, y; - int mask = 0; - const int *tab16; - const unsigned int *coef; + int32_t tab4[4]; + int32_t scalef, scalei, shift; + int32_t sx, x, y; + int32_t mask = 0; + const int32_t *tab16; + const uint32_t *coef; //tab16 = pow43_14[scale & 0x3]; @@ -2544,7 +2545,7 @@ int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { //scalef = pow14[scale & 0x3]; - const int *p14 = (const int*)((uint8_t *)pow14+EXEC_OFFSET); + const int32_t *p14 = (const int32_t*)((uint8_t *)pow14+EXEC_OFFSET); scalef = p14[scale & 0x3]; //AddLog(LOG_LEVEL_INFO, PSTR("DequantBlock 2")); @@ -2563,8 +2564,8 @@ int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { // p14[0] = 0x7fffffff uint32_t pmask = p14[0]; - const int *p43 = (const int*)((uint8_t *)pow43+EXEC_OFFSET); - const unsigned int *sh = (const unsigned int *) ((uint8_t *)m_SQRTHALF+EXEC_OFFSET); + const int32_t *p43 = (const int32_t*)((uint8_t *)pow43+EXEC_OFFSET); + const uint32_t *sh = (const uint32_t *) ((uint8_t *)m_SQRTHALF+EXEC_OFFSET); do { sx = *inbuf++; @@ -2593,7 +2594,7 @@ int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { x <<= 17; shift = 0; - //const unsigned int *sh = (const unsigned int *) ((uint8_t *)m_SQRTHALF+EXEC_OFFSET); + //const uint32_t *sh = (const uint32_t *) ((uint8_t *)m_SQRTHALF+EXEC_OFFSET); if (x < sh[1]) x <<= 4, shift += 4; @@ -2603,8 +2604,8 @@ int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { x <<= 1, shift += 1; //coef = (x < m_SQRTHALF) ? poly43lo : poly43hi; - const unsigned int *lop = (const unsigned int *) ((uint8_t *)poly43lo+EXEC_OFFSET); - const unsigned int *hip = (const unsigned int *) ((uint8_t *)poly43hi+EXEC_OFFSET); + const uint32_t *lop = (const uint32_t *) ((uint8_t *)poly43lo+EXEC_OFFSET); + const uint32_t *hip = (const uint32_t *) ((uint8_t *)poly43hi+EXEC_OFFSET); coef = (x < sh[0]) ? lop : hip; @@ -2616,14 +2617,14 @@ int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { y = MULSHIFT32(y, x) + coef[4]; //y = MULSHIFT32(y, pow2frac[shift]) << 3; - const int *p2f = (const int *) ((uint8_t *)pow2frac+EXEC_OFFSET); + const int32_t *p2f = (const int32_t *) ((uint8_t *)pow2frac+EXEC_OFFSET); y = MULSHIFT32(y, p2f[shift]) << 3; /* fractional scale */ y = MULSHIFT32(y, scalef); // shift = scalei - pow2exp[shift]; - const int *p2e = (const int *) ((uint8_t *)pow2exp+EXEC_OFFSET); + const int32_t *p2e = (const int32_t *) ((uint8_t *)pow2exp+EXEC_OFFSET); shift = scalei - p2e[shift]; @@ -2677,16 +2678,16 @@ int DequantBlock(int *inbuf, int *outbuf, int num, int scale) { * * Notes: dequantized samples in Q(DQ_FRACBITS_OUT) format **********************************************************************************************************************/ -int DequantChannel(int *sampleBuf, int *workBuf, int *nonZeroBound, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, +int32_t DequantChannel(int32_t *sampleBuf, int32_t *workBuf, int32_t *nonZeroBound, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi) { SETREGS - int i, j, w, cb; - int /* cbStartL, */ cbEndL, cbStartS, cbEndS; - int nSamps, nonZero, sfactMultiplier, gbMask; - int globalGain, gainI; - int cbMax[3]; - typedef int ARRAY3[3]; /* for short-block reordering */ + int32_t i, j, w, cb; + int32_t /* cbStartL, */ cbEndL, cbStartS, cbEndS; + int32_t nSamps, nonZero, sfactMultiplier, gbMask; + int32_t globalGain, gainI; + int32_t cbMax[3]; + typedef int32_t ARRAY3[3]; /* for short-block reordering */ ARRAY3 *buf; /* short block reorder */ //AddLog(LOG_LEVEL_INFO, PSTR("DequantChannel 1")); @@ -2740,9 +2741,9 @@ int DequantChannel(int *sampleBuf, int *workBuf, int *nonZeroBound, SideInfoSub const char *pt = &preTab[cb]; pt += EXEC_OFFSET; - int ptb = pgm_read_byte(pt); + int32_t ptb = pgm_read_byte(pt); - //gainI = 210 - globalGain + sfactMultiplier * (sfis->l[cb] + (sis->preFlag ? (int)preTab[cb] : 0)); + //gainI = 210 - globalGain + sfactMultiplier * (sfis->l[cb] + (sis->preFlag ? (int32_t)preTab[cb] : 0)); gainI = 210 - globalGain + sfactMultiplier * (sfis->l[cb] + (sis->preFlag ? ptb : 0)); nonZero |= DequantBlock(sampleBuf + i, sampleBuf + i, nSamps, gainI); @@ -2860,8 +2861,8 @@ uint32_t my_clz(uint32_t in) { * * Notes: assume at least 1 GB in input **********************************************************************************************************************/ -void MidSideProc(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, int mOut[2]){ - int i, xr, xl, mOutL, mOutR; +void MidSideProc(int32_t x[m_MAX_NCHAN][m_MAX_NSAMP], int32_t nSamps, int32_t mOut[2]){ + int32_t i, xr, xl, mOutL, mOutR; /* L = (M+S)/sqrt(2), R = (M-S)/sqrt(2) * NOTE: 1/sqrt(2) done in DequantChannel() - see comments there @@ -2899,15 +2900,15 @@ void MidSideProc(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, int mOut[2]){ * Notes: assume at least 1 GB in input * **********************************************************************************************************************/ -void IntensityProcMPEG1(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFactorInfoSub_t *sfis, - CriticalBandInfo_t *cbi, int midSideFlag, int mixFlag, int mOut[2]) +void IntensityProcMPEG1(int32_t x[m_MAX_NCHAN][m_MAX_NSAMP], int32_t nSamps, ScaleFactorInfoSub_t *sfis, + CriticalBandInfo_t *cbi, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]) { SETREGS - int i = 0, j = 0, n = 0, cb = 0, w = 0; - int sampsLeft, isf, mOutL, mOutR, xl, xr; - int fl, fr, fls[3], frs[3]; - int cbStartL = 0, cbStartS = 0, cbEndL = 0, cbEndS = 0; - int *isfTab; + int32_t i = 0, j = 0, n = 0, cb = 0, w = 0; + int32_t sampsLeft, isf, mOutL, mOutR, xl, xr; + int32_t fl, fr, fls[3], frs[3]; + int32_t cbStartL = 0, cbStartS = 0, cbEndL = 0, cbEndS = 0; + int32_t *isfTab; (void) mixFlag; /* NOTE - this works fine for mixed blocks, as long as the switch point starts in the @@ -2928,8 +2929,8 @@ void IntensityProcMPEG1(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFacto i = 3 * mp3m.m_SFBandTable.s[cbStartS]; } sampsLeft = nSamps - i; /* process to length of left */ - // isfTab = (int *) ISFMpeg1[midSideFlag]; - isfTab = (int *) ISFMpeg1[midSideFlag]; + // isfTab = (int32_t *) ISFMpeg1[midSideFlag]; + isfTab = (int32_t *) ISFMpeg1[midSideFlag]; isfTab += EXEC_OFFSET >> 2; mOutL = mOutR = 0; @@ -2942,9 +2943,9 @@ void IntensityProcMPEG1(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFacto fl = ISFIIP[midSideFlag][0]; fr = ISFIIP[midSideFlag][1]; #else - const int *flp = &ISFIIP[midSideFlag][0]; + const int32_t *flp = &ISFIIP[midSideFlag][0]; flp += EXEC_OFFSET >> 2; - const int *frp = &ISFIIP[midSideFlag][1]; + const int32_t *frp = &ISFIIP[midSideFlag][1]; frp += EXEC_OFFSET >> 2; fl = *flp; fr = *frp; @@ -2974,9 +2975,9 @@ void IntensityProcMPEG1(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFacto fls[w] = ISFIIP[midSideFlag][0]; frs[w] = ISFIIP[midSideFlag][1]; #else - const int *flp = &ISFIIP[midSideFlag][0]; + const int32_t *flp = &ISFIIP[midSideFlag][0]; flp += EXEC_OFFSET >> 2; - const int *frp = &ISFIIP[midSideFlag][1]; + const int32_t *frp = &ISFIIP[midSideFlag][1]; frp += EXEC_OFFSET >> 2; fls[w] = *flp; frs[w] = *frp; @@ -3035,22 +3036,22 @@ void IntensityProcMPEG1(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFacto * Notes: assume at least 1 GB in input * **********************************************************************************************************************/ -void IntensityProcMPEG2(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, +void IntensityProcMPEG2(int32_t x[m_MAX_NCHAN][m_MAX_NSAMP], int32_t nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, - ScaleFactorJS_t *sfjs, int midSideFlag, int mixFlag, int mOut[2]) { + ScaleFactorJS_t *sfjs, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]) { SETREGS - int i, j, k, n, r, cb, w; - int fl, fr, mOutL, mOutR, xl, xr; - int sampsLeft; - int isf, sfIdx, tmp, il[23]; - int *isfTab; - int cbStartL, cbStartS, cbEndL, cbEndS; + int32_t i, j, k, n, r, cb, w; + int32_t fl, fr, mOutL, mOutR, xl, xr; + int32_t sampsLeft; + int32_t isf, sfIdx, tmp, il[23]; + int32_t *isfTab; + int32_t cbStartL, cbStartS, cbEndL, cbEndS; (void) mixFlag; - isfTab = (int *) ISFMpeg2[sfjs->intensityScale][midSideFlag]; + isfTab = (int32_t *) ISFMpeg2[sfjs->intensityScale][midSideFlag]; isfTab += EXEC_OFFSET >> 2; mOutL = mOutR = 0; @@ -3076,9 +3077,9 @@ void IntensityProcMPEG2(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, fl = ISFIIP[midSideFlag][0]; fr = ISFIIP[midSideFlag][1]; #else - const int *flp = &ISFIIP[midSideFlag][0]; + const int32_t *flp = &ISFIIP[midSideFlag][0]; flp += EXEC_OFFSET >> 2; - const int *frp = &ISFIIP[midSideFlag][1]; + const int32_t *frp = &ISFIIP[midSideFlag][1]; frp += EXEC_OFFSET >> 2; fl = *flp; fr = *frp; @@ -3088,7 +3089,7 @@ void IntensityProcMPEG2(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, fl = isfTab[(sfIdx & 0x01 ? isf : 0)]; fr = isfTab[(sfIdx & 0x01 ? 0 : isf)]; } - int r=mp3m.m_SFBandTable.l[cb + 1] - mp3m.m_SFBandTable.l[cb]; + int32_t r=mp3m.m_SFBandTable.l[cb + 1] - mp3m.m_SFBandTable.l[cb]; n=(r < sampsLeft ? r : sampsLeft); //n = MIN(fh->sfBand->l[cb + 1] - fh->sfBand->l[cb], sampsLeft); for (j = 0; j < n; j++, i++) { @@ -3121,9 +3122,9 @@ void IntensityProcMPEG2(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, fl = ISFIIP[midSideFlag][0]; fr = ISFIIP[midSideFlag][1]; #else - const int *flp = &ISFIIP[midSideFlag][0]; + const int32_t *flp = &ISFIIP[midSideFlag][0]; flp += EXEC_OFFSET >> 2; - const int *frp = &ISFIIP[midSideFlag][1]; + const int32_t *frp = &ISFIIP[midSideFlag][1]; frp += EXEC_OFFSET >> 2; fl = *flp; fr = *frp; @@ -3181,9 +3182,9 @@ void IntensityProcMPEG2(int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, **********************************************************************************************************************/ // a little bit faster in RAM (< 1 ms per block) /* __attribute__ ((section (".data"))) */ -void AntiAlias(int *x, int nBfly){ +void AntiAlias(int32_t *x, int32_t nBfly){ SETREGS - int k, a0, b0, c0, c1; + int32_t k, a0, b0, c0, c1; const uint32_t *c; const uint32_t *csap = (const uint32_t *) ((uint8_t *)csa+EXEC_OFFSET); @@ -3284,9 +3285,9 @@ void AntiAlias(int *x, int nBfly){ * sign bit, short blocks can have one addition but max gain < 1.0) **********************************************************************************************************************/ -void WinPrevious(int *xPrev, int *xPrevWin, int btPrev){ +void WinPrevious(int32_t *xPrev, int32_t *xPrevWin, int32_t btPrev){ SETREGS - int i, x, *xp, *xpwLo, *xpwHi, wLo, wHi; + int32_t i, x, *xp, *xpwLo, *xpwHi, wLo, wHi; const uint32_t *wpLo, *wpHi; xp = xPrev; @@ -3354,7 +3355,7 @@ void WinPrevious(int *xPrev, int *xPrevWin, int btPrev){ * Return: updated mOut (from new outputs y) **********************************************************************************************************************/ -int FreqInvertRescale(int *y, int *xPrev, int blockIdx, int es) { +int32_t FreqInvertRescale(int32_t *y, int32_t *xPrev, int32_t blockIdx, int32_t es) { // .literal .LC36, 2432 @@ -3362,26 +3363,26 @@ int FreqInvertRescale(int *y, int *xPrev, int blockIdx, int es) { /* fast case - frequency invert only (no rescaling) */ if (blockIdx & 0x01) { y += m_NBANDS; - for (int i = 0; i < 9; i++) { + for (int32_t i = 0; i < 9; i++) { *y = - *y; y += 2 * m_NBANDS; } } return 0; } - int d, mOut; + int32_t d, mOut; /* undo pre-IMDCT scaling, clipping if necessary */ mOut = 0; int32_t esdiff = 31 - es; if (blockIdx & 0x01) { /* frequency invert */ - for (int i = 0; i < 9; i++) { + for (int32_t i = 0; i < 9; i++) { d = *y; CLIP_2N(d, esdiff); *y = d << es; mOut |= FASTABS(*y); y += m_NBANDS; d = -*y; CLIP_2N(d, esdiff); *y = d << es; mOut |= FASTABS(*y); y += m_NBANDS; d = *xPrev; CLIP_2N(d, esdiff); *xPrev++ = d << es; } } else { - for (int i = 0; i < 9; i++) { + for (int32_t i = 0; i < 9; i++) { d = *y; CLIP_2N(d, esdiff); *y = d << es; mOut |= FASTABS(*y); y += m_NBANDS; d = *y; CLIP_2N(d, esdiff); *y = d << es; mOut |= FASTABS(*y); y += m_NBANDS; d = *xPrev; CLIP_2N(d, esdiff); *xPrev++ = d << es; @@ -3393,16 +3394,16 @@ int FreqInvertRescale(int *y, int *xPrev, int blockIdx, int es) { /* require at least 3 guard bits in x[] to ensure no overflow */ -void idct9(int *x) { +void idct9(int32_t *x) { SETREGS //AddLog(LOG_LEVEL_INFO, PSTR("idct9 1")); - int a1, a2, a3, a4, a5, a6, a7, a8, a9; - int a10, a11, a12, a13, a14, a15, a16, a17, a18; - int a19, a20, a21, a22, a23, a24, a25, a26, a27; - int m1, m3, m5, m6, m7, m8, m9, m10, m11, m12; - int x0, x1, x2, x3, x4, x5, x6, x7, x8; + int32_t a1, a2, a3, a4, a5, a6, a7, a8, a9; + int32_t a10, a11, a12, a13, a14, a15, a16, a17, a18; + int32_t a19, a20, a21, a22, a23, a24, a25, a26, a27; + int32_t m1, m3, m5, m6, m7, m8, m9, m10, m11, m12; + int32_t x0, x1, x2, x3, x4, x5, x6, x7, x8; x0 = x[0]; x1 = x[1]; @@ -3441,7 +3442,7 @@ void idct9(int *x) { m12 = MULSHIFT32(c9_4, a9); */ - const int *c9xp = (const int *) ((uint8_t *)c9_x+EXEC_OFFSET); + const int32_t *c9xp = (const int32_t *) ((uint8_t *)c9_x+EXEC_OFFSET); m1 = MULSHIFT32(c9xp[0], x3); m3 = MULSHIFT32(c9xp[0], a10); m5 = MULSHIFT32(c9xp[1], a5); @@ -3525,20 +3526,20 @@ void idct9(int *x) { **********************************************************************************************************************/ // barely faster in RAM -int IMDCT36(int *xCurr, int *xPrev, int *y, int btCurr, int btPrev, int blockIdx, int gb){ +int32_t IMDCT36(int32_t *xCurr, int32_t *xPrev, int32_t *y, int32_t btCurr, int32_t btPrev, int32_t blockIdx, int32_t gb){ SETREGS //AddLog(LOG_LEVEL_INFO, PSTR("IMDCT36 1")); - int i, es; + int32_t i, es; //int xBuf[18]; //int xPrevWin[18]; - int *xBuf = (int*)calloc(18, sizeof(int)); - int *xPrevWin = (int*)calloc(18, sizeof(int)); + int32_t *xBuf = (int32_t*)calloc(18, sizeof(int32_t)); + int32_t *xPrevWin = (int32_t*)calloc(18, sizeof(int32_t)); - int acc1, acc2, s, d, t, mOut; - int xo, xe, c, *xp, yLo, yHi; + int32_t acc1, acc2, s, d, t, mOut; + int32_t xo, xe, c, *xp, yLo, yHi; const uint32_t *cp, *wp; acc1 = acc2 = 0; xCurr += 17; @@ -3660,10 +3661,10 @@ int IMDCT36(int *xCurr, int *xPrev, int *y, int btCurr, int btPrev, int blockIdx /* 12-point inverse DCT, used in IMDCT12x3() * 4 input guard bits will ensure no overflow */ -void imdct12(int *x, int *out) { +void imdct12(int32_t *x, int32_t *out) { SETREGS - int a0, a1, a2; - int x0, x1, x2, x3, x4, x5; + int32_t a0, a1, a2; + int32_t x0, x1, x2, x3, x4, x5; x0 = *x; x += 3; @@ -3689,7 +3690,7 @@ void imdct12(int *x, int *out) { x0 >>= 1; x1 >>= 1; - const int *c30p = (const int *) ((uint8_t *)c3_0+EXEC_OFFSET); + const int32_t *c30p = (const int32_t *) ((uint8_t *)c3_0+EXEC_OFFSET); a0 = MULSHIFT32(*c30p, x2) << 1; a1 = x0 + (x4 >> 1); @@ -3702,7 +3703,7 @@ void imdct12(int *x, int *out) { a1 = x1 + (x5 >> 1); a2 = x1 - x5; - const int *c6p = (const int *) ((uint8_t *)c6+EXEC_OFFSET); + const int32_t *c6p = (const int32_t *) ((uint8_t *)c6+EXEC_OFFSET); /* cos window odd samples, mul by 2, eat sign bit */ x1 = MULSHIFT32(c6p[0], a1 + a0) << 2; @@ -3742,9 +3743,9 @@ void imdct12(int *x, int *out) { * Return: mOut (OR of abs(y) for all y calculated here) **********************************************************************************************************************/ // barely faster in RAM -int IMDCT12x3(int *xCurr, int *xPrev, int *y, int btPrev, int blockIdx, int gb){ +int32_t IMDCT12x3(int32_t *xCurr, int32_t *xPrev, int32_t *y, int32_t btPrev, int32_t blockIdx, int32_t gb){ SETREGS - int i, es, mOut, yLo, xBuf[18], xPrevWin[18]; /* need temp buffer for reordering short blocks */ + int32_t i, es, mOut, yLo, xBuf[18], xPrevWin[18]; /* need temp buffer for reordering short blocks */ const uint32_t *wp; es = 0; /* 7 gb is always adequate for accumulator loop + idct12 + window + overlap */ @@ -3834,14 +3835,14 @@ int IMDCT12x3(int *xCurr, int *xPrev, int *y, int btPrev, int blockIdx, int gb){ * Return: number of non-zero IMDCT blocks calculated in this call * (including overlap-add) **********************************************************************************************************************/ -int HybridTransform(int *xCurr, int *xPrev, int y[m_BLOCK_SIZE][m_NBANDS], SideInfoSub_t *sis, BlockCount_t *bc){ +int32_t HybridTransform(int32_t *xCurr, int32_t *xPrev, int32_t y[m_BLOCK_SIZE][m_NBANDS], SideInfoSub_t *sis, BlockCount_t *bc){ SETREGS // .literal .LC55, 2304 - int xPrevWin[18], currWinIdx, prevWinIdx; - int i, j, nBlocksOut, nonZero, mOut; - int fiBit, xp; + int32_t xPrevWin[18], currWinIdx, prevWinIdx; + int32_t i, j, nBlocksOut, nonZero, mOut; + int32_t fiBit, xp; // >>>> assert(bc->nBlocksLong <= m_NBANDS); // >>>> assert(bc->nBlocksTotal <= m_NBANDS); @@ -3949,8 +3950,8 @@ int HybridTransform(int *xCurr, int *xPrev, int y[m_BLOCK_SIZE][m_NBANDS], SideI **********************************************************************************************************************/ // a bit faster in RAM /*__attribute__ ((section (".data")))*/ -int IMDCT( int gr, int ch) { - int nBfly, blockCutoff; +int32_t IMDCT( int32_t gr, int32_t ch) { + int32_t nBfly, blockCutoff; BlockCount_t bc; SETREGS /* mp3m.m_SideInfo is an array of up to 4 structs, stored as gr0ch0, gr0ch1, gr1ch0, gr1ch1 */ @@ -3969,7 +3970,7 @@ int IMDCT( int gr, int ch) { if (mp3m.m_SideInfoSub[gr][ch].blockType != 2) { /* all long transforms */ //int x=(mp3m.m_HuffmanInfo->nonZeroBound[ch] + 7) / 18 + 1; - int x = __divsi3((mp3m.m_HuffmanInfo->nonZeroBound[ch] + 7), 18) + 1; + int32_t x = __divsi3((mp3m.m_HuffmanInfo->nonZeroBound[ch] + 7), 18) + 1; bc.nBlocksLong=(x<32 ? x : 32); //bc.nBlocksLong = min((hi->nonZeroBound[ch] + 7) / 18 + 1, 32); nBfly = bc.nBlocksLong - 1; @@ -3987,8 +3988,8 @@ int IMDCT( int gr, int ch) { //AddLog(LOG_LEVEL_INFO, PSTR("IMDCT 2")); AntiAlias(mp3m.m_HuffmanInfo->huffDecBuf[ch], nBfly); - int x=mp3m.m_HuffmanInfo->nonZeroBound[ch]; - int y=nBfly * 18 + 8; + int32_t x=mp3m.m_HuffmanInfo->nonZeroBound[ch]; + int32_t y=nBfly * 18 + 8; mp3m.m_HuffmanInfo->nonZeroBound[ch]=(x>y ? x: y); @@ -4038,12 +4039,12 @@ int IMDCT( int gr, int ch) { * * Return: 0 on success, -1 if null input pointers **********************************************************************************************************************/ -int Subband( short *pcmBuf) { +int32_t Subband( short *pcmBuf) { SETREGS //AddLog(LOG_LEVEL_INFO, PSTR("Subband 1")); - int b; + int32_t b; if (mp3m.m_MP3DecInfo->nChans == 2) { /* stereo */ for (b = 0; b < m_BLOCK_SIZE; b++) { @@ -4126,17 +4127,17 @@ int Subband( short *pcmBuf) { const uint8_t FDCT32s1s2[16] PROGMEM = {5,3,3,2,2,1,1,1, 1,1,1,1,1,2,2,4}; -void FDCT32(int *buf, int *dest, int offset, int oddBlock, int gb) { +void FDCT32(int32_t *buf, int32_t *dest, int32_t offset, int32_t oddBlock, int32_t gb) { //.literal .LC43, -4032 SETREGS - int i, s, tmp, es; - const int *cptr = (const int*)m_dcttab; + int32_t i, s, tmp, es; + const int32_t *cptr = (const int32_t*)m_dcttab; cptr += EXEC_OFFSET >> 2; - int a0, a1, a2, a3, a4, a5, a6, a7; - int b0, b1, b2, b3, b4, b5, b6, b7; - int *d; + int32_t a0, a1, a2, a3, a4, a5, a6, a7; + int32_t b0, b1, b2, b3, b4, b5, b6, b7; + int32_t *d; /* scaling - ensure at least 6 guard bits for DCT * (in practice this is already true 99% of time, so this code is @@ -4279,7 +4280,7 @@ void FDCT32(int *buf, int *dest, int offset, int oddBlock, int gb) { * P O L Y P H A S E **********************************************************************************************************************/ inline -short ClipToShort(int x, int fracBits){ +short ClipToShort(int32_t x, int32_t fracBits){ /* assumes you've already rounded (x += (1 << (fracBits-1))) */ x >>= fracBits; @@ -4287,7 +4288,7 @@ short ClipToShort(int x, int fracBits){ #ifndef __XTENSA__ /* Ken's trick: clips to [-32768, 32767] */ //ok vor generic case (fb) - int sign = x >> 31; + int32_t sign = x >> 31; if (sign != (x >> 15)) x = sign ^ ((1 << 15) - 1); @@ -4314,13 +4315,13 @@ short ClipToShort(int x, int fracBits){ * * Return: none **********************************************************************************************************************/ -void PolyphaseMono(short *pcm, int *vbuf, const uint32_t *coefBase){ +void PolyphaseMono(short *pcm, int32_t *vbuf, const uint32_t *coefBase){ SETREGS - int i; + int32_t i; const uint32_t *coef; - int *vb1; - int vLo, vHi, c1, c2; + int32_t *vb1; + int32_t vLo, vHi, c1, c2; uint64_t sum1L, sum2L, rndVal; const uint64_t *ulc = (const uint64_t*)((uint8_t *)ulconst+EXEC_OFFSET); @@ -4334,26 +4335,26 @@ void PolyphaseMono(short *pcm, int *vbuf, const uint32_t *coefBase){ coef = coefBase; vb1 = vbuf; sum1L = rndVal; - for(int j=0; j<8; j++){ + for(int32_t j=0; j<8; j++){ c1=*coef; coef++; c2=*coef; coef++; vLo=*(vb1+(j)); vHi=*(vb1+(23-(j))); // 0...7 //sum1L=MADD64(sum1L, vLo, c1); //sum1L=MADD64(sum1L, vHi, -c2); sum1L += MADD64(vLo, c1); sum1L += MADD64(vHi, -c2); } - *(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 0) = ClipToShort((int32_t)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); /* special case, output sample 16 */ coef = coefBase + 256; vb1 = vbuf + 64 * 16; sum1L = rndVal; - for(int j=0; j<8; j++){ + for(int32_t j=0; j<8; j++){ c1=*coef; coef++; vLo=*(vb1+(j)); //sum1L = MADD64(sum1L, vLo, c1); // 0...7 sum1L += MADD64(vLo, c1); // 0...7 } - *(pcm + 16) = ClipToShort((int)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 16) = ClipToShort((int32_t)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); /* main convolution loop: sum1L = samples 1, 2, 3, ... 15 sum2L = samples 31, 30, ... 17 */ coef = coefBase + 16; @@ -4363,7 +4364,7 @@ void PolyphaseMono(short *pcm, int *vbuf, const uint32_t *coefBase){ /* right now, the compiler creates bad asm from this... */ for (i = 15; i > 0; i--) { sum1L = sum2L = rndVal; - for(int j = 0; j < 8; j++){ + for(int32_t j = 0; j < 8; j++){ c1 = *coef; coef++; c2 = *coef; coef++; vLo = *(vb1+(j)); vHi = *(vb1+(23-(j))); //sum1L = MADD64(sum1L, vLo, c1); //sum2L = MADD64(sum2L, vLo, c2); @@ -4375,8 +4376,8 @@ void PolyphaseMono(short *pcm, int *vbuf, const uint32_t *coefBase){ sum2L += MADD64(vHi, c1); } vb1 += 64; - *(pcm) = ClipToShort((int)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); - *(pcm + 2*i) = ClipToShort((int)SAR64(sum2L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm) = ClipToShort((int32_t)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 2*i) = ClipToShort((int32_t)SAR64(sum2L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); pcm++; } } @@ -4398,7 +4399,7 @@ void PolyphaseMono(short *pcm, int *vbuf, const uint32_t *coefBase){ * * Notes: interleaves PCM samples LRLRLR... **********************************************************************************************************************/ -void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ +void PolyphaseStereo(short *pcm, int32_t *vbuf, const uint32_t *coefBase){ //.literal .LC39, 4224 @@ -4407,10 +4408,10 @@ void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ //AddLog(LOG_LEVEL_INFO, PSTR("PolyphaseStereo 1")); - int i; + int32_t i; const uint32_t *coef; - int *vb1; - int vLo, vHi, c1, c2; + int32_t *vb1; + int32_t vLo, vHi, c1, c2; uint64_t sum1L, sum2L, sum1R, sum2R, rndVal; const uint64_t *ulc = (const uint64_t*)((uint8_t *)ulconst+EXEC_OFFSET); uint64_t ull1 = *ulc; @@ -4422,7 +4423,7 @@ void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ vb1 = vbuf; sum1L = sum1R = rndVal; - for(int j=0; j<8; j++){ + for(int32_t j=0; j<8; j++){ c1=*coef; coef++; c2=*coef; coef++; vLo=*(vb1+(j)); vHi = *(vb1+(23-(j))); //sum1L=MADD64(sum1L, vLo, c1); //sum1L=MADD64(sum1L, vHi, -c2); @@ -4434,15 +4435,15 @@ void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ sum1R += MADD64(vLo, c1); sum1R += MADD64(vHi, -c2); } - *(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); - *(pcm + 1) = ClipToShort((int)SAR64(sum1R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 0) = ClipToShort((int32_t)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 1) = ClipToShort((int32_t)SAR64(sum1R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); /* special case, output sample 16 */ coef = coefBase + 256; vb1 = vbuf + 64*16; sum1L = sum1R = rndVal; - for(int j=0; j<8; j++){ + for(int32_t j=0; j<8; j++){ c1=*coef; coef++; vLo = *(vb1+(j)); //sum1L = MADD64(sum1L, vLo, c1); sum1L += MADD64(vLo, c1); @@ -4450,8 +4451,8 @@ void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ //sum1R = MADD64(sum1R, vLo, c1); sum1R += MADD64(vLo, c1); } - *(pcm + 2*16 + 0) = ClipToShort((int)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); - *(pcm + 2*16 + 1) = ClipToShort((int)SAR64(sum1R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 2*16 + 0) = ClipToShort((int32_t)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 2*16 + 1) = ClipToShort((int32_t)SAR64(sum1R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); /* main convolution loop: sum1L = samples 1, 2, 3, ... 15 sum2L = samples 31, 30, ... 17 */ coef = coefBase + 16; @@ -4463,7 +4464,7 @@ void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ sum1L = sum2L = rndVal; sum1R = sum2R = rndVal; - for(int j=0; j<8; j++){ + for(int32_t j=0; j<8; j++){ c1=*coef; coef++; c2=*coef; coef++; vLo=*(vb1+(j)); vHi = *(vb1+(23-(j))); //sum1L=MADD64(sum1L, vLo, c1); //sum2L=MADD64(sum2L, vLo, c2); @@ -4484,10 +4485,10 @@ void PolyphaseStereo(short *pcm, int *vbuf, const uint32_t *coefBase){ sum2R += MADD64(vHi, c1); } vb1 += 64; - *(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); - *(pcm + 1) = ClipToShort((int)SAR64(sum1R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); - *(pcm + 2*2*i + 0) = ClipToShort((int)SAR64(sum2L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); - *(pcm + 2*2*i + 1) = ClipToShort((int)SAR64(sum2R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 0) = ClipToShort((int32_t)SAR64(sum1L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 1) = ClipToShort((int32_t)SAR64(sum1R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 2*2*i + 0) = ClipToShort((int32_t)SAR64(sum2L, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); + *(pcm + 2*2*i + 1) = ClipToShort((int32_t)SAR64(sum2R, (32-m_CSHIFT)), m_DQ_FRACBITS_OUT - 2 - 2 - 15); pcm += 2; } } diff --git a/tasmota/Plugins/module_defines.h b/tasmota/Plugins/module_defines.h index 76565e85ba38..5d111455cc92 100644 --- a/tasmota/Plugins/module_defines.h +++ b/tasmota/Plugins/module_defines.h @@ -784,35 +784,42 @@ typedef struct { #define i2s_enable_tx(A) ji2s(6,(uint32_t)A,0,0,0,0) #define i2s_disable_tx(A) ji2s(7,(uint32_t)A,0,0,0,0) -#define WiFiClient() (void*)jtmod_wifi(0,0,0,0) -#define client_connect(A,B,C) (int32_t)jtmod_wifi(1,(uint32)A,(uint32)B,C) -#define client_connected(A) (int32_t)jtmod_wifi(2,(uint32)A,0,0) -#define client_available(A) (int32_t)jtmod_wifi(3,(uint32)A,0,0) -#define client_read(A) (uint8_t)jtmod_wifi(4,(uint32)A,0,0) -#define client_readn(A,B,C) (int32_t)jtmod_wifi(5,(uint32)A,(uint32_t)B,C) -#define client_stop(A) jtmod_wifi(6,(uint32)A,0,0) -#define client_delete(A) jtmod_wifi(7,(uint32)A,0,0) - -#define WiFiClientSecure() (void*)jtmod_wifi(10,0,0,0) -#define sclient_connect(A,B,C) (int32_t)jtmod_wifi(11,(uint32)A,(uint32)B,C) -#define sclient_connected(A) (int32_t)jtmod_wifi(12,(uint32)A,0,0) -#define sclient_available(A) (int32_t)jtmod_wifi(13,(uint32)A,0,0) -#define sclient_read(A) (uint8_t)jtmod_wifi(14,(uint32)A,0,0) -#define sclient_readn(A,B,C) (int32_t)jtmod_wifi(15,(uint32)A,(uint32_t)B,C) -#define sclient_stop(A) jtmod_wifi(16,(uint32)A,0,0) -#define sclient_setInsecure(A) jtmod_wifi(18,(uint32)A,0,0) -#define sclient_setTimeout(A,B) jtmod_wifi(19,(uint32)A,B,0) - - -#define HTTP() (void*)jtmod_wifi(30,0,0,0) +#define New_WiFiClient() (void*)jtmod_wifi(0,0,0,0) +#define client_connect(A,B,C) (int32_t)jtmod_wifi(1,(uint32_t)A,(uint32_t)B,C) +#define client_connected(A) (int32_t)jtmod_wifi(2,(uint32_t)A,0,0) +#define client_available(A) (int32_t)jtmod_wifi(3,(uint32_t)A,0,0) +#define client_read(A) (uint8_t)jtmod_wifi(4,(uint32_t)A,0,0) +#define client_readn(A,B,C) (int32_t)jtmod_wifi(5,(uint32_t)A,(uint32_t)B,C) +#define client_stop(A) jtmod_wifi(6,(uint32_t)A,0,0) +#define client_delete(A) jtmod_wifi(7,(uint32_t)A,0,0) + +#define New_WiFiClientSecure() (void*)jtmod_wifi(10,0,0,0) +#define sclient_connect(A,B,C) (int32_t)jtmod_wifi(11,(uint32_t)A,(uint32_t)B,C) +#define sclient_connected(A) (int32_t)jtmod_wifi(12,(uint32_t)A,0,0) +#define sclient_available(A) (int32_t)jtmod_wifi(13,(uint32_t)A,0,0) +#define sclient_read(A) (uint8_t)jtmod_wifi(14,(uint32_t)A,0,0) +#define sclient_readn(A,B,C) (int32_t)jtmod_wifi(15,(uint32_t)A,(uint32_t)B,C) +#define sclient_stop(A) jtmod_wifi(16,(uint32_t)A,0,0) +#define sclient_setInsecure(A) jtmod_wifi(18,(uint32_t)A,0,0) +#define sclient_setTimeout(A,B) jtmod_wifi(19,(uint32_t)A,B,0) + + +#define New_HTTP() (void*)jtmod_wifi(30,0,0,0) #define http_end(A) jtmod_wifi(31,(uint32)A,0,0) #define http_delete(A) jtmod_wifi(32,(uint32)A,0,0) -#define http_begin(A,B,C) jtmod_wifi(33,(uint32)A,B,(uint32_t)C) +#define http_begin(A,B,C) jtmod_wifi(33,(uint32)A,(uint32)B,(uint32_t)C) #define http_setReuse(A,B) jtmod_wifi(34,(uint32)A,B,0) #define http_GET(A) (uint8_t)jtmod_wifi(35,(uint32)A,0,0) #define http_getSize(A) (int32_t)jtmod_wifi(36,(uint32)A,0,0) #define http_connected(A) (int32_t)jtmod_wifi(37,(uint32)A,0,0) #define http_getStreamPtr(A) (void*)jtmod_wifi(38,(uint32)A,0,0) +#define http_addHeader(A,B,C) jtmod_wifi(39,(uint32)A,(uint32)B,(uint32)C) +#define http_collectHeaders(A,B,C) jtmod_wifi(40,(uint32)A,(uint32)B,(uint32)C) +#define http_header(A,B)(char*)jtmod_wifi(41,(uint32)A,(uint32)B,0) +#define http_hasHeader(A,B) jtmod_wifi(42,(uint32)A,(uint32)B,0) +#define http_setFollowRedirects(A,B) jtmod_wifi(43,(uint32)A,(uint32)B,0) + + #define xTaskCreatePinnedToCore(A) jtaskc(A) diff --git a/tasmota/Plugins/xdrv_42_i2s.cpp b/tasmota/Plugins/xdrv_42_i2s.cpp index 691e45855964..04fdff95fede 100644 --- a/tasmota/Plugins/xdrv_42_i2s.cpp +++ b/tasmota/Plugins/xdrv_42_i2s.cpp @@ -27,10 +27,11 @@ // select a codec #define USE_WM8960 + //#define USE_SAY #ifdef ESP32 -#define USE_MP3_PSRAM +//#define USE_MP3_PSRAM #define USE_MP3 #define USE_WEBRADIO #endif @@ -104,7 +105,8 @@ typedef struct { TwoWire *xWire; #endif #ifdef USE_WEBRADIO - void *client; + void *http; + void *wclient; #endif } MODULE_MEMORY; @@ -124,7 +126,8 @@ typedef struct { #define chans mem->chans #define input_bytes mem->input_bytes #define filepos mem->filepos -#define client mem->client +#define wclient mem->wclient +#define http mem->http // esp8266 fixed i2s pins : DOUT = 3(RX), BCK = 15(D8), WS = 2(D4) @@ -568,20 +571,18 @@ void I2sTaskWR(void) { SETREGS i2s_enable_tx(i2sp); - //uint8_t *buff; - - while (client_connected(client)) { - while (client_available(client) && running) { - client_read(client); - //client_readn(client, buff, 5); + while (client_connected(wclient)) { + while (client_available(wclient) && running) { + client_read(wclient); + //client_readn(wclient, buff, 5); } if (!running) { break; } } - client_stop(client); - client_delete(client); + client_stop(wclient); + client_delete(wclient); i2s_disable_tx(i2sp); @@ -591,6 +592,8 @@ void I2sTaskWR(void) { } #endif +#include + void WebRadio(void) { SETREGS #ifdef USE_WEBRADIO @@ -610,6 +613,75 @@ void WebRadio(void) { //WDR2 i2swr http://wdr-wdr2-aachenundregion.icecastssl.wdr.de/wdr/wdr2/aachenundregion/mp3/128/stream.mp3 + wclient = New_WiFiClient(); + http = New_HTTP(); + + if (!http_begin(http, wclient, cp)) { + http_delete(http); + AddLog(LOG_LEVEL_INFO, PSTR("WR could not connect TCP to %s"),cp); + return; + } + + //http_addHeader(http, PSTR("Icy-MetaData"), "1"); + + //static const char *hdr[] = { "icy-metaint", "icy-name", "icy-genre", "icy-br" }; + + //http_collectHeaders(http, hdr, 4 ); + + http_setReuse(http, true); + + http_setFollowRedirects(http, HTTPC_FORCE_FOLLOW_REDIRECTS); + + int32_t code = http_GET(http); + +/* + if (http_hasHeader(http, hdr[0])) { + char *ret = http_header(http, hdr[0]); + icyMetaInt = 1; // ret.toInt(); + } else { + icyMetaInt = 0; + } +*/ + + int32_t size = http_getSize(http); + + AddLog(LOG_LEVEL_INFO, PSTR("WR code %d - %d"),code, size); + + http_end(http); + client_delete(wclient); + http_delete(http); + +/* + + + int code = http.GET(); + if (http.hasHeader(hdr[0])) { + String ret = http.header(hdr[0]); + icyMetaInt = ret.toInt(); + } else { + icyMetaInt = 0; + } + if (http.hasHeader(hdr[1])) { + String ret = http.header(hdr[1]); +// cb.md("SiteName", false, ret.c_str()); + } + if (http.hasHeader(hdr[2])) { + String ret = http.header(hdr[2]); +// cb.md("Genre", false, ret.c_str()); + } + if (http.hasHeader(hdr[3])) { + String ret = http.header(hdr[3]); +// cb.md("Bitrate", false, ret.c_str()); + } + + icyByteCount = 0; + size = http.getSize(); + strncpy(saveURL, url, sizeof(saveURL)); + saveURL[sizeof(saveURL)-1] = 0; + return true; + */ + +/* client = WiFiClient(); int32_t err = client_connect(client, cp, 80); if (!err) { @@ -617,6 +689,8 @@ void WebRadio(void) { AddLog(LOG_LEVEL_INFO, PSTR("WR could not connect TCP to %s"),cp); return; } + + // play webradio file const uint32_t *icp = (const uint32_t *) ((uint8_t *)i32_const+EXEC_OFFSET); TASKPARS tp; @@ -628,6 +702,7 @@ void WebRadio(void) { tp.constpvCreatedTask = nullptr; tp.xCoreID = 1; err = xTaskCreatePinnedToCore(&tp); +*/ busy = true; ResponseCmndDone(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino b/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino index f93b12bb4d2f..472c53270824 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino @@ -464,7 +464,6 @@ uint32_t tmod_wifi(uint32_t sel, uint32_t p1, uint32_t p2, uint32_t p3) { case 1: { int32_t err = client->connect((char*)p2, p3); - AddLog(LOG_LEVEL_INFO,PSTR("connect %s - %d - %d"), (char*)p2, p3, err); return err; } case 2: @@ -489,7 +488,6 @@ uint32_t tmod_wifi(uint32_t sel, uint32_t p1, uint32_t p2, uint32_t p3) { case 11: { int32_t err = sclient->connect((char*)p2, p3); - AddLog(LOG_LEVEL_INFO,PSTR("connect %s - %d - %d"), (char*)p2, p3, err); return err; } case 12: @@ -524,8 +522,7 @@ uint32_t tmod_wifi(uint32_t sel, uint32_t p1, uint32_t p2, uint32_t p3) { delete http; break; case 33: - http->begin(String((char*)p2), (char*)p3); - break; + return http->begin((NetworkClient&)*(NetworkClient*)p2, (char*)p3); case 34: http->setReuse(p2); break; @@ -538,7 +535,35 @@ uint32_t tmod_wifi(uint32_t sel, uint32_t p1, uint32_t p2, uint32_t p3) { case 38: // returns client return (uint32_t)http->getStreamPtr(); - + case 39: + { + char *cp2 = copyStr((char*)p2); + char *cp3 = copyStr((char*)p3); + http->addHeader((const char*)cp2, (const char*)cp3); + free(cp2); + free(cp3); + break; + } + case 40: + http->collectHeaders((const char**)p2, p3); + break; + case 41: + { + char *cp = copyStr((char*)p2); + String hd = http->header(cp); + free(cp); + return (uint32_t) hd.c_str(); + } + case 42: + { + char *cp = copyStr((char*)p2); + bool hd = http->hasHeader(cp); + free(cp); + return hd; + } + case 43: + http->setFollowRedirects((followRedirects_t)p2); + break; } #endif // ESP32 return 0;