Compare commits
No commits in common. "standalone-encoder" and "master" have entirely different histories.
standalone
...
master
25 changed files with 91 additions and 452 deletions
10
.travis.yml
10
.travis.yml
|
|
@ -1,12 +1,5 @@
|
|||
language: c
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- ~/arduino_ide
|
||||
- ~/.arduino15/packages/
|
||||
git:
|
||||
depth: false
|
||||
quiet: true
|
||||
|
||||
# Blacklist
|
||||
branches:
|
||||
|
|
@ -21,8 +14,7 @@ before_install:
|
|||
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
|
||||
|
||||
script:
|
||||
- build_platform m4
|
||||
- make -C examples/standalone
|
||||
- build_main_platforms
|
||||
|
||||
# Generate and deploy documentation
|
||||
after_success:
|
||||
|
|
|
|||
|
|
@ -1,113 +0,0 @@
|
|||
#include "Adafruit_MP3.h"
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <Adafruit_SPIFlash.h>
|
||||
|
||||
#if defined(__SAMD51__) || defined(NRF52840_XXAA)
|
||||
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
|
||||
#else
|
||||
#if (SPI_INTERFACES_COUNT == 1 || defined(ADAFRUIT_CIRCUITPLAYGROUND_M0))
|
||||
Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
|
||||
#else
|
||||
Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Adafruit_SPIFlash flash(&flashTransport);
|
||||
|
||||
// file system object from SdFat
|
||||
FatFileSystem fatfs;
|
||||
|
||||
//set this to a value between 0 and 4095 to raise/lower volume
|
||||
#define VOLUME_MAX 1023
|
||||
|
||||
const char *filename = "test.mp3";
|
||||
|
||||
File dataFile;
|
||||
Adafruit_MP3 player;
|
||||
|
||||
void writeDacs(int16_t l, int16_t r){
|
||||
uint16_t vall = map(l, -32768, 32767, 0, VOLUME_MAX);
|
||||
uint16_t valr = map(r, -32768, 32767, 0, VOLUME_MAX);
|
||||
#if defined(__SAMD51__) // feather/metro m4
|
||||
analogWrite(A0, vall);
|
||||
analogWrite(A1, valr);
|
||||
#elif defined(__MK66FX1M0__) // teensy 3.6
|
||||
analogWrite(A21, vall);
|
||||
analogWrite(A22, valr);
|
||||
#elif defined(NRF52)
|
||||
analogWrite(27, vall);
|
||||
#elif defined(__MK20DX256__) //teensy 3.2
|
||||
analogWrite(A14, vall); //this board only has one dac, so play only left channel (or mono)
|
||||
#endif
|
||||
}
|
||||
|
||||
int getMoreData(uint8_t *writeHere, int thisManyBytes){
|
||||
int bytesRead = 0;
|
||||
int toRead = min(thisManyBytes, 768); //limit the number of bytes we can read at a time so the file isn't interrupted
|
||||
while(dataFile.available() && bytesRead < toRead){
|
||||
*writeHere = dataFile.read();
|
||||
writeHere++;
|
||||
bytesRead++;
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
// the setup routine runs once when you press reset:
|
||||
void setup() {
|
||||
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
analogWriteResolution(12);
|
||||
#if defined(__SAMD51__)
|
||||
analogWrite(A0, 2048);
|
||||
analogWrite(A1, 2048);
|
||||
#endif
|
||||
|
||||
Serial.println("Native MP3 decoding!");
|
||||
Serial.print("Initializing QSPI storage...");
|
||||
|
||||
// Initialize flash library and check its chip ID.
|
||||
if (!flash.begin()) {
|
||||
Serial.println("Error, failed to initialize flash chip!");
|
||||
while(1);
|
||||
}
|
||||
|
||||
Serial.println("QSPI initialized.");
|
||||
Serial.print("Flash chip JEDEC ID: 0x"); Serial.println(flash.getJEDECID(), HEX);
|
||||
|
||||
// First call begin to mount the filesystem. Check that it returns true
|
||||
// to make sure the filesystem was mounted.
|
||||
if (!fatfs.begin(&flash)) {
|
||||
Serial.println("Error, failed to mount newly formatted filesystem!");
|
||||
Serial.println("Was the flash chip formatted with the fatfs_format example?");
|
||||
while(1);
|
||||
}
|
||||
Serial.println("Mounted filesystem!");
|
||||
|
||||
|
||||
dataFile = fatfs.open(filename);
|
||||
if(!dataFile){
|
||||
Serial.println("could not open file!");
|
||||
while(1);
|
||||
}
|
||||
|
||||
player.begin();
|
||||
|
||||
//do this when there are samples ready
|
||||
player.setSampleReadyCallback(writeDacs);
|
||||
|
||||
//do this when more data is required
|
||||
player.setBufferCallback(getMoreData);
|
||||
|
||||
player.play();
|
||||
}
|
||||
|
||||
// the loop routine runs over and over again forever:
|
||||
void loop() {
|
||||
player.tick();
|
||||
}
|
||||
2
examples/standalone/.gitignore
vendored
2
examples/standalone/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
|||
decoder
|
||||
decoder.exe
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
decoder: $(wildcard ../../src/*.c) main.c $(wildcard ../../src/*.h) Makefile
|
||||
gcc -Og -ggdb -g3 -iquote ../../src -o $@ $(filter %.c, $^) \
|
||||
-DMPDEC_ALLOCATOR=malloc -DMPDEC_FREE=free -include stdlib.h
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f decoder
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "mp3dec.h"
|
||||
|
||||
#define MAX_BUFFER_LEN (MAX_NSAMP * MAX_NGRAN * MAX_NCHAN)
|
||||
|
||||
int16_t audiodata[MAX_BUFFER_LEN];
|
||||
|
||||
typedef struct {
|
||||
char *ptr, *end;
|
||||
} stream;
|
||||
#define READ_PTR(stream) ((void*)((stream)->ptr))
|
||||
#define BYTES_LEFT(stream) ((stream)->end - (stream)->ptr)
|
||||
#define CONSUME(stream, n) ((stream)->ptr += n)
|
||||
|
||||
void skip_id3v2(stream* self) {
|
||||
if (BYTES_LEFT(self) < 10) {
|
||||
return;
|
||||
}
|
||||
uint8_t *data = READ_PTR(self);
|
||||
if (!(
|
||||
data[0] == 'I' &&
|
||||
data[1] == 'D' &&
|
||||
data[2] == '3' &&
|
||||
data[3] != 0xff &&
|
||||
data[4] != 0xff &&
|
||||
(data[5] & 0x1f) == 0 &&
|
||||
(data[6] & 0x80) == 0 &&
|
||||
(data[7] & 0x80) == 0 &&
|
||||
(data[8] & 0x80) == 0 &&
|
||||
(data[9] & 0x80) == 0)) {
|
||||
return;
|
||||
}
|
||||
uint32_t size = (data[6] << 21) | (data[7] << 14) | (data[8] << 7) | (data[9]);
|
||||
size += 10; // size excludes the "header" (but not the "extended header")
|
||||
CONSUME(self, size + 10);
|
||||
}
|
||||
|
||||
bool mp3file_find_sync_word(stream* self) {
|
||||
int offset = MP3FindSyncWord(READ_PTR(self), BYTES_LEFT(self));
|
||||
if (offset >= 0) {
|
||||
CONSUME(self, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void fatal(const char *msg) { fprintf(stderr, "%s\n", msg); exit(1); }
|
||||
void perror_fatal(const char *msg) { perror(msg); exit(1); }
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if(argc != 3) {
|
||||
fprintf(stderr, "Decode MP3 into headerless LE16 stereo\n");
|
||||
fprintf(stderr, "Usage: %s input.mp3 output.bin\n", argv[0]);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
HMP3Decoder decoder = MP3InitDecoder();
|
||||
|
||||
FILE *fi = fopen(argv[1], "rb");
|
||||
if(!fi) perror_fatal("open");
|
||||
|
||||
struct stat st;
|
||||
if(fstat(fileno(fi), &st) < 0) perror_fatal("fstat");
|
||||
|
||||
stream s;
|
||||
s.ptr = malloc(st.st_size);
|
||||
if(!s.ptr) perror_fatal("malloc");
|
||||
s.end = s.ptr + st.st_size;
|
||||
|
||||
if(fread(s.ptr, 1, st.st_size, fi) != st.st_size) perror_fatal("fread");
|
||||
|
||||
FILE *fo = fopen(argv[2], "wb");
|
||||
if(!fo) perror_fatal("open");
|
||||
|
||||
skip_id3v2(&s);
|
||||
|
||||
while(mp3file_find_sync_word(&s)) {
|
||||
MP3FrameInfo fi;
|
||||
int err = MP3GetNextFrameInfo(decoder, &fi, READ_PTR(&s));
|
||||
if(err != ERR_MP3_NONE) fatal("MP3GetNextFrameInfo");
|
||||
int bytes_left = (int)BYTES_LEFT(&s);
|
||||
uint8_t *inbuf = READ_PTR(&s);
|
||||
err = MP3Decode(decoder, &inbuf, &bytes_left,
|
||||
audiodata, 0);
|
||||
if(err != ERR_MP3_NONE) fatal("MP3Decode");
|
||||
if(fwrite(audiodata, 1, fi.outputSamps*sizeof(int16_t), fo)
|
||||
!= fi.outputSamps*sizeof(int16_t))
|
||||
perror_fatal("fwrite");
|
||||
CONSUME(&s, BYTES_LEFT(&s) - bytes_left);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
name=Adafruit_mp3
|
||||
version=1.1.2
|
||||
version=1.0.5
|
||||
author=Dean Miller <dean@adafruit.com>
|
||||
maintainer=Dean Miller <dean@adafruit.com>
|
||||
sentence=mp3 decoder
|
||||
|
|
@ -7,4 +7,3 @@ paragraph=
|
|||
category=Data Processing
|
||||
url=https://github.com/adafruit/Adafruit_MP3
|
||||
architectures=*
|
||||
depends=Adafruit SPIFlash, SdFat - Adafruit Fork
|
||||
106
src/assembly.h
106
src/assembly.h
|
|
@ -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 */
|
||||
|
|
@ -156,20 +152,6 @@ static __inline Word64 SHL64(Word64 x, int n)
|
|||
}
|
||||
}
|
||||
|
||||
// Shift right 26 and return the lower 16-bits (short)
|
||||
static __inline short SAR64_Clip(Word64 x)
|
||||
{
|
||||
unsigned int xLo = ((unsigned int *)&x)[0];
|
||||
int xHi = ((int *)&x)[1];
|
||||
|
||||
__asm {
|
||||
mov edx, xHi
|
||||
mov eax, xLo
|
||||
mov cl, 26
|
||||
shrd eax, edx, cl
|
||||
}
|
||||
}
|
||||
|
||||
static __inline Word64 SAR64(Word64 x, int n)
|
||||
{
|
||||
unsigned int xLo = ((unsigned int *)&x)[0];
|
||||
|
|
@ -285,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)
|
||||
{
|
||||
|
|
@ -335,54 +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;
|
||||
}
|
||||
|
||||
// Shift the 64-bit value right by 26 bits and return the lower 16-bits
|
||||
__attribute__((__always_inline__)) static __inline short SAR64_Clip(Word64 x)
|
||||
{
|
||||
unsigned int xLo = (unsigned int) x;
|
||||
int xHi = (int) (x >> 32);
|
||||
__asm__ __volatile__(
|
||||
"lsr %1, %1, #26\n\t" // xLo <- xLo>>n
|
||||
"orr %1, %1, %0, lsl #6\n\t" // xLo <= xLo || (xHi << 6)
|
||||
: "+&r" (xHi), "+r" (xLo) );
|
||||
return( (short)xLo );
|
||||
}
|
||||
|
||||
__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.
|
||||
|
|
@ -535,44 +469,8 @@ __attribute__((__always_inline__)) static __inline Word64 SAR64(Word64 x, int n)
|
|||
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#warning "Using generic implementation of intrinsics"
|
||||
|
||||
typedef int64_t Word64;
|
||||
|
||||
static inline int MULSHIFT32(int x, int y) {
|
||||
return ((int64_t)x * y) >> 32;
|
||||
}
|
||||
|
||||
static inline int FASTABS(int x) {
|
||||
int sign = x >> 31;
|
||||
return (x ^ sign) - sign;
|
||||
}
|
||||
|
||||
static inline int CLZ(int x) {
|
||||
return __builtin_clz(x);
|
||||
}
|
||||
|
||||
static inline Word64 MADD64(Word64 sum, int x, int y) {
|
||||
return sum + (int64_t)x * y;
|
||||
}
|
||||
|
||||
static inline Word64 SHL64(Word64 x, int n) {
|
||||
return x << n;
|
||||
}
|
||||
|
||||
static inline Word64 SAR64(Word64 x, int n) {
|
||||
return x >> n;
|
||||
}
|
||||
|
||||
static inline short SAR64_Clip(Word64 x) {
|
||||
return SAR64(x, 26);
|
||||
}
|
||||
#error Unsupported platform in assembly.h
|
||||
|
||||
#endif /* platforms */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _ASSEMBLY_H */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
*/
|
||||
}
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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)
|
||||
|
|
@ -44,7 +44,6 @@
|
|||
|
||||
#include "coder.h"
|
||||
#include "assembly.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**************************************************************************************
|
||||
* Function: AntiAlias
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -44,9 +44,7 @@
|
|||
#ifndef _MP3DEC_H
|
||||
#define _MP3DEC_H
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE)
|
||||
#
|
||||
|
|
@ -60,12 +58,8 @@
|
|||
#
|
||||
#elif defined(__GNUC__) && defined(ARM)
|
||||
#
|
||||
#elif defined(__GNUC__) && defined(__ARMEL__)
|
||||
#
|
||||
#elif defined(__GNUC__) && defined(__i386__)
|
||||
#
|
||||
#elif defined(__GNUC__) && defined(__amd64__)
|
||||
#
|
||||
#elif defined(_OPENWAVE_SIMULATOR) || defined(_OPENWAVE_ARMULATOR)
|
||||
#
|
||||
#elif defined(__GNUC__) && defined(__AVR32_UC__)
|
||||
|
|
|
|||
|
|
@ -142,8 +142,7 @@ void PolyphaseMono(short *pcm, int *vbuf, const int *coefBase)
|
|||
MC0M(6)
|
||||
MC0M(7)
|
||||
|
||||
// *(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 0) = SAR64_Clip(sum1L);
|
||||
*(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
|
||||
/* special case, output sample 16 */
|
||||
coef = coefBase + 256;
|
||||
|
|
@ -159,8 +158,7 @@ void PolyphaseMono(short *pcm, int *vbuf, const int *coefBase)
|
|||
MC1M(6)
|
||||
MC1M(7)
|
||||
|
||||
// *(pcm + 16) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 16) = SAR64_Clip(sum1L);
|
||||
*(pcm + 16) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
|
||||
/* main convolution loop: sum1L = samples 1, 2, 3, ... 15 sum2L = samples 31, 30, ... 17 */
|
||||
coef = coefBase + 16;
|
||||
|
|
@ -181,10 +179,8 @@ void PolyphaseMono(short *pcm, int *vbuf, const int *coefBase)
|
|||
MC2M(7)
|
||||
|
||||
vb1 += 64;
|
||||
// *(pcm) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
// *(pcm + 2*i) = ClipToShort((int)SAR64(sum2L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm) = SAR64_Clip(sum1L);
|
||||
*(pcm + 2*i) = SAR64_Clip(sum2L);
|
||||
*(pcm) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 2*i) = ClipToShort((int)SAR64(sum2L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
pcm++;
|
||||
}
|
||||
}
|
||||
|
|
@ -259,10 +255,8 @@ void PolyphaseStereo(short *pcm, int *vbuf, const int *coefBase)
|
|||
MC0S(6)
|
||||
MC0S(7)
|
||||
|
||||
// *(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
// *(pcm + 1) = ClipToShort((int)SAR64(sum1R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 0) = SAR64_Clip(sum1L);
|
||||
*(pcm + 1) = SAR64_Clip(sum1R);
|
||||
*(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 1) = ClipToShort((int)SAR64(sum1R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
|
||||
/* special case, output sample 16 */
|
||||
coef = coefBase + 256;
|
||||
|
|
@ -278,10 +272,8 @@ void PolyphaseStereo(short *pcm, int *vbuf, const int *coefBase)
|
|||
MC1S(6)
|
||||
MC1S(7)
|
||||
|
||||
// *(pcm + 2*16 + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
// *(pcm + 2*16 + 1) = ClipToShort((int)SAR64(sum1R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 2*16 + 0) = SAR64_Clip(sum1L);
|
||||
*(pcm + 2*16 + 1) = SAR64_Clip(sum1R);
|
||||
*(pcm + 2*16 + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 2*16 + 1) = ClipToShort((int)SAR64(sum1R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
|
||||
/* main convolution loop: sum1L = samples 1, 2, 3, ... 15 sum2L = samples 31, 30, ... 17 */
|
||||
coef = coefBase + 16;
|
||||
|
|
@ -303,15 +295,10 @@ void PolyphaseStereo(short *pcm, int *vbuf, const int *coefBase)
|
|||
MC2S(7)
|
||||
|
||||
vb1 += 64;
|
||||
// *(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
// *(pcm + 1) = ClipToShort((int)SAR64(sum1R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 0) = SAR64_Clip(sum1L);
|
||||
*(pcm + 1) = SAR64_Clip(sum1R);
|
||||
// *(pcm + 2*2*i + 0) = ClipToShort((int)SAR64(sum2L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
// *(pcm + 2*2*i + 1) = ClipToShort((int)SAR64(sum2R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 2*2*i + 0) = SAR64_Clip(sum2L);
|
||||
*(pcm + 2*2*i + 1) = SAR64_Clip(sum2R);
|
||||
|
||||
*(pcm + 0) = ClipToShort((int)SAR64(sum1L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 1) = ClipToShort((int)SAR64(sum1R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 2*2*i + 0) = ClipToShort((int)SAR64(sum2L, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
*(pcm + 2*2*i + 1) = ClipToShort((int)SAR64(sum2R, (32-CSHIFT)), DEF_NFRACBITS);
|
||||
pcm += 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -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]);
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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
|
||||
Loading…
Reference in a new issue