forked from len0rd/rockbox
Cleaned up code a bit, removed all rb references.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6825 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
54c1c667de
commit
10426dbe22
1 changed files with 103 additions and 115 deletions
|
|
@ -25,8 +25,6 @@
|
||||||
#include "mp3data.h"
|
#include "mp3data.h"
|
||||||
#include "lib/codeclib.h"
|
#include "lib/codeclib.h"
|
||||||
|
|
||||||
static struct codec_api* rb;
|
|
||||||
|
|
||||||
struct mad_stream Stream IDATA_ATTR;
|
struct mad_stream Stream IDATA_ATTR;
|
||||||
struct mad_frame Frame IDATA_ATTR;
|
struct mad_frame Frame IDATA_ATTR;
|
||||||
struct mad_synth Synth IDATA_ATTR;
|
struct mad_synth Synth IDATA_ATTR;
|
||||||
|
|
@ -65,8 +63,7 @@ unsigned long prng(unsigned long state)
|
||||||
* NAME: dither()
|
* NAME: dither()
|
||||||
* DESCRIPTION: dither and scale sample
|
* DESCRIPTION: dither and scale sample
|
||||||
*/
|
*/
|
||||||
static __inline
|
inline int dither(mad_fixed_t sample, struct dither *dither)
|
||||||
signed int dither(mad_fixed_t sample, struct dither *dither)
|
|
||||||
{
|
{
|
||||||
unsigned int scalebits;
|
unsigned int scalebits;
|
||||||
mad_fixed_t output, mask, random;
|
mad_fixed_t output, mask, random;
|
||||||
|
|
@ -80,7 +77,7 @@ signed int dither(mad_fixed_t sample, struct dither *dither)
|
||||||
sample += dither->error[0] - dither->error[1] + dither->error[2];
|
sample += dither->error[0] - dither->error[1] + dither->error[2];
|
||||||
|
|
||||||
dither->error[2] = dither->error[1];
|
dither->error[2] = dither->error[1];
|
||||||
dither->error[1] = dither->error[0] / 2;
|
dither->error[1] = dither->error[0]/2;
|
||||||
|
|
||||||
/* bias */
|
/* bias */
|
||||||
output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
|
output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
|
||||||
|
|
@ -100,8 +97,7 @@ signed int dither(mad_fixed_t sample, struct dither *dither)
|
||||||
|
|
||||||
if (sample > MAX)
|
if (sample > MAX)
|
||||||
sample = MAX;
|
sample = MAX;
|
||||||
}
|
} else if (output < MIN) {
|
||||||
else if (output < MIN) {
|
|
||||||
output = MIN;
|
output = MIN;
|
||||||
|
|
||||||
if (sample < MIN)
|
if (sample < MIN)
|
||||||
|
|
@ -118,8 +114,7 @@ signed int dither(mad_fixed_t sample, struct dither *dither)
|
||||||
return output >> scalebits;
|
return output >> scalebits;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline
|
inline int detect_silence(mad_fixed_t sample)
|
||||||
signed int detect_silence(mad_fixed_t sample)
|
|
||||||
{
|
{
|
||||||
unsigned int scalebits;
|
unsigned int scalebits;
|
||||||
mad_fixed_t output, mask;
|
mad_fixed_t output, mask;
|
||||||
|
|
@ -141,8 +136,7 @@ signed int detect_silence(mad_fixed_t sample)
|
||||||
|
|
||||||
if (sample > MAX)
|
if (sample > MAX)
|
||||||
sample = MAX;
|
sample = MAX;
|
||||||
}
|
} else if (output < MIN) {
|
||||||
else if (output < MIN) {
|
|
||||||
output = MIN;
|
output = MIN;
|
||||||
|
|
||||||
if (sample < MIN)
|
if (sample < MIN)
|
||||||
|
|
@ -160,15 +154,14 @@ signed int detect_silence(mad_fixed_t sample)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#define SHRT_MAX 32767
|
|
||||||
|
|
||||||
#define INPUT_CHUNK_SIZE 8192
|
#define INPUT_CHUNK_SIZE 8192
|
||||||
#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
|
#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
|
||||||
|
|
||||||
unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
|
unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
|
||||||
unsigned char *OutputPtr;
|
unsigned char *OutputPtr;
|
||||||
unsigned char *GuardPtr=NULL;
|
unsigned char *GuardPtr = NULL;
|
||||||
const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
|
const unsigned char *OutputBufferEnd = OutputBuffer + OUTPUT_BUFFER_SIZE;
|
||||||
long resampled_data[2][5000]; /* enough to cope with 11khz upsampling */
|
long resampled_data[2][5000]; /* enough to cope with 11khz upsampling */
|
||||||
|
|
||||||
mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
|
mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
|
||||||
|
|
@ -261,7 +254,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
{
|
{
|
||||||
struct codec_api *ci = api;
|
struct codec_api *ci = api;
|
||||||
struct mp3info *info;
|
struct mp3info *info;
|
||||||
int Status=0;
|
int Status = 0;
|
||||||
size_t size;
|
size_t size;
|
||||||
int file_end;
|
int file_end;
|
||||||
unsigned short Sample;
|
unsigned short Sample;
|
||||||
|
|
@ -281,10 +274,9 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
/* Generic codec inititialisation */
|
/* Generic codec inititialisation */
|
||||||
|
|
||||||
TEST_CODEC_API(api);
|
TEST_CODEC_API(api);
|
||||||
rb = api;
|
|
||||||
|
|
||||||
#ifdef USE_IRAM
|
#ifdef USE_IRAM
|
||||||
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
ci->memcpy(iramstart, iramcopy, iramend - iramstart);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This function sets up the buffers and reads the file into RAM */
|
/* This function sets up the buffers and reads the file into RAM */
|
||||||
|
|
@ -298,10 +290,10 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
|
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
|
||||||
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
|
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
|
||||||
|
|
||||||
memset(&Stream, 0, sizeof(struct mad_stream));
|
ci->memset(&Stream, 0, sizeof(struct mad_stream));
|
||||||
memset(&Frame, 0, sizeof(struct mad_frame));
|
ci->memset(&Frame, 0, sizeof(struct mad_frame));
|
||||||
memset(&Synth, 0, sizeof(struct mad_synth));
|
ci->memset(&Synth, 0, sizeof(struct mad_synth));
|
||||||
memset(&Timer, 0, sizeof(mad_timer_t));
|
ci->memset(&Timer, 0, sizeof(mad_timer_t));
|
||||||
|
|
||||||
mad_stream_init(&Stream);
|
mad_stream_init(&Stream);
|
||||||
mad_frame_init(&Frame);
|
mad_frame_init(&Frame);
|
||||||
|
|
@ -319,9 +311,9 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
|
|
||||||
#ifdef DEBUG_GAPLESS
|
#ifdef DEBUG_GAPLESS
|
||||||
if (first)
|
if (first)
|
||||||
fd = rb->open("/first.pcm", O_WRONLY | O_CREAT);
|
fd = ci->open("/first.pcm", O_WRONLY | O_CREAT);
|
||||||
else
|
else
|
||||||
fd = rb->open("/second.pcm", O_WRONLY | O_CREAT);
|
fd = ci->open("/second.pcm", O_WRONLY | O_CREAT);
|
||||||
first = false;
|
first = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -331,7 +323,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
OutputPtr = OutputBuffer;
|
OutputPtr = OutputBuffer;
|
||||||
|
|
||||||
while (!*ci->taginfo_ready)
|
while (!*ci->taginfo_ready)
|
||||||
rb->yield();
|
ci->yield();
|
||||||
|
|
||||||
ci->request_buffer(&size, ci->id3->first_frame_offset);
|
ci->request_buffer(&size, ci->id3->first_frame_offset);
|
||||||
ci->advance_buffer(size);
|
ci->advance_buffer(size);
|
||||||
|
|
@ -367,7 +359,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
lr.delta = rr.delta = ci->id3->frequency*65536/44100;
|
lr.delta = rr.delta = ci->id3->frequency*65536/44100;
|
||||||
/* This is the decoding loop. */
|
/* This is the decoding loop. */
|
||||||
while (1) {
|
while (1) {
|
||||||
rb->yield();
|
ci->yield();
|
||||||
if (ci->stop_codec || ci->reload_codec) {
|
if (ci->stop_codec || ci->reload_codec) {
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +393,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
if(mad_frame_decode(&Frame,&Stream))
|
if(mad_frame_decode(&Frame,&Stream))
|
||||||
{
|
{
|
||||||
if (Stream.error == MAD_FLAG_INCOMPLETE || Stream.error == MAD_ERROR_BUFLEN) {
|
if (Stream.error == MAD_FLAG_INCOMPLETE || Stream.error == MAD_ERROR_BUFLEN) {
|
||||||
// rb->splash(HZ*1, true, "Incomplete");
|
// ci->splash(HZ*1, true, "Incomplete");
|
||||||
/* This makes the codec to support partially corrupted files too. */
|
/* This makes the codec to support partially corrupted files too. */
|
||||||
if (file_end == 30)
|
if (file_end == 30)
|
||||||
break ;
|
break ;
|
||||||
|
|
@ -434,10 +426,6 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
/* ?? Do we need the timer module? */
|
/* ?? Do we need the timer module? */
|
||||||
// mad_timer_add(&Timer,Frame.header.duration);
|
// mad_timer_add(&Timer,Frame.header.duration);
|
||||||
|
|
||||||
/* DAVE: This can be used to attenuate the audio */
|
|
||||||
// if(DoFilter)
|
|
||||||
// ApplyFilter(&Frame);
|
|
||||||
|
|
||||||
mad_synth_frame(&Synth,&Frame);
|
mad_synth_frame(&Synth,&Frame);
|
||||||
|
|
||||||
//if (!first_frame) {
|
//if (!first_frame) {
|
||||||
|
|
@ -452,7 +440,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
length = resample((long *)&Synth.pcm.samples[0][start_skip], resampled_data[0], Synth.pcm.length, &lr);
|
length = resample((long *)&Synth.pcm.samples[0][start_skip], resampled_data[0], Synth.pcm.length, &lr);
|
||||||
if (MAD_NCHANNELS(&Frame.header) == 2)
|
if (MAD_NCHANNELS(&Frame.header) == 2)
|
||||||
resample((long *)&Synth.pcm.samples[1][start_skip], resampled_data[1], Synth.pcm.length, &rr);
|
resample((long *)&Synth.pcm.samples[1][start_skip], resampled_data[1], Synth.pcm.length, &rr);
|
||||||
for (i = 0;i<length;i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
start_skip = 0; /* not very elegant, and might want to keep this value */
|
start_skip = 0; /* not very elegant, and might want to keep this value */
|
||||||
samplesdone++;
|
samplesdone++;
|
||||||
|
|
@ -467,42 +455,42 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/* Left channel */
|
/* Left channel */
|
||||||
Sample=scale(resampled_data[0][i],&d0);
|
Sample = scale(resampled_data[0][i], &d0);
|
||||||
*(OutputPtr++)=Sample>>8;
|
*(OutputPtr++) = Sample >> 8;
|
||||||
*(OutputPtr++)=Sample&0xff;
|
*(OutputPtr++) = Sample & 0xff;
|
||||||
|
|
||||||
/* Right channel. If the decoded stream is monophonic then
|
/* Right channel. If the decoded stream is monophonic then
|
||||||
* the right output channel is the same as the left one.
|
* the right output channel is the same as the left one.
|
||||||
*/
|
*/
|
||||||
if(MAD_NCHANNELS(&Frame.header)==2)
|
if (MAD_NCHANNELS(&Frame.header) == 2)
|
||||||
Sample=scale(resampled_data[1][i],&d1);
|
Sample = scale(resampled_data[1][i], &d1);
|
||||||
*(OutputPtr++)=Sample>>8;
|
*(OutputPtr++) = Sample >> 8;
|
||||||
*(OutputPtr++)=Sample&0xff;
|
*(OutputPtr++) = Sample & 0xff;
|
||||||
|
|
||||||
samplecount--;
|
samplecount--;
|
||||||
if (samplecount == 0) {
|
if (samplecount == 0) {
|
||||||
#ifdef DEBUG_GAPLESS
|
#ifdef DEBUG_GAPLESS
|
||||||
rb->write(fd, OutputBuffer, (int)OutputPtr-(int)OutputBuffer);
|
ci->write(fd, OutputBuffer, (int)OutputPtr - (int)OutputBuffer);
|
||||||
#endif
|
#endif
|
||||||
while (!ci->audiobuffer_insert(OutputBuffer, (int)OutputPtr-(int)OutputBuffer))
|
while (!ci->audiobuffer_insert(OutputBuffer, (int)OutputPtr - (int)OutputBuffer))
|
||||||
rb->yield();
|
ci->yield();
|
||||||
goto song_end;
|
goto song_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yieldcounter++ == 200) {
|
if (yieldcounter++ == 200) {
|
||||||
rb->yield();
|
ci->yield();
|
||||||
yieldcounter = 0;
|
yieldcounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flush the buffer if it is full. */
|
/* Flush the buffer if it is full. */
|
||||||
if(OutputPtr==OutputBufferEnd)
|
if (OutputPtr == OutputBufferEnd)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_GAPLESS
|
#ifdef DEBUG_GAPLESS
|
||||||
rb->write(fd, OutputBuffer, OUTPUT_BUFFER_SIZE);
|
ci->write(fd, OutputBuffer, OUTPUT_BUFFER_SIZE);
|
||||||
#endif
|
#endif
|
||||||
while (!ci->audiobuffer_insert(OutputBuffer, OUTPUT_BUFFER_SIZE))
|
while (!ci->audiobuffer_insert(OutputBuffer, OUTPUT_BUFFER_SIZE))
|
||||||
rb->yield();
|
ci->yield();
|
||||||
OutputPtr=OutputBuffer;
|
OutputPtr = OutputBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ci->set_elapsed(samplesdone / (ci->id3->frequency/1000));
|
ci->set_elapsed(samplesdone / (ci->id3->frequency/1000));
|
||||||
|
|
@ -510,7 +498,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
|
|
||||||
song_end:
|
song_end:
|
||||||
#ifdef DEBUG_GAPLESS
|
#ifdef DEBUG_GAPLESS
|
||||||
rb->close(fd);
|
ci->close(fd);
|
||||||
#endif
|
#endif
|
||||||
Stream.error = 0;
|
Stream.error = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue