1
0
Fork 0
forked from len0rd/rockbox

FS#12141 by Sean Bartell

Some of these were found with http://www.samba.org/junkcode/#findstatic. Changes of note:
* The old MDCT has been removed.
* Makefile.test files that create test programs for libatrac, libcook, and libffmpegFLAC have been removed, as they don't work. My project will have a replacement that works with all codecs.
* I've tried not to remove anything useful. CLIP_TO_15 was removed from libtremor because there's another copy (also commented) in codeclib.



git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29945 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Nils Wallménius 2011-06-02 14:59:15 +00:00
parent b58d3656d7
commit 4909e09267
26 changed files with 27 additions and 1826 deletions

View file

@ -83,7 +83,6 @@ enum codec_status codec_run(void)
}
/* initialise the sound converter */
create_alac(demux_res.sound_sample_size, demux_res.num_channels,&alac);
alac_set_info(&alac, demux_res.codecdata);
/* Set i for first frame, seek to desired sample position for resuming. */

View file

@ -1,4 +1,3 @@
crc.c
predictor.c
#ifdef CPU_ARM
predictor-arm.S

View file

@ -3,16 +3,11 @@ codeclib.c
fixedpoint.c
ffmpeg_bitstream.c
/* OLD MDCT */
/* (when all other codecs are remediated this can be remoed) */
mdct2.c
mdct_lookup.c
fft-ffmpeg.c
mdct.c
#ifdef CPU_ARM
mdct_arm.S
../../../firmware/target/arm/support-arm.S
#endif

View file

@ -1,513 +0,0 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
* *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
* BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
* *
********************************************************************
function: normalized modified discrete cosine transform
power of two length transform only [64 <= n ]
Original algorithm adapted long ago from _The use of multirate filter
banks for coding of high quality digital audio_, by T. Sporer,
K. Brandenburg and B. Edler, collection of the European Signal
Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp
211-214
The below code implements an algorithm that no longer looks much like
that presented in the paper, but the basic structure remains if you
dig deep enough to see it.
This module DOES NOT INCLUDE code to generate/apply the window
function. Everybody has their own weird favorite including me... I
happen to like the properties of y=sin(.5PI*sin^2(x)), but others may
vehemently disagree.
********************************************************************/
/*Tremor IMDCT adapted for use with libwmai*/
#include "mdct2.h"
#include "mdct_lookup.h"
#ifdef ROCKBOX
#include <codecs/lib/codeclib.h>
#endif /* ROCKBOX */
#if defined(CPU_ARM)
extern void mdct_butterfly_32(int32_t *x);
extern void mdct_butterfly_generic_loop(int32_t *x1, int32_t *x2,
const int32_t *T0, int step,
const int32_t *Ttop);
static inline void mdct_butterfly_generic(int32_t *x,int points, int step){
mdct_butterfly_generic_loop(x + points, x + (points>>1), sincos_lookup0, step, sincos_lookup0+1024);
}
#else
/* 8 point butterfly (in place) */
static inline void mdct_butterfly_8(int32_t *x){
register int32_t r0 = x[4] + x[0];
register int32_t r1 = x[4] - x[0];
register int32_t r2 = x[5] + x[1];
register int32_t r3 = x[5] - x[1];
register int32_t r4 = x[6] + x[2];
register int32_t r5 = x[6] - x[2];
register int32_t r6 = x[7] + x[3];
register int32_t r7 = x[7] - x[3];
x[0] = r5 + r3;
x[1] = r7 - r1;
x[2] = r5 - r3;
x[3] = r7 + r1;
x[4] = r4 - r0;
x[5] = r6 - r2;
x[6] = r4 + r0;
x[7] = r6 + r2;
}
/* 16 point butterfly (in place, 4 register) */
static inline void mdct_butterfly_16(int32_t *x){
register int32_t r0, r1;
r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0];
r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1];
x[ 0] = MULT31((r0 + r1) , cPI2_8);
x[ 1] = MULT31((r1 - r0) , cPI2_8);
r0 = x[10] - x[ 2]; x[10] += x[ 2];
r1 = x[ 3] - x[11]; x[11] += x[ 3];
x[ 2] = r1; x[ 3] = r0;
r0 = x[12] - x[ 4]; x[12] += x[ 4];
r1 = x[13] - x[ 5]; x[13] += x[ 5];
x[ 4] = MULT31((r0 - r1) , cPI2_8);
x[ 5] = MULT31((r0 + r1) , cPI2_8);
r0 = x[14] - x[ 6]; x[14] += x[ 6];
r1 = x[15] - x[ 7]; x[15] += x[ 7];
x[ 6] = r0; x[ 7] = r1;
mdct_butterfly_8(x);
mdct_butterfly_8(x+8);
}
/* 32 point butterfly (in place, 4 register) */
static inline void mdct_butterfly_32(int32_t *x){
register int32_t r0, r1;
r0 = x[30] - x[14]; x[30] += x[14];
r1 = x[31] - x[15]; x[31] += x[15];
x[14] = r0; x[15] = r1;
r0 = x[28] - x[12]; x[28] += x[12];
r1 = x[29] - x[13]; x[29] += x[13];
XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] );
r0 = x[26] - x[10]; x[26] += x[10];
r1 = x[27] - x[11]; x[27] += x[11];
x[10] = MULT31((r0 - r1) , cPI2_8);
x[11] = MULT31((r0 + r1) , cPI2_8);
r0 = x[24] - x[ 8]; x[24] += x[ 8];
r1 = x[25] - x[ 9]; x[25] += x[ 9];
XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] );
r0 = x[22] - x[ 6]; x[22] += x[ 6];
r1 = x[ 7] - x[23]; x[23] += x[ 7];
x[ 6] = r1; x[ 7] = r0;
r0 = x[ 4] - x[20]; x[20] += x[ 4];
r1 = x[ 5] - x[21]; x[21] += x[ 5];
XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] );
r0 = x[ 2] - x[18]; x[18] += x[ 2];
r1 = x[ 3] - x[19]; x[19] += x[ 3];
x[ 2] = MULT31((r1 + r0) , cPI2_8);
x[ 3] = MULT31((r1 - r0) , cPI2_8);
r0 = x[ 0] - x[16]; x[16] += x[ 0];
r1 = x[ 1] - x[17]; x[17] += x[ 1];
XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] );
mdct_butterfly_16(x);
mdct_butterfly_16(x+16);
}
/* N/stage point generic N stage butterfly (in place, 4 register) */
void mdct_butterfly_generic(int32_t *x,int points, int step)
ICODE_ATTR_TREMOR_MDCT;
void mdct_butterfly_generic(int32_t *x,int points, int step){
const int32_t *T = sincos_lookup0;
int32_t *x1 = x + points - 8;
int32_t *x2 = x + (points>>1) - 8;
register int32_t r0;
register int32_t r1;
register int32_t r2;
register int32_t r3;
do{
r0 = x1[6] - x2[6]; x1[6] += x2[6];
r1 = x2[7] - x1[7]; x1[7] += x2[7];
r2 = x1[4] - x2[4]; x1[4] += x2[4];
r3 = x2[5] - x1[5]; x1[5] += x2[5];
XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step;
XPROD31( r3, r2, T[0], T[1], &x2[4], &x2[5] ); T+=step;
r0 = x1[2] - x2[2]; x1[2] += x2[2];
r1 = x2[3] - x1[3]; x1[3] += x2[3];
r2 = x1[0] - x2[0]; x1[0] += x2[0];
r3 = x2[1] - x1[1]; x1[1] += x2[1];
XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step;
XPROD31( r3, r2, T[0], T[1], &x2[0], &x2[1] ); T+=step;
x1-=8; x2-=8;
}while(T<sincos_lookup0+1024);
do{
r0 = x1[6] - x2[6]; x1[6] += x2[6];
r1 = x1[7] - x2[7]; x1[7] += x2[7];
r2 = x1[4] - x2[4]; x1[4] += x2[4];
r3 = x1[5] - x2[5]; x1[5] += x2[5];
XNPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T-=step;
XNPROD31( r2, r3, T[0], T[1], &x2[4], &x2[5] ); T-=step;
r0 = x1[2] - x2[2]; x1[2] += x2[2];
r1 = x1[3] - x2[3]; x1[3] += x2[3];
r2 = x1[0] - x2[0]; x1[0] += x2[0];
r3 = x1[1] - x2[1]; x1[1] += x2[1];
XNPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T-=step;
XNPROD31( r2, r3, T[0], T[1], &x2[0], &x2[1] ); T-=step;
x1-=8; x2-=8;
}while(T>sincos_lookup0);
do{
r0 = x2[6] - x1[6]; x1[6] += x2[6];
r1 = x2[7] - x1[7]; x1[7] += x2[7];
r2 = x2[4] - x1[4]; x1[4] += x2[4];
r3 = x2[5] - x1[5]; x1[5] += x2[5];
XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step;
XPROD31( r2, r3, T[0], T[1], &x2[4], &x2[5] ); T+=step;
r0 = x2[2] - x1[2]; x1[2] += x2[2];
r1 = x2[3] - x1[3]; x1[3] += x2[3];
r2 = x2[0] - x1[0]; x1[0] += x2[0];
r3 = x2[1] - x1[1]; x1[1] += x2[1];
XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step;
XPROD31( r2, r3, T[0], T[1], &x2[0], &x2[1] ); T+=step;
x1-=8; x2-=8;
}while(T<sincos_lookup0+1024);
do{
r0 = x1[6] - x2[6]; x1[6] += x2[6];
r1 = x2[7] - x1[7]; x1[7] += x2[7];
r2 = x1[4] - x2[4]; x1[4] += x2[4];
r3 = x2[5] - x1[5]; x1[5] += x2[5];
XNPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T-=step;
XNPROD31( r3, r2, T[0], T[1], &x2[4], &x2[5] ); T-=step;
r0 = x1[2] - x2[2]; x1[2] += x2[2];
r1 = x2[3] - x1[3]; x1[3] += x2[3];
r2 = x1[0] - x2[0]; x1[0] += x2[0];
r3 = x2[1] - x1[1]; x1[1] += x2[1];
XNPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T-=step;
XNPROD31( r3, r2, T[0], T[1], &x2[0], &x2[1] ); T-=step;
x1-=8; x2-=8;
}while(T>sincos_lookup0);
}
#endif /* CPU_ARM */
static inline void mdct_butterflies(int32_t *x,int points,int shift) {
int stages=8-shift;
int i,j;
for(i=0;--stages>0;i++){
for(j=0;j<(1<<i);j++)
mdct_butterfly_generic(x+(points>>i)*j,points>>i,4<<(i+shift));
}
for(j=0;j<points;j+=32)
mdct_butterfly_32(x+j);
}
static const unsigned char bitrev[] ICONST_ATTR =
{
0, 32, 16, 48, 8, 40, 24, 56, 4, 36, 20, 52, 12, 44, 28, 60,
2, 34, 18, 50, 10, 42, 26, 58, 6, 38, 22, 54, 14, 46, 30, 62,
1, 33, 17, 49, 9, 41, 25, 57, 5, 37, 21, 53, 13, 45, 29, 61,
3, 35, 19, 51, 11, 43, 27, 59, 7, 39, 23, 55, 15, 47, 31, 63
};
static inline int bitrev12(int x){
return bitrev[x>>6]|((bitrev[x&0x03f])<<6);
}
static inline void mdct_bitreverse(int32_t *x,int n,int step,int shift) {
int bit = 0;
int32_t *w0 = x;
int32_t *w1 = x = w0+(n>>1);
const int32_t *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
const int32_t *Ttop = T+1024;
register int32_t r2;
do{
register int32_t r3 = bitrev12(bit++);
int32_t *x0 = x + ((r3 ^ 0xfff)>>shift) -1;
int32_t *x1 = x + (r3>>shift);
register int32_t r0 = x0[0] + x1[0];
register int32_t r1 = x1[1] - x0[1];
XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step;
w1 -= 4;
r0 = (x0[1] + x1[1])>>1;
r1 = (x0[0] - x1[0])>>1;
w0[0] = r0 + r2;
w0[1] = r1 + r3;
w1[2] = r0 - r2;
w1[3] = r3 - r1;
r3 = bitrev12(bit++);
x0 = x + ((r3 ^ 0xfff)>>shift) -1;
x1 = x + (r3>>shift);
r0 = x0[0] + x1[0];
r1 = x1[1] - x0[1];
XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step;
r0 = (x0[1] + x1[1])>>1;
r1 = (x0[0] - x1[0])>>1;
w0[2] = r0 + r2;
w0[3] = r1 + r3;
w1[0] = r0 - r2;
w1[1] = r3 - r1;
w0 += 4;
}while(T<Ttop);
do{
register int32_t r3 = bitrev12(bit++);
int32_t *x0 = x + ((r3 ^ 0xfff)>>shift) -1;
int32_t *x1 = x + (r3>>shift);
register int32_t r0 = x0[0] + x1[0];
register int32_t r1 = x1[1] - x0[1];
T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 );
w1 -= 4;
r0 = (x0[1] + x1[1])>>1;
r1 = (x0[0] - x1[0])>>1;
w0[0] = r0 + r2;
w0[1] = r1 + r3;
w1[2] = r0 - r2;
w1[3] = r3 - r1;
r3 = bitrev12(bit++);
x0 = x + ((r3 ^ 0xfff)>>shift) -1;
x1 = x + (r3>>shift);
r0 = x0[0] + x1[0];
r1 = x1[1] - x0[1];
T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 );
r0 = (x0[1] + x1[1])>>1;
r1 = (x0[0] - x1[0])>>1;
w0[2] = r0 + r2;
w0[3] = r1 + r3;
w1[0] = r0 - r2;
w1[1] = r3 - r1;
w0 += 4;
}while(w0<w1);
}
void mdct_backward(int n, int32_t *in, int32_t *out)
ICODE_ATTR_TREMOR_MDCT;
void mdct_backward(int n, int32_t *in, int32_t *out) {
int n2=n>>1;
int n4=n>>2;
int32_t *iX;
int32_t *oX;
const int32_t *T;
const int32_t *V;
int shift;
int step;
for (shift=6;!(n&(1<<shift));shift++);
shift=13-shift;
step=2<<shift;
/* rotate */
iX = in+n2-7;
oX = out+n2+n4;
T = sincos_lookup0;
do{
oX-=4;
XPROD31( iX[4], iX[6], T[0], T[1], &oX[2], &oX[3] ); T+=step;
XPROD31( iX[0], iX[2], T[0], T[1], &oX[0], &oX[1] ); T+=step;
iX-=8;
}while(iX>=in+n4);
do{
oX-=4;
XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step;
XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step;
iX-=8;
}while(iX>=in);
iX = in+n2-8;
oX = out+n2+n4;
T = sincos_lookup0;
do{
T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] );
T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] );
iX-=8;
oX+=4;
}while(iX>=in+n4);
do{
T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] );
T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] );
iX-=8;
oX+=4;
}while(iX>=in);
mdct_butterflies(out+n2,n2,shift);
mdct_bitreverse(out,n,step,shift);
/* rotate + window */
step>>=2;
{
int32_t *oX1=out+n2+n4;
int32_t *oX2=out+n2+n4;
int32_t *iX =out;
switch(step) {
default: {
T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
do{
oX1-=4;
XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step;
XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step;
XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step;
XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step;
oX2+=4;
iX+=8;
}while(iX<oX1);
break;
}
case 1: {
/* linear interpolation between table values: offset=0.5, step=1 */
register int32_t t0,t1,v0,v1;
T = sincos_lookup0;
V = sincos_lookup1;
t0 = (*T++)>>1;
t1 = (*T++)>>1;
do{
oX1-=4;
t0 += (v0 = (*V++)>>1);
t1 += (v1 = (*V++)>>1);
XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] );
v0 += (t0 = (*T++)>>1);
v1 += (t1 = (*T++)>>1);
XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] );
t0 += (v0 = (*V++)>>1);
t1 += (v1 = (*V++)>>1);
XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] );
v0 += (t0 = (*T++)>>1);
v1 += (t1 = (*T++)>>1);
XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] );
oX2+=4;
iX+=8;
}while(iX<oX1);
break;
}
case 0: {
/* linear interpolation between table values: offset=0.25, step=0.5 */
register int32_t t0,t1,v0,v1,q0,q1;
T = sincos_lookup0;
V = sincos_lookup1;
t0 = *T++;
t1 = *T++;
do{
oX1-=4;
v0 = *V++;
v1 = *V++;
t0 += (q0 = (v0-t0)>>2);
t1 += (q1 = (v1-t1)>>2);
XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] );
t0 = v0-q0;
t1 = v1-q1;
XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] );
t0 = *T++;
t1 = *T++;
v0 += (q0 = (t0-v0)>>2);
v1 += (q1 = (t1-v1)>>2);
XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] );
v0 = t0-q0;
v1 = t1-q1;
XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] );
oX2+=4;
iX+=8;
}while(iX<oX1);
break;
}
}
iX=out+n2+n4;
oX1=out+n4;
oX2=oX1;
do{
oX1-=4;
iX-=4;
oX2[0] = -(oX1[3] = iX[3]);
oX2[1] = -(oX1[2] = iX[2]);
oX2[2] = -(oX1[1] = iX[1]);
oX2[3] = -(oX1[0] = iX[0]);
oX2+=4;
}while(oX2<iX);
iX=out+n2+n4;
oX1=out+n2+n4;
oX2=out+n2;
do{
oX1-=4;
oX1[0]= iX[3];
oX1[1]= iX[2];
oX1[2]= iX[1];
oX1[3]= iX[0];
iX+=4;
}while(oX1>oX2);
}
}

View file

@ -1,76 +0,0 @@
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
* *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
* BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
* *
********************************************************************
function: modified discrete cosine transform prototypes
********************************************************************/
#ifndef _OGG_mdct_H_
#define _OGG_mdct_H_
#ifdef _LOW_ACCURACY_
# define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9))
# //define LOOKUP_T const unsigned char
#else
# define X(n) (n)
# //define LOOKUP_T const ogg_int32_t
#endif
#ifdef ROCKBOX
#include <codecs.h>
#endif /* ROCKBOX */
#include "codeclib_misc.h"
#ifndef ICONST_ATTR_TREMOR_WINDOW
#define ICONST_ATTR_TREMOR_WINDOW ICONST_ATTR
#endif
#ifndef ICODE_ATTR_TREMOR_MDCT
#define ICODE_ATTR_TREMOR_MDCT ICODE_ATTR
#endif
#ifndef ICODE_ATTR_TREMOR_NOT_MDCT
#define ICODE_ATTR_TREMOR_NOT_MDCT ICODE_ATTR
#endif
#ifdef _LOW_ACCURACY_
#define cPI3_8 (0x0062)
#define cPI2_8 (0x00b5)
#define cPI1_8 (0x00ed)
#else
#define cPI3_8 (0x30fbc54d)
#define cPI2_8 (0x5a82799a)
#define cPI1_8 (0x7641af3d)
#endif
extern void mdct_backward(int n, int32_t *in, int32_t *out);
#endif

View file

@ -1,437 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007 by Tomasz Malesinski
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
/* Codecs should not normally do this, but we need to check a macro, and
* codecs.h would confuse the assembler. */
#define cPI3_8 (0x30fbc54d)
#define cPI2_8 (0x5a82799a)
#define cPI1_8 (0x7641af3d)
#ifdef USE_IRAM
.section .icode,"ax",%progbits
#else
.text
#endif
.align
.global mdct_butterfly_32
.global mdct_butterfly_generic_loop
mdct_butterfly_8:
@ inputs: r0,r1,r2,r3,r4,r5,r6,r10,r11 &lr
@ uses: r8,r9,r12(scratch)
@ modifies: r0,r1,r2,r3,r4,r5,r6,r10,r11. increments r0 by #8*4
add r9, r5, r1 @ x4 + x0
sub r5, r5, r1 @ x4 - x0
add r7, r6, r2 @ x5 + x1
sub r6, r6, r2 @ x5 - x1
add r8, r10, r3 @ x6 + x2
sub r10, r10, r3 @ x6 - x2
add r12, r11, r4 @ x7 + x3
sub r11, r11, r4 @ x7 - x3
add r1, r10, r6 @ y0 = (x6 - x2) + (x5 - x1)
sub r2, r11, r5 @ y1 = (x7 - x3) - (x4 - x0)
sub r3, r10, r6 @ y2 = (x6 - x2) - (x5 - x1)
add r4, r11, r5 @ y3 = (x7 - x3) + (x4 - x0)
sub r5, r8, r9 @ y4 = (x6 + x2) - (x4 + x0)
sub r6, r12, r7 @ y5 = (x7 + x3) - (x5 + x1)
add r10, r8, r9 @ y6 = (x6 + x2) + (x4 + x0)
add r11, r12, r7 @ y7 = (x7 + x3) + (x5 + x1)
stmia r0!, {r1, r2, r3, r4, r5, r6, r10, r11}
bx lr
mdct_butterfly_16:
@ inputs: r0,r1 &lr
@ uses: r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12
@ modifies: r0. increments r0 by #16*4
@ calls mdct_butterfly_8 via bl so need to stack lr for return address
str lr, [sp, #-4]!
add r1, r0, #8*4
ldmia r0, {r2, r3, r4, r5}
ldmia r1, {r6, r7, r8, r9}
add r6, r6, r2 @ y8 = x8 + x0
rsb r2, r6, r2, asl #1 @ x0 - x8
add r7, r7, r3 @ y9 = x9 + x1
rsb r3, r7, r3, asl #1 @ x1 - x9
add r8, r8, r4 @ y10 = x10 + x2
sub r11, r8, r4, asl #1 @ x10 - x2
add r9, r9, r5 @ y11 = x11 + x3
rsb r10, r9, r5, asl #1 @ x3 - x11
stmia r1!, {r6, r7, r8, r9}
add r2, r2, r3 @ (x0 - x8) + (x1 - x9)
rsb r3, r2, r3, asl #1 @ (x1 - x9) - (x0 - x8)
ldr r12, =cPI2_8
smull r8, r5, r12, r2
smull r8, r6, r12, r3
mov r5, r5, asl #1
mov r6, r6, asl #1
stmia r0!, {r5, r6, r10, r11}
ldmia r0, {r2, r3, r4, r5}
ldmia r1, {r6, r7, r8, r9}
add r6, r6, r2 @ y12 = x12 + x4
sub r2, r6, r2, asl #1 @ x12 - x4
add r7, r7, r3 @ y13 = x13 + x5
sub r3, r7, r3, asl #1 @ x13 - x5
add r8, r8, r4 @ y10 = x14 + x6
sub r10, r8, r4, asl #1 @ x14 - x6
add r9, r9, r5 @ y11 = x15 + x7
sub r11, r9, r5, asl #1 @ x15 - x7
stmia r1, {r6, r7, r8, r9}
sub r2, r2, r3 @ (x12 - x4) - (x13 - x5)
add r3, r2, r3, asl #1 @ (x12 - x4) + (x13 - x5)
smull r8, r5, r12, r2
smull r8, r6, r12, r3
mov r5, r5, asl #1
mov r6, r6, asl #1
@ no stmia here, r5, r6, r10, r11 are passed to mdct_butterfly_8
sub r0, r0, #4*4
ldmia r0, {r1, r2, r3, r4}
bl mdct_butterfly_8
@ mdct_butterfly_8 will have incremented r0 by #8*4 already
ldmia r0, {r1, r2, r3, r4, r5, r6, r10, r11}
bl mdct_butterfly_8
@ mdct_butterfly_8 increments r0 by another #8*4 here
@ at end, r0 has been incremented by #16*4
ldrpc
mdct_butterfly_32:
stmdb sp!, {r4-r11, lr}
add r1, r0, #16*4
ldmia r0, {r2, r3, r4, r5}
ldmia r1, {r6, r7, r8, r9}
add r6, r6, r2 @ y16 = x16 + x0
rsb r2, r6, r2, asl #1 @ x0 - x16
add r7, r7, r3 @ y17 = x17 + x1
rsb r3, r7, r3, asl #1 @ x1 - x17
add r8, r8, r4 @ y18 = x18 + x2
rsb r4, r8, r4, asl #1 @ x2 - x18
add r9, r9, r5 @ y19 = x19 + x3
rsb r5, r9, r5, asl #1 @ x3 - x19
stmia r1!, {r6, r7, r8, r9}
ldr r12, =cPI1_8
ldr lr, =cPI3_8
smull r10, r6, r12, r2
rsb r2, r2, #0
smlal r10, r6, lr, r3
smull r10, r7, r12, r3
smlal r10, r7, lr, r2
mov r6, r6, asl #1
mov r7, r7, asl #1
add r4, r4, r5 @ (x3 - x19) + (x2 - x18)
rsb r5, r4, r5, asl #1 @ (x3 - x19) - (x2 - x18)
ldr r11, =cPI2_8
smull r10, r8, r4, r11
smull r10, r9, r5, r11
mov r8, r8, asl #1
mov r9, r9, asl #1
stmia r0!, {r6, r7, r8, r9}
ldmia r0, {r2, r3, r4, r5}
ldmia r1, {r6, r7, r8, r9}
add r6, r6, r2 @ y20 = x20 + x4
rsb r2, r6, r2, asl #1 @ x4 - x20
add r7, r7, r3 @ y21 = x21 + x5
rsb r3, r7, r3, asl #1 @ x5 - x21
add r8, r8, r4 @ y22 = x22 + x6
sub r11, r8, r4, asl #1 @ x22 - x6
add r9, r9, r5 @ y23 = x23 + x7
rsb r10, r9, r5, asl #1 @ x7 - x23
stmia r1!, {r6, r7, r8, r9}
@r4,r5,r6,r7,r8,r9 now free
@ we don't use r5, r8, r9 below
smull r4, r6, lr, r2
rsb r2, r2, #0
smlal r4, r6, r12, r3
smull r4, r7, lr, r3
smlal r4, r7, r12, r2
mov r6, r6, asl #1
mov r7, r7, asl #1
stmia r0!, {r6, r7, r10, r11}
ldmia r0, {r2, r3, r4, r5}
ldmia r1, {r6, r7, r8, r9}
add r6, r6, r2 @ y24 = x24 + x8
sub r2, r6, r2, asl #1 @ x24 - x8
add r7, r7, r3 @ y25 = x25 + x9
sub r3, r7, r3, asl #1 @ x25 - x9
add r8, r8, r4 @ y26 = x26 + x10
sub r4, r8, r4, asl #1 @ x26 - x10
add r9, r9, r5 @ y27 = x27 + x11
sub r5, r9, r5, asl #1 @ x27 - x11
stmia r1!, {r6, r7, r8, r9}
smull r10, r7, lr, r3
rsb r3, r3, #0
smlal r10, r7, r12, r2
smull r10, r6, r12, r3
smlal r10, r6, lr, r2
mov r6, r6, asl #1
mov r7, r7, asl #1
sub r4, r4, r5 @ (x26 - x10) - (x27 - x11)
add r5, r4, r5, asl #1 @ (x26 - x10) + (x27 - x11)
ldr r11, =cPI2_8
smull r10, r8, r11, r4
smull r10, r9, r11, r5
mov r8, r8, asl #1
mov r9, r9, asl #1
stmia r0!, {r6, r7, r8, r9}
ldmia r0, {r2, r3, r4, r5}
ldmia r1, {r6, r7, r8, r9}
add r6, r6, r2 @ y28 = x28 + x12
sub r2, r6, r2, asl #1 @ x28 - x12
add r7, r7, r3 @ y29 = x29 + x13
sub r3, r7, r3, asl #1 @ x29 - x13
add r8, r8, r4 @ y30 = x30 + x14
sub r10, r8, r4, asl #1 @ x30 - x14
add r9, r9, r5 @ y31 = x31 + x15
sub r11, r9, r5, asl #1 @ x31 - x15
stmia r1, {r6, r7, r8, r9}
@ r4,r5,r6,r7,r8,r9 now free
@ we don't use r5,r8,r9 below
smull r4, r7, r12, r3
rsb r3, r3, #0
smlal r4, r7, lr, r2
smull r4, r6, lr, r3
smlal r4, r6, r12, r2
mov r6, r6, asl #1
mov r7, r7, asl #1
stmia r0, {r6, r7, r10, r11}
sub r0, r0, #12*4
bl mdct_butterfly_16
@ we know mdct_butterfly_16 increments r0 by #16*4
@ and we wanted to advance by #16*4 anyway, so just call again
bl mdct_butterfly_16
ldmpc regs=r4-r11
@ mdct_butterfly_generic_loop(x1, x2, T0, step, Ttop)
mdct_butterfly_generic_loop:
stmdb sp!, {r4-r11, lr}
str r2, [sp, #-4]
ldr r4, [sp, #36]
1:
ldmdb r0, {r6, r7, r8, r9}
ldmdb r1, {r10, r11, r12, r14}
add r6, r6, r10
sub r10, r6, r10, asl #1
add r7, r7, r11
rsb r11, r7, r11, asl #1
add r8, r8, r12
sub r12, r8, r12, asl #1
add r9, r9, r14
rsb r14, r9, r14, asl #1
stmdb r0!, {r6, r7, r8, r9}
ldmia r2, {r6, r7}
smull r5, r8, r6, r14
rsb r14, r14, #0
smlal r5, r8, r7, r12
smull r5, r9, r6, r12
smlal r5, r9, r7, r14
mov r8, r8, asl #1
mov r9, r9, asl #1
add r2, r2, r3, asl #2
ldmia r2, {r12, r14}
smull r5, r6, r12, r11
rsb r11, r11, #0
smlal r5, r6, r14, r10
smull r5, r7, r12, r10
smlal r5, r7, r14, r11
mov r6, r6, asl #1
mov r7, r7, asl #1
stmdb r1!, {r6, r7, r8, r9}
add r2, r2, r3, asl #2
cmp r2, r4
blo 1b
ldr r4, [sp, #-4]
1:
ldmdb r0, {r6, r7, r8, r9}
ldmdb r1, {r10, r11, r12, r14}
add r6, r6, r10
sub r10, r6, r10, asl #1
add r7, r7, r11
sub r11, r7, r11, asl #1
add r8, r8, r12
sub r12, r8, r12, asl #1
add r9, r9, r14
sub r14, r9, r14, asl #1
stmdb r0!, {r6, r7, r8, r9}
ldmia r2, {r6, r7}
smull r5, r9, r6, r14
rsb r14, r14, #0
smlal r5, r9, r7, r12
smull r5, r8, r6, r12
smlal r5, r8, r7, r14
mov r8, r8, asl #1
mov r9, r9, asl #1
sub r2, r2, r3, asl #2
ldmia r2, {r12, r14}
smull r5, r7, r12, r11
rsb r11, r11, #0
smlal r5, r7, r14, r10
smull r5, r6, r12, r10
smlal r5, r6, r14, r11
mov r6, r6, asl #1
mov r7, r7, asl #1
stmdb r1!, {r6, r7, r8, r9}
sub r2, r2, r3, asl #2
cmp r2, r4
bhi 1b
ldr r4, [sp, #36]
1:
ldmdb r0, {r6, r7, r8, r9}
ldmdb r1, {r10, r11, r12, r14}
add r6, r6, r10
rsb r10, r6, r10, asl #1
add r7, r7, r11
rsb r11, r7, r11, asl #1
add r8, r8, r12
rsb r12, r8, r12, asl #1
add r9, r9, r14
rsb r14, r9, r14, asl #1
stmdb r0!, {r6, r7, r8, r9}
ldmia r2, {r6, r7}
smull r5, r8, r6, r12
rsb r12, r12, #0
smlal r5, r8, r7, r14
smull r5, r9, r6, r14
smlal r5, r9, r7, r12
mov r8, r8, asl #1
mov r9, r9, asl #1
add r2, r2, r3, asl #2
ldmia r2, {r12, r14}
smull r5, r6, r12, r10
rsb r10, r10, #0
smlal r5, r6, r14, r11
smull r5, r7, r12, r11
smlal r5, r7, r14, r10
mov r6, r6, asl #1
mov r7, r7, asl #1
stmdb r1!, {r6, r7, r8, r9}
add r2, r2, r3, asl #2
cmp r2, r4
blo 1b
ldr r4, [sp, #-4]
1:
ldmdb r0, {r6, r7, r8, r9}
ldmdb r1, {r10, r11, r12, r14}
add r6, r6, r10
sub r10, r6, r10, asl #1
add r7, r7, r11
rsb r11, r7, r11, asl #1
add r8, r8, r12
sub r12, r8, r12, asl #1
add r9, r9, r14
rsb r14, r9, r14, asl #1
stmdb r0!, {r6, r7, r8, r9}
ldmia r2, {r6, r7}
smull r5, r9, r6, r12
smlal r5, r9, r7, r14
rsb r12, r12, #0
smull r5, r8, r6, r14
smlal r5, r8, r7, r12
mov r8, r8, asl #1
mov r9, r9, asl #1
sub r2, r2, r3, asl #2
ldmia r2, {r12, r14}
smull r5, r7, r12, r10
rsb r10, r10, #0
smlal r5, r7, r14, r11
smull r5, r6, r12, r11
smlal r5, r6, r14, r10
mov r6, r6, asl #1
mov r7, r7, asl #1
stmdb r1!, {r6, r7, r8, r9}
sub r2, r2, r3, asl #2
cmp r2, r4
bhi 1b
ldmpc regs=r4-r11

View file

@ -1139,9 +1139,10 @@ int alac_decode_frame(alac_file *alac,
return outputsamples;
}
/* rockbox: not used
void create_alac(int samplesize, int numchannels, alac_file* alac)
{
alac->samplesize = samplesize;
alac->numchannels = numchannels;
alac->bytespersample = (samplesize / 8) * numchannels;
}
} */

View file

@ -17,9 +17,12 @@ typedef struct
unsigned char *input_buffer;
int input_buffer_bitaccumulator; /* used so we can do arbitary
bit reads */
/* rockbox: not used
int samplesize;
int numchannels;
int bytespersample;
int bytespersample; */
int bytes_consumed;
/* stuff from setinfo */
@ -37,8 +40,10 @@ typedef struct
/* end setinfo stuff */
} alac_file;
/* rockbox: not used
void create_alac(int samplesize, int numchannels, alac_file* alac)
ICODE_ATTR_ALAC;
ICODE_ATTR_ALAC; */
int alac_decode_frame(alac_file *alac,
unsigned char *inbuffer,
int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE],

View file

@ -1,11 +0,0 @@
CFLAGS = -Wall -O3 -I../lib -DTEST -D"DEBUGF=printf" -D"ROCKBOX_LITTLE_ENDIAN=1" -D"ICONST_ATTR=" -D"ICODE_ATTR=" -D"IBSS_ATTR="
OBJS = atrac3.o ../lib/ffmpeg_bitstream.o ../librm/rm.o fixp_math.o ../lib/mdct2.o ../lib/mdct_lookup.o main.o
atractest: $(OBJS)
gcc -o atractest $(OBJS)
.c.o :
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f atractest $(OBJS) *~ output.wav

View file

@ -1,168 +0,0 @@
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "atrac3.h"
#include "../librm/rm.h"
ATRAC3Context q IBSS_ATTR;
static unsigned char wav_header[44]={
'R','I','F','F',// 0 - ChunkID
0,0,0,0, // 4 - ChunkSize (filesize-8)
'W','A','V','E',// 8 - Format
'f','m','t',' ',// 12 - SubChunkID
16,0,0,0, // 16 - SubChunk1ID // 16 for PCM
1,0, // 20 - AudioFormat (1=Uncompressed)
2,0, // 22 - NumChannels
0,0,0,0, // 24 - SampleRate in Hz
0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8)
4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8)
16,0, // 34 - BitsPerSample
'd','a','t','a',// 36 - Subchunk2ID
0,0,0,0 // 40 - Subchunk2Size
};
int open_wav(char* filename) {
int fd,res;
fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR);
if (fd >= 0) {
res = write(fd,wav_header,sizeof(wav_header));
}
return(fd);
}
void close_wav(int fd, RMContext *rmctx, ATRAC3Context *q) {
int x,res;
int filesize;
int bytes_per_sample = 2;
int samples_per_frame = q->samples_per_frame;
int nb_channels = rmctx->nb_channels;
int sample_rate = rmctx->sample_rate;
int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output
filesize= samples_per_frame*bytes_per_sample*nb_frames +44;
printf("Filesize = %d\n",filesize);
// ChunkSize
x=filesize-8;
wav_header[4]=(x&0xff);
wav_header[5]=(x&0xff00)>>8;
wav_header[6]=(x&0xff0000)>>16;
wav_header[7]=(x&0xff000000)>>24;
// Number of channels
wav_header[22]=nb_channels;
// Samplerate
wav_header[24]=sample_rate&0xff;
wav_header[25]=(sample_rate&0xff00)>>8;
wav_header[26]=(sample_rate&0xff0000)>>16;
wav_header[27]=(sample_rate&0xff000000)>>24;
// ByteRate
x=sample_rate*bytes_per_sample*nb_channels;
wav_header[28]=(x&0xff);
wav_header[29]=(x&0xff00)>>8;
wav_header[30]=(x&0xff0000)>>16;
wav_header[31]=(x&0xff000000)>>24;
// BlockAlign
wav_header[32]=rmctx->block_align;//2*rmctx->nb_channels;
// Bits per sample
wav_header[34]=16;
// Subchunk2Size
x=filesize-44;
wav_header[40]=(x&0xff);
wav_header[41]=(x&0xff00)>>8;
wav_header[42]=(x&0xff0000)>>16;
wav_header[43]=(x&0xff000000)>>24;
lseek(fd,0,SEEK_SET);
res = write(fd,wav_header,sizeof(wav_header));
close(fd);
}
int main(int argc, char *argv[])
{
int fd, fd_dec;
int res, i, datasize = 0;
#ifdef DUMP_RAW_FRAMES
char filename[15];
int fd_out;
#endif
int16_t outbuf[2048];
uint16_t fs,sps,h;
uint32_t packet_count;
RMContext rmctx;
RMPacket pkt;
memset(&q,0,sizeof(ATRAC3Context));
memset(&rmctx,0,sizeof(RMContext));
memset(&pkt,0,sizeof(RMPacket));
if (argc != 2) {
DEBUGF("Incorrect number of arguments\n");
return -1;
}
fd = open(argv[1],O_RDONLY);
if (fd < 0) {
DEBUGF("Error opening file %s\n", argv[1]);
return -1;
}
/* copy the input rm file to a memory buffer */
uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t));
res = read(fd,filebuf,filesize(fd));
fd_dec = open_wav("output.wav");
if (fd_dec < 0) {
DEBUGF("Error creating output file\n");
return -1;
}
res = real_parse_header(fd, &rmctx);
packet_count = rmctx.nb_packets;
rmctx.audio_framesize = rmctx.block_align;
rmctx.block_align = rmctx.sub_packet_size;
fs = rmctx.audio_framesize;
sps= rmctx.block_align;
h = rmctx.sub_packet_h;
atrac3_decode_init(&q,&rmctx);
/* change the buffer pointer to point at the first audio frame */
advance_buffer(&filebuf, rmctx.data_offset + DATA_HEADER_SIZE);
while(packet_count)
{
rm_get_packet(&filebuf, &rmctx, &pkt);
for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
{
/* output raw audio frames that are sent to the decoder into separate files */
#ifdef DUMP_RAW_FRAMES
snprintf(filename,sizeof(filename),"dump%d.raw",++x);
fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND, 0666);
write(fd_out,pkt.frames[i],sps);
close(fd_out);
#endif
if(pkt.length > 0)
res = atrac3_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align);
rmctx.frame_number++;
res = write(fd_dec,outbuf,datasize);
}
packet_count -= rmctx.audio_pkt_cnt;
rmctx.audio_pkt_cnt = 0;
}
close_wav(fd_dec, &rmctx, &q);
close(fd);
return 0;
}

View file

@ -1,10 +0,0 @@
CFLAGS = -Wall -O3 -I../lib -DTEST -D"DEBUGF=printf" -D"ROCKBOX_LITTLE_ENDIAN=1" -D"ICONST_ATTR=" -D"ICODE_ATTR="
OBJS = main.o ../lib/ffmpeg_bitstream.o cook.o ../librm/rm.o ../lib/mdct2.o ../lib/mdct_lookup.o
cooktest: $(OBJS)
gcc -o cooktest $(OBJS)
.c.o :
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f cooktest $(OBJS) *~ output.wav

View file

@ -1,190 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 Mohamed Tarek
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdint.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "../librm/rm.h"
#include "cook.h"
//#define DUMP_RAW_FRAMES
#define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */
static unsigned char wav_header[44]={
'R','I','F','F',// 0 - ChunkID
0,0,0,0, // 4 - ChunkSize (filesize-8)
'W','A','V','E',// 8 - Format
'f','m','t',' ',// 12 - SubChunkID
16,0,0,0, // 16 - SubChunk1ID // 16 for PCM
1,0, // 20 - AudioFormat (1=Uncompressed)
2,0, // 22 - NumChannels
0,0,0,0, // 24 - SampleRate in Hz
0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8)
4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8)
16,0, // 34 - BitsPerSample
'd','a','t','a',// 36 - Subchunk2ID
0,0,0,0 // 40 - Subchunk2Size
};
int open_wav(char* filename) {
int fd,res;
fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR);
if (fd >= 0) {
res = write(fd,wav_header,sizeof(wav_header));
}
return(fd);
}
void close_wav(int fd, RMContext *rmctx, COOKContext *q) {
int x,res;
int filesize;
int bytes_per_sample = 2;
int samples_per_frame = q->samples_per_frame;
int nb_channels = rmctx->nb_channels;
int sample_rate = rmctx->sample_rate;
int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output
filesize= samples_per_frame*bytes_per_sample*nb_frames +44;
printf("Filesize = %d\n",filesize);
// ChunkSize
x=filesize-8;
wav_header[4]=(x&0xff);
wav_header[5]=(x&0xff00)>>8;
wav_header[6]=(x&0xff0000)>>16;
wav_header[7]=(x&0xff000000)>>24;
// Number of channels
wav_header[22]=nb_channels;
// Samplerate
wav_header[24]=sample_rate&0xff;
wav_header[25]=(sample_rate&0xff00)>>8;
wav_header[26]=(sample_rate&0xff0000)>>16;
wav_header[27]=(sample_rate&0xff000000)>>24;
// ByteRate
x=sample_rate*bytes_per_sample*nb_channels;
wav_header[28]=(x&0xff);
wav_header[29]=(x&0xff00)>>8;
wav_header[30]=(x&0xff0000)>>16;
wav_header[31]=(x&0xff000000)>>24;
// BlockAlign
wav_header[32]=rmctx->block_align;//2*rmctx->nb_channels;
// Bits per sample
wav_header[34]=16;
// Subchunk2Size
x=filesize-44;
wav_header[40]=(x&0xff);
wav_header[41]=(x&0xff00)>>8;
wav_header[42]=(x&0xff0000)>>16;
wav_header[43]=(x&0xff000000)>>24;
lseek(fd,0,SEEK_SET);
res = write(fd,wav_header,sizeof(wav_header));
close(fd);
}
int main(int argc, char *argv[])
{
int fd, fd_dec;
int res, datasize,i;
int nb_frames = 0;
#ifdef DUMP_RAW_FRAMES
char filename[15];
int fd_out;
#endif
int32_t outbuf[2048];
uint16_t fs,sps,h;
uint32_t packet_count;
COOKContext q;
RMContext rmctx;
RMPacket pkt;
memset(&q,0,sizeof(COOKContext));
memset(&rmctx,0,sizeof(RMContext));
memset(&pkt,0,sizeof(RMPacket));
if (argc != 2) {
DEBUGF("Incorrect number of arguments\n");
return -1;
}
fd = open(argv[1],O_RDONLY);
if (fd < 0) {
DEBUGF("Error opening file %s\n", argv[1]);
return -1;
}
/* copy the input rm file to a memory buffer */
uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t));
res = read(fd,filebuf,filesize(fd));
fd_dec = open_wav("output.wav");
if (fd_dec < 0) {
DEBUGF("Error creating output file\n");
return -1;
}
res = real_parse_header(fd, &rmctx);
packet_count = rmctx.nb_packets;
rmctx.audio_framesize = rmctx.block_align;
rmctx.block_align = rmctx.sub_packet_size;
fs = rmctx.audio_framesize;
sps= rmctx.block_align;
h = rmctx.sub_packet_h;
cook_decode_init(&rmctx,&q);
/* change the buffer pointer to point at the first audio frame */
advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE);
while(packet_count)
{
rm_get_packet(&filebuf, &rmctx, &pkt);
//DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt);
for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
{
/* output raw audio frames that are sent to the decoder into separate files */
#ifdef DUMP_RAW_FRAMES
snprintf(filename,sizeof(filename),"dump%d.raw",++x);
fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND, 0666);
write(fd_out,pkt.frames[i],sps);
close(fd_out);
#endif
nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align);
rmctx.frame_number++;
res = write(fd_dec,outbuf,datasize);
}
packet_count -= rmctx.audio_pkt_cnt;
rmctx.audio_pkt_cnt = 0;
}
close_wav(fd_dec, &rmctx, &q);
close(fd);
return 0;
}

View file

@ -88,6 +88,8 @@ char* NEAACDECAPI NeAACDecGetErrorMessage(uint8_t errcode)
return err_msg[errcode];
}
/* rockbox: not used */
#if 0
uint32_t NEAACDECAPI NeAACDecGetCapabilities(void)
{
uint32_t cap = 0;
@ -113,6 +115,7 @@ uint32_t NEAACDECAPI NeAACDecGetCapabilities(void)
return cap;
}
#endif
NeAACDecHandle NEAACDECAPI NeAACDecOpen(void)
{

View file

@ -119,12 +119,13 @@ static uint8_t ObjectTypesTable[32] = {
};
/* Table 1.6.1 */
/* rockbox: not used
int8_t NEAACDECAPI NeAACDecAudioSpecificConfig(uint8_t *pBuffer,
uint32_t buffer_size,
mp4AudioSpecificConfig *mp4ASC)
{
return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL);
}
}*/
int8_t AudioSpecificConfig2(uint8_t *pBuffer,
uint32_t buffer_size,

View file

@ -34,9 +34,11 @@ extern "C" {
#include "decoder.h"
/* rockbox: not used
int8_t NEAACDECAPI NeAACDecAudioSpecificConfig(uint8_t *pBuffer,
uint32_t buffer_size,
mp4AudioSpecificConfig *mp4ASC);
*/
int8_t AudioSpecificConfig2(uint8_t *pBuffer,
uint32_t buffer_size,

View file

@ -37,8 +37,10 @@ static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_c
uint8_t *coef, real_t *a);
static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
int8_t order);
#ifdef LTP_DEC
static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
int8_t order);
#endif
#ifdef _MSC_VER
@ -129,6 +131,7 @@ void tns_decode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
}
}
#ifdef LTP_DEC
/* TNS encoding for one channel and frame */
void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
uint8_t object_type, real_t *spec, uint16_t frame_len)
@ -182,6 +185,7 @@ void tns_encode_frame(ic_stream *ics, tns_info *tns, uint8_t sr_index,
}
}
}
#endif
/* Decoder transmitted coefficients for one TNS filter */
static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
@ -268,6 +272,7 @@ static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *l
}
}
#ifdef LTP_DEC
static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
int8_t order)
{
@ -304,3 +309,4 @@ static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *l
spectrum += inc;
}
}
#endif

View file

@ -1,21 +0,0 @@
# Simple Makefile for standalone testing of decoder
OBJS=main.o decoder.o bitstream.o tables.o
CFLAGS=-O2 -Wall -DBUILD_STANDALONE
CC=gcc
# Uncomment the next line to build on a big-endian target:
#CFLAGS += -DBUILD_BIGENDIAN
all: test
main.o: main.c decoder.h
decoder.o: decoder.c bitstream.h golomb.h decoder.h
bitstream.o: bitstream.c
test: $(OBJS)
gcc -o test $(OBJS)
clean:
rm -f test $(OBJS) *~

View file

@ -1,322 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/* A test program for the Rockbox version of the ffmpeg FLAC decoder.
Compile using Makefile.test - run it as "./test file.flac" to decode the
FLAC file to the file "test.wav" in the current directory
This test program should support 16-bit and 24-bit mono and stereo files.
The resulting "test.wav" should have the same md5sum as a WAV file created
by the official FLAC decoder (it produces the same 44-byte canonical WAV
header.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "decoder.h"
static unsigned char wav_header[44]={
'R','I','F','F',// 0 - ChunkID
0,0,0,0, // 4 - ChunkSize (filesize-8)
'W','A','V','E',// 8 - Format
'f','m','t',' ',// 12 - SubChunkID
16,0,0,0, // 16 - SubChunk1ID // 16 for PCM
1,0, // 20 - AudioFormat (1=Uncompressed)
2,0, // 22 - NumChannels
0,0,0,0, // 24 - SampleRate in Hz
0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8)
4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8)
16,0, // 34 - BitsPerSample
'd','a','t','a',// 36 - Subchunk2ID
0,0,0,0 // 40 - Subchunk2Size
};
int open_wav(char* filename) {
int fd;
fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd >= 0) {
if (write(fd,wav_header,sizeof(wav_header)) < sizeof(wav_header)) {
fprintf(stderr,"[ERR} Failed to write wav header\n");
exit(1);
}
}
return(fd);
}
void close_wav(int fd, FLACContext* fc) {
int x;
int filesize;
int bytespersample;
bytespersample=fc->bps/8;
filesize=fc->totalsamples*bytespersample*fc->channels+44;
// ChunkSize
x=filesize-8;
wav_header[4]=(x&0xff);
wav_header[5]=(x&0xff00)>>8;
wav_header[6]=(x&0xff0000)>>16;
wav_header[7]=(x&0xff000000)>>24;
// Number of channels
wav_header[22]=fc->channels;
// Samplerate
wav_header[24]=fc->samplerate&0xff;
wav_header[25]=(fc->samplerate&0xff00)>>8;
wav_header[26]=(fc->samplerate&0xff0000)>>16;
wav_header[27]=(fc->samplerate&0xff000000)>>24;
// ByteRate
x=fc->samplerate*(fc->bps/8)*fc->channels;
wav_header[28]=(x&0xff);
wav_header[29]=(x&0xff00)>>8;
wav_header[30]=(x&0xff0000)>>16;
wav_header[31]=(x&0xff000000)>>24;
// BlockAlign
wav_header[32]=(fc->bps/8)*fc->channels;
// Bits per sample
wav_header[34]=fc->bps;
// Subchunk2Size
x=filesize-44;
wav_header[40]=(x&0xff);
wav_header[41]=(x&0xff00)>>8;
wav_header[42]=(x&0xff0000)>>16;
wav_header[43]=(x&0xff000000)>>24;
lseek(fd,0,SEEK_SET);
if (write(fd,wav_header,sizeof(wav_header)) < sizeof(wav_header)) {
fprintf(stderr,"[ERR} Failed to write wav header\n");
exit(1);
}
close(fd);
}
static void dump_headers(FLACContext *s)
{
fprintf(stderr," Blocksize: %d .. %d\n", s->min_blocksize,
s->max_blocksize);
fprintf(stderr," Framesize: %d .. %d\n", s->min_framesize,
s->max_framesize);
fprintf(stderr," Samplerate: %d\n", s->samplerate);
fprintf(stderr," Channels: %d\n", s->channels);
fprintf(stderr," Bits per sample: %d\n", s->bps);
fprintf(stderr," Metadata length: %d\n", s->metadatalength);
fprintf(stderr," Total Samples: %lu\n",s->totalsamples);
fprintf(stderr," Duration: %d ms\n",s->length);
fprintf(stderr," Bitrate: %d kbps\n",s->bitrate);
}
static bool flac_init(int fd, FLACContext* fc)
{
unsigned char buf[255];
struct stat statbuf;
bool found_streaminfo=false;
int endofmetadata=0;
int blocklength;
uint32_t* p;
uint32_t seekpoint_lo,seekpoint_hi;
uint32_t offset_lo,offset_hi;
int n;
if (lseek(fd, 0, SEEK_SET) < 0)
{
return false;
}
if (read(fd, buf, 4) < 4)
{
return false;
}
if (memcmp(buf,"fLaC",4) != 0)
{
return false;
}
fc->metadatalength = 4;
while (!endofmetadata) {
if (read(fd, buf, 4) < 4)
{
return false;
}
endofmetadata=(buf[0]&0x80);
blocklength = (buf[1] << 16) | (buf[2] << 8) | buf[3];
fc->metadatalength+=blocklength+4;
if ((buf[0] & 0x7f) == 0) /* 0 is the STREAMINFO block */
{
/* FIXME: Don't trust the value of blocklength */
if (read(fd, buf, blocklength) < 0)
{
return false;
}
fstat(fd,&statbuf);
fc->filesize = statbuf.st_size;
fc->min_blocksize = (buf[0] << 8) | buf[1];
fc->max_blocksize = (buf[2] << 8) | buf[3];
fc->min_framesize = (buf[4] << 16) | (buf[5] << 8) | buf[6];
fc->max_framesize = (buf[7] << 16) | (buf[8] << 8) | buf[9];
fc->samplerate = (buf[10] << 12) | (buf[11] << 4)
| ((buf[12] & 0xf0) >> 4);
fc->channels = ((buf[12]&0x0e)>>1) + 1;
fc->bps = (((buf[12]&0x01) << 4) | ((buf[13]&0xf0)>>4) ) + 1;
/* totalsamples is a 36-bit field, but we assume <= 32 bits are
used */
fc->totalsamples = (buf[14] << 24) | (buf[15] << 16)
| (buf[16] << 8) | buf[17];
/* Calculate track length (in ms) and estimate the bitrate
(in kbit/s) */
fc->length = (fc->totalsamples / fc->samplerate) * 1000;
found_streaminfo=true;
} else if ((buf[0] & 0x7f) == 3) { /* 3 is the SEEKTABLE block */
fprintf(stderr,"Seektable length = %d bytes\n",blocklength);
while (blocklength >= 18) {
n=read(fd,buf,18);
if (n < 18) return false;
blocklength-=n;
p=(uint32_t*)buf;
seekpoint_hi=betoh32(*(p++));
seekpoint_lo=betoh32(*(p++));
offset_hi=betoh32(*(p++));
offset_lo=betoh32(*(p++));
if ((seekpoint_hi != 0xffffffff) && (seekpoint_lo != 0xffffffff)) {
fprintf(stderr,"Seekpoint: %u, Offset=%u\n",seekpoint_lo,offset_lo);
}
}
lseek(fd, blocklength, SEEK_CUR);
} else {
/* Skip to next metadata block */
if (lseek(fd, blocklength, SEEK_CUR) < 0)
{
return false;
}
}
}
if (found_streaminfo) {
fc->bitrate = ((fc->filesize-fc->metadatalength) * 8) / fc->length;
return true;
} else {
return false;
}
}
/* Dummy function needed to pass to flac_decode_frame() */
void yield() {
}
int main(int argc, char* argv[]) {
FLACContext fc;
int fd,fdout;
int n;
int i;
int bytesleft;
int consumed;
unsigned char buf[MAX_FRAMESIZE]; /* The input buffer */
/* The output buffers containing the decoded samples (channels 0 and 1) */
int32_t decoded0[MAX_BLOCKSIZE];
int32_t decoded1[MAX_BLOCKSIZE];
/* For testing */
int8_t wavbuf[MAX_CHANNELS*MAX_BLOCKSIZE*3];
int8_t* p;
int scale;
fd=open(argv[1],O_RDONLY);
if (fd < 0) {
fprintf(stderr,"Can not parse %s\n",argv[1]);
return(1);
}
/* Read the metadata and position the file pointer at the start of the
first audio frame */
flac_init(fd,&fc);
dump_headers(&fc);
fdout=open_wav("test.wav");
bytesleft=read(fd,buf,sizeof(buf));
while (bytesleft) {
if(flac_decode_frame(&fc,decoded0,decoded1,buf,bytesleft,yield) < 0) {
fprintf(stderr,"DECODE ERROR, ABORTING\n");
break;
}
consumed=fc.gb.index/8;
scale=FLAC_OUTPUT_DEPTH-fc.bps;
p=wavbuf;
for (i=0;i<fc.blocksize;i++) {
/* Left sample */
decoded0[i]=decoded0[i]>>scale;
*(p++)=decoded0[i]&0xff;
*(p++)=(decoded0[i]&0xff00)>>8;
if (fc.bps==24) *(p++)=(decoded0[i]&0xff0000)>>16;
if (fc.channels==2) {
/* Right sample */
decoded1[i]=decoded1[i]>>scale;
*(p++)=decoded1[i]&0xff;
*(p++)=(decoded1[i]&0xff00)>>8;
if (fc.bps==24) *(p++)=(decoded1[i]&0xff0000)>>16;
}
}
n = fc.blocksize*fc.channels*(fc.bps/8);
if (write(fdout,wavbuf,n) < n) {
fprintf(stderr,"[ERR] Write failed\n");
exit(1);
}
memmove(buf,&buf[consumed],bytesleft-consumed);
bytesleft-=consumed;
n=read(fd,&buf[bytesleft],sizeof(buf)-bytesleft);
if (n > 0) {
bytesleft+=n;
}
}
close_wav(fdout,&fc);
close(fd);
return(0);
}

View file

@ -67,16 +67,6 @@ uint32_t stream_read_uint32(stream_t *stream)
return v;
}
int16_t stream_read_int16(stream_t *stream)
{
int16_t v;
stream_read(stream, 2, &v);
#ifdef ROCKBOX_LITTLE_ENDIAN
_Swap16(v);
#endif
return v;
}
uint16_t stream_read_uint16(stream_t *stream)
{
uint16_t v;
@ -87,13 +77,6 @@ uint16_t stream_read_uint16(stream_t *stream)
return v;
}
int8_t stream_read_int8(stream_t *stream)
{
int8_t v;
stream_read(stream, 1, &v);
return v;
}
uint8_t stream_read_uint8(stream_t *stream)
{
uint8_t v;

View file

@ -117,10 +117,8 @@ int32_t stream_tell(stream_t *stream);
int32_t stream_read_int32(stream_t *stream);
uint32_t stream_read_uint32(stream_t *stream);
int16_t stream_read_int16(stream_t *stream);
uint16_t stream_read_uint16(stream_t *stream);
int8_t stream_read_int8(stream_t *stream);
uint8_t stream_read_uint8(stream_t *stream);
void stream_skip(stream_t *stream, size_t skip);

View file

@ -45,7 +45,7 @@
#define MAX_CHARS_PER_FRAME (2000/BYTES_PER_CHAR)
#endif
#ifndef ROCKBOX_VOICE_CODEC
#ifdef ROCKBOX_VOICE_ENCODER
void speex_bits_init(SpeexBits *bits)
{
bits->chars = (char*)speex_alloc(MAX_CHARS_PER_FRAME);

View file

@ -216,26 +216,6 @@ static inline void vect_copy(ogg_int32_t *x, const ogg_int32_t *y, int n)
#endif
#endif
/* not used anymore */
/*
#ifndef _V_CLIP_MATH
#define _V_CLIP_MATH
static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
int tmp;
asm volatile("subs %1, %0, #32768\n\t"
"movpl %0, #0x7f00\n\t"
"orrpl %0, %0, #0xff\n"
"adds %1, %0, #32768\n\t"
"movmi %0, #0x8000"
: "+r"(x),"=r"(tmp)
:
: "cc");
return(x);
}
#endif
*/
#ifndef _V_LSP_MATH_ASM
#define _V_LSP_MATH_ASM

View file

@ -250,16 +250,4 @@ void vect_mult_bw(ogg_int32_t *data, LOOKUP_T *window, int n)
#endif
#endif
/* not used anymore */
/*
#ifndef _V_CLIP_MATH
#define _V_CLIP_MATH
static inline ogg_int32_t CLIP_TO_15(register ogg_int32_t x) {
register ogg_int32_t hi=32767, lo=-32768;
return (x>=hi ? hi : (x<=lo ? lo : x));
}
#endif
*/
#endif

View file

@ -203,20 +203,6 @@ static inline void vect_copy(ogg_int32_t *x, const ogg_int32_t *y, int n)
#endif
#endif
/* not used anymore */
/*
#ifndef _V_CLIP_MATH
#define _V_CLIP_MATH
static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
int ret=x;
ret-= ((x<=32767)-1)&(x-32767);
ret-= ((x>=-32768)-1)&(x+32768);
return(ret);
}
#endif
*/
static inline ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap,
ogg_int32_t b,ogg_int32_t bp,

View file

@ -227,6 +227,7 @@ static int done_buffer_read(void) {
/************************* decoder functions ****************************/
/* rockbox: not used
const char *get_error_str (int error) {
switch (error) {
case NO_ERROR: return "No errors found";
@ -237,7 +238,7 @@ const char *get_error_str (int error) {
case MEMORY_ERROR: return "Insufficient memory available";
default: return "Unknown error code";
}
}
} */
int set_tta_info (tta_info *info)
{

View file

@ -24,7 +24,9 @@
#include "libfaad/common.h"
#include "libfaad/structs.h"
#include "libfaad/decoder.h"
/* rockbox: not used
#include "libfaad/output.h"
*/
CODEC_HEADER