Compare commits

..

No commits in common. "circuitpython" and "master" have entirely different histories.

19 changed files with 76 additions and 135 deletions

View file

@ -56,10 +56,6 @@
#ifndef _ASSEMBLY_H
#define _ASSEMBLY_H
#ifdef __cplusplus
extern "C" {
#endif
#if (defined _WIN32 && !defined _WIN32_WCE) || (defined __WINS__ && defined _SYMBIAN) || defined(_OPENWAVE_SIMULATOR) || defined(WINCE_EMULATOR) /* Symbian emulator for Ix86 */
#pragma warning( disable : 4035 ) /* complains about inline asm not returning a value */
@ -271,7 +267,7 @@ static __inline int CLZ(int x)
return numZeros;
}
#elif defined(__GNUC__) && (defined(ARM) || defined(__ARMEL__))
#elif defined(__GNUC__) && defined(ARM)
static __inline int MULSHIFT32(int x, int y)
{
@ -321,42 +317,6 @@ static __inline int CLZ(int x)
return numZeros;
}
typedef signed long long int Word64; // 64-bit signed integer.
typedef union _U64 {
Word64 w64;
struct {
/* ARM ADS = little endian */
unsigned int lo32;
signed int hi32;
} r;
} U64;
static __inline Word64 MADD64(Word64 sum64, int x, int y)
{
U64 u;
u.w64 = sum64;
__asm__ volatile ("smlal %0,%1,%2,%3" : "+&r" (u.r.lo32), "+&r" (u.r.hi32) : "r" (x), "r" (y) : "cc");
return u.w64;
}
__attribute__((__always_inline__)) static __inline Word64 SAR64(Word64 x, int n)
{
unsigned int xLo = (unsigned int) x;
int xHi = (int) (x >> 32);
int nComp = 32-n;
int tmp;
// Shortcut: n is always < 32.
__asm__ __volatile__( "lsl %2, %0, %3\n\t" // tmp <- xHi<<(32-n)
"asr %0, %0, %4\n\t" // xHi <- xHi>>n
"lsr %1, %1, %4\n\t" // xLo <- xLo>>n
"orr %1, %2\n\t" // xLo <= xLo || tmp
: "+&r" (xHi), "+r" (xLo), "=&r" (tmp)
: "r" (nComp), "r" (n) );
x = xLo | ((Word64)xHi << 32);
return( x );
}
#elif defined(__GNUC__) && defined(__AVR32_UC__)
typedef signed long long int Word64; // 64-bit signed integer.
@ -513,7 +473,4 @@ __attribute__((__always_inline__)) static __inline Word64 SAR64(Word64 x, int n)
#endif /* platforms */
#ifdef __cplusplus
}
#endif
#endif /* _ASSEMBLY_H */

View file

@ -67,7 +67,6 @@
*
* Notes: slow, platform-independent equivalent to memset(buf, 0, nBytes)
**************************************************************************************/
#ifndef MPDEC_ALLOCATOR
static void ClearBuffer(void *buf, int nBytes)
{
int i;
@ -78,7 +77,6 @@ static void ClearBuffer(void *buf, int nBytes)
return;
}
#endif
/**************************************************************************************
* Function: AllocateBuffers
@ -99,7 +97,7 @@ static void ClearBuffer(void *buf, int nBytes)
MP3DecInfo *AllocateBuffers(void)
{
MP3DecInfo *mp3DecInfo;
#ifdef MPDEC_ALLOCATOR
/*
FrameHeader *fh;
SideInfo *si;
ScaleFactorInfo *sfi;
@ -107,44 +105,8 @@ MP3DecInfo *AllocateBuffers(void)
DequantInfo *di;
IMDCTInfo *mi;
SubbandInfo *sbi;
mp3DecInfo = (MP3DecInfo *)MPDEC_ALLOCATOR(sizeof(MP3DecInfo));
if (!mp3DecInfo)
{
#ifndef _WIN32
#ifdef DEMO_HELIX_FOOTPRINT
sprintf(COPY_DEBUG_BUFFER,"mp3DecInfo size: %d\n", (int)sizeof(MP3DecInfo));
DV_DEBUG_USART_Trace( COPY_DEBUG_BUFFER );
#endif
#endif
return 0;
}
hi = (HuffmanInfo *) MPDEC_ALLOCATOR(sizeof(HuffmanInfo));
sbi = (SubbandInfo *) MPDEC_ALLOCATOR(sizeof(SubbandInfo));
mi = (IMDCTInfo *) MPDEC_ALLOCATOR(sizeof(IMDCTInfo));
di = (DequantInfo *) MPDEC_ALLOCATOR(sizeof(DequantInfo));
si = (SideInfo *) MPDEC_ALLOCATOR(sizeof(SideInfo));
sfi = (ScaleFactorInfo *) MPDEC_ALLOCATOR(sizeof(ScaleFactorInfo));
fh = (FrameHeader *) MPDEC_ALLOCATOR(sizeof(FrameHeader));
if (!fh || !si || !sfi || !hi || !di || !mi || !sbi) {
#ifndef _WIN32
#ifdef DEMO_HELIX_FOOTPRINT
sprintf(COPY_DEBUG_BUFFER,"mp3DecInfo:%d[%d] | fh:%d[%d] | si:%d[%d] \
| sfi:%d[%d] | hi:%d[%d] | di:%d[%d] | mi:%d[%d] | sbi:%d[%d]\n",
(int)mp3DecInfo, (int)sizeof(MP3DecInfo), (int)fh, (int)sizeof(FrameHeader),
(int)si, (int)sizeof(SideInfo), (int)sfi, (int)sizeof(ScaleFactorInfo),
(int)hi, (int)sizeof(HuffmanInfo), (int)di, (int)sizeof(DequantInfo),
(int)mi, (int)sizeof(IMDCTInfo), (int)sbi, (int)sizeof(SubbandInfo) );
DV_DEBUG_USART_Trace( COPY_DEBUG_BUFFER );
#endif
#endif
FreeBuffers(mp3DecInfo); // safe to call - only frees memory that was successfully allocated
return 0;
}
#else
*/
// Buffers:
static char s_mp3DecInfo[sizeof(MP3DecInfo)];
static char fh[sizeof(FrameHeader)];
@ -155,8 +117,65 @@ MP3DecInfo *AllocateBuffers(void)
static char mi[sizeof(IMDCTInfo)];
static char sbi[sizeof(SubbandInfo)];
//mp3DecInfo = (MP3DecInfo *)malloc(sizeof(MP3DecInfo));
mp3DecInfo = (MP3DecInfo *)s_mp3DecInfo;
if (!mp3DecInfo)
{
#ifndef _WIN32
#ifdef DEMO_HELIX_FOOTPRINT
sprintf(COPY_DEBUG_BUFFER,"mp3DecInfo size: %d\n", (int)sizeof(MP3DecInfo));
DV_DEBUG_USART_Trace( COPY_DEBUG_BUFFER );
#endif
#endif
return 0;
}
ClearBuffer(mp3DecInfo, sizeof(MP3DecInfo));
/* Switched to static allocations.
hi = (HuffmanInfo *) malloc(sizeof(HuffmanInfo));
sbi = (SubbandInfo *) malloc(sizeof(SubbandInfo));
mi = (IMDCTInfo *) malloc(sizeof(IMDCTInfo));
di = (DequantInfo *) malloc(sizeof(DequantInfo));
si = (SideInfo *) malloc(sizeof(SideInfo));
sfi = (ScaleFactorInfo *) malloc(sizeof(ScaleFactorInfo));
fh = (FrameHeader *) malloc(sizeof(FrameHeader));
*/
mp3DecInfo->FrameHeaderPS = (void *)fh;
mp3DecInfo->SideInfoPS = (void *)si;
mp3DecInfo->ScaleFactorInfoPS = (void *)sfi;
mp3DecInfo->HuffmanInfoPS = (void *)hi;
mp3DecInfo->DequantInfoPS = (void *)di;
mp3DecInfo->IMDCTInfoPS = (void *)mi;
mp3DecInfo->SubbandInfoPS = (void *)sbi;
/* Removed; static allocation guarantees success.
if (!fh || !si || !sfi || !hi || !di || !mi || !sbi) {
#ifndef _WIN32
#ifdef DEMO_HELIX_FOOTPRINT
sprintf(COPY_DEBUG_BUFFER,"mp3DecInfo:%d[%d] | fh:%d[%d] | si:%d[%d] \
| sfi:%d[%d] | hi:%d[%d] | di:%d[%d] | mi:%d[%d] | sbi:%d[%d]\n",
(int)mp3DecInfo, (int)sizeof(MP3DecInfo), (int)fh, (int)sizeof(FrameHeader),
(int)si, (int)sizeof(SideInfo), (int)sfi, (int)sizeof(ScaleFactorInfo),
(int)hi, (int)sizeof(HuffmanInfo), (int)di, (int)sizeof(DequantInfo),
(int)mi, (int)sizeof(IMDCTInfo), (int)sbi, (int)sizeof(SubbandInfo) );
DV_DEBUG_USART_Trace( COPY_DEBUG_BUFFER );
#endif
#endif
FreeBuffers(mp3DecInfo); // safe to call - only frees memory that was successfully allocated
return 0;
}
*/
#ifndef _WIN32
#ifdef DEMO_HELIX_FOOTPRINT
sprintf(COPY_DEBUG_BUFFER, "Total decoder malloc size: %d\n",
(int)(sizeof(MP3DecInfo) + sizeof(FrameHeader) + sizeof(SideInfo)
+ sizeof(ScaleFactorInfo) + sizeof(HuffmanInfo) + sizeof(DequantInfo)
+ sizeof(IMDCTInfo) + sizeof(SubbandInfo)));
DV_DEBUG_USART_Trace( COPY_DEBUG_BUFFER );
#endif
#endif
/* important to do this - DSP primitives assume a bunch of state variables are 0 on first use */
ClearBuffer(fh, sizeof(FrameHeader));
@ -167,34 +186,10 @@ MP3DecInfo *AllocateBuffers(void)
ClearBuffer(mi, sizeof(IMDCTInfo));
ClearBuffer(sbi, sizeof(SubbandInfo));
#endif
mp3DecInfo->FrameHeaderPS = (void *)fh;
mp3DecInfo->SideInfoPS = (void *)si;
mp3DecInfo->ScaleFactorInfoPS = (void *)sfi;
mp3DecInfo->HuffmanInfoPS = (void *)hi;
mp3DecInfo->DequantInfoPS = (void *)di;
mp3DecInfo->IMDCTInfoPS = (void *)mi;
mp3DecInfo->SubbandInfoPS = (void *)sbi;
#ifndef _WIN32
#ifdef DEMO_HELIX_FOOTPRINT
sprintf(COPY_DEBUG_BUFFER, "Total decoder malloc size: %d\n",
(int)(sizeof(MP3DecInfo) + sizeof(FrameHeader) + sizeof(SideInfo)
+ sizeof(ScaleFactorInfo) + sizeof(HuffmanInfo) + sizeof(DequantInfo)
+ sizeof(IMDCTInfo) + sizeof(SubbandInfo)));
DV_DEBUG_USART_Trace( COPY_DEBUG_BUFFER );
#endif
#endif
return mp3DecInfo;
}
#ifdef MPDEC_FREE
#define SAFE_FREE(x) {if (x) MPDEC_FREE(x); (x) = 0;} /* helper macro */
#else
#define SAFE_FREE(x) { (x) = 0; }
#endif
#define SAFE_FREE(x) {if (x) free(x); (x) = 0;} /* helper macro */
/**************************************************************************************
* Function: FreeBuffers
@ -213,7 +208,8 @@ void FreeBuffers(MP3DecInfo *mp3DecInfo)
{
if (!mp3DecInfo)
return;
/* Switched to static allocations.
SAFE_FREE(mp3DecInfo->FrameHeaderPS);
SAFE_FREE(mp3DecInfo->SideInfoPS);
SAFE_FREE(mp3DecInfo->ScaleFactorInfoPS);
@ -223,4 +219,5 @@ void FreeBuffers(MP3DecInfo *mp3DecInfo)
SAFE_FREE(mp3DecInfo->SubbandInfoPS);
SAFE_FREE(mp3DecInfo);
*/
}

View file

@ -46,10 +46,6 @@
#include "mp3common.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(ASSERT)
#undef ASSERT
#endif
@ -308,7 +304,4 @@ extern const int csa[8][2];
extern const int coef32[31];
extern const int polyCoef[264];
#ifdef __cplusplus
}
#endif
#endif /* _CODER_H */

View file

@ -43,7 +43,6 @@
#include "coder.h"
#include "assembly.h"
#include <stdint.h>
typedef int ARRAY3[3]; /* for short-block reordering */
@ -246,7 +245,7 @@ static const int pow2frac[8] = {
ScaleFactorInfoSub *sfis, CriticalBandInfo *cbi)
{
int i, j, w, cb;
int cbEndL, cbStartS, cbEndS;
int cbStartL, cbEndL, cbStartS, cbEndS;
int nSamps, nonZero, sfactMultiplier, gbMask;
int globalGain, gainI;
int cbMax[3];
@ -254,6 +253,7 @@ static const int pow2frac[8] = {
/* set default start/end points for short/long blocks - will update with non-zero cb info */
if (sis->blockType == 2) {
cbStartL = 0;
if (sis->mixedBlock) {
cbEndL = (fh->ver == MPEG1 ? 8 : 6);
cbStartS = 3;
@ -264,6 +264,7 @@ static const int pow2frac[8] = {
cbEndS = 13;
} else {
/* long block */
cbStartL = 0;
cbEndL = 22;
cbStartS = 13;
cbEndS = 13;

View file

@ -388,6 +388,7 @@ int DecodeHuffman(MP3DecInfo *mp3DecInfo, unsigned char *buf, int *bitOffset, in
FrameHeader *fh;
SideInfo *si;
SideInfoSub *sis;
ScaleFactorInfo *sfi;
HuffmanInfo *hi;
/* validate pointers */
@ -397,6 +398,7 @@ int DecodeHuffman(MP3DecInfo *mp3DecInfo, unsigned char *buf, int *bitOffset, in
fh = ((FrameHeader *)(mp3DecInfo->FrameHeaderPS));
si = ((SideInfo *)(mp3DecInfo->SideInfoPS));
sis = &si->sis[gr][ch];
sfi = ((ScaleFactorInfo *)(mp3DecInfo->ScaleFactorInfoPS));
hi = (HuffmanInfo*)(mp3DecInfo->HuffmanInfoPS);
if (huffBlockBits < 0)

View file

@ -44,7 +44,6 @@
#include "coder.h"
#include "assembly.h"
#include <stdint.h>
/**************************************************************************************
* Function: AntiAlias

View file

@ -47,10 +47,6 @@
#include "mp3dec.h"
#include "statname.h" /* do name-mangling for static linking */
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_SCFBD 4 /* max scalefactor bands per channel */
#define NGRANS_MPEG1 2
#define NGRANS_MPEG2 1
@ -124,8 +120,4 @@ extern const short sideBytesTab[3][2];
extern const short slotTab[3][3][15];
extern const SFBandTable sfBandTable[3][3];
#ifdef __cplusplus
}
#endif
#endif /* _MP3COMMON_H */

View file

@ -44,9 +44,7 @@
#ifndef _MP3DEC_H
#define _MP3DEC_H
#ifdef ARDUINO
#include <Arduino.h>
#endif
#if defined(_WIN32) && !defined(_WIN32_WCE)
#
@ -60,8 +58,6 @@
#
#elif defined(__GNUC__) && defined(ARM)
#
#elif defined(__GNUC__) && defined(__ARMEL__)
#
#elif defined(__GNUC__) && defined(__i386__)
#
#elif defined(_OPENWAVE_SIMULATOR) || defined(_OPENWAVE_ARMULATOR)

View file

@ -208,7 +208,7 @@ static const char NRTab[6][3][4] = {
static void UnpackSFMPEG2(BitStreamInfo *bsi, SideInfoSub *sis, ScaleFactorInfoSub *sfis, int gr, int ch, int modeExt, ScaleFactorJS *sfjs)
{
int i, sfb, sfcIdx, btIdx, nrIdx;
int i, sfb, sfcIdx, btIdx, nrIdx, iipTest;
int slen[4], nr[4];
int sfCompress, preFlag, intensityScale;
@ -298,6 +298,7 @@ static void UnpackSFMPEG2(BitStreamInfo *bsi, SideInfoSub *sis, ScaleFactorInfoS
if(sis->blockType == 2) {
if(sis->mixedBlock) {
/* do long block portion */
iipTest = (1 << slen[0]) - 1;
for (sfb=0; sfb < 6; sfb++) {
sfis->l[sfb] = (char)GetBits(bsi, slen[0]);
}
@ -311,6 +312,7 @@ static void UnpackSFMPEG2(BitStreamInfo *bsi, SideInfoSub *sis, ScaleFactorInfoS
/* remaining short blocks, sfb just keeps incrementing */
for ( ; nrIdx <= 3; nrIdx++) {
iipTest = (1 << slen[nrIdx]) - 1;
for (i=0; i < nr[nrIdx]; i++, sfb++) {
sfis->s[sfb][0] = (char)GetBits(bsi, slen[nrIdx]);
sfis->s[sfb][1] = (char)GetBits(bsi, slen[nrIdx]);
@ -323,6 +325,7 @@ static void UnpackSFMPEG2(BitStreamInfo *bsi, SideInfoSub *sis, ScaleFactorInfoS
/* long blocks */
sfb = 0;
for (nrIdx = 0; nrIdx <= 3; nrIdx++) {
iipTest = (1 << slen[nrIdx]) - 1;
for(i=0; i < nr[nrIdx]; i++, sfb++) {
sfis->l[sfb] = (char)GetBits(bsi, slen[nrIdx]);
}

View file

@ -60,6 +60,7 @@
int Subband(MP3DecInfo *mp3DecInfo, short *pcmBuf)
{
int b;
HuffmanInfo *hi;
IMDCTInfo *mi;
SubbandInfo *sbi;
@ -67,6 +68,7 @@ int Subband(MP3DecInfo *mp3DecInfo, short *pcmBuf)
if (!mp3DecInfo || !mp3DecInfo->HuffmanInfoPS || !mp3DecInfo->IMDCTInfoPS || !mp3DecInfo->SubbandInfoPS)
return -1;
hi = (HuffmanInfo *)mp3DecInfo->HuffmanInfoPS;
mi = (IMDCTInfo *)(mp3DecInfo->IMDCTInfoPS);
sbi = (SubbandInfo*)(mp3DecInfo->SubbandInfoPS);

View file

@ -44,7 +44,6 @@
// constants in RAM are not significantly faster
#include "coder.h"
#include <stdint.h>
/* post-IMDCT window, win[blockType][i]
* format = Q31