1
0
Fork 0
forked from len0rd/rockbox

moved and renamed the codecs, gave the codecs a new extension (.codec),

unified to a single codec-only API, made a new codeclib, disabled the building
of the *2wav plugins


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6812 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2005-06-22 19:41:30 +00:00
parent b7aaa641b8
commit 1dd672fe32
29 changed files with 1709 additions and 937 deletions

View file

@ -1,7 +0,0 @@
codecvorbis.elf
codecmpa.elf
codecflac.elf
codecwav.elf
codeca52.elf
codecmpc.elf
codecwavpack.elf

View file

@ -22,7 +22,6 @@ endif
LDS := plugin.lds
LINKFILE := $(OBJDIR)/pluginlink.lds
LINKCODEC := $(OBJDIR)/codeclink.lds
DEPFILE = $(OBJDIR)/dep-plugins
# This sets up 'SRC' based on the files mentioned in SOURCES
@ -55,13 +54,7 @@ ifndef SIMVER
$(OBJDIR)/%.elf: $(OBJDIR)/%.o $(LINKFILE) $(LINKCODEC) $(BUILDDIR)/libplugin.a
$(SILENT)(file=`basename $@`; \
echo "LD $$file"; \
match=`grep $$file CODECS`; \
if test -z "$$match"; then \
LINKWITH=$(LINKFILE); \
else \
LINKWITH=$(LINKCODEC); \
fi; \
$(CC) $(GCCOPTS) -O -nostdlib -o $@ $< -L$(BUILDDIR) $(CODECLIBS) -lplugin -lgcc -T$$LINKWITH -Wl,-Map,$(OBJDIR)/$*.map)
$(CC) $(GCCOPTS) -O -nostdlib -o $@ $< -L$(BUILDDIR) $(CODECLIBS) -lplugin -lgcc -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/$*.map)
$(OBJDIR)/%.rock : $(OBJDIR)/%.elf
@echo "OBJCOPY "`basename $@`
@ -108,7 +101,7 @@ endif # end of simulator section
include $(TOOLSDIR)/make.inc
$(BUILDDIR)/libplugin.a:
@echo "MAKE in lib"
@echo "MAKE in plugin/lib"
@mkdir -p $(OBJDIR)/lib
@$(MAKE) -C lib OBJDIR=$(OBJDIR)/lib
@ -116,10 +109,6 @@ $(LINKFILE): $(LDS)
@echo "build $@"
@cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P - >$@
$(LINKCODEC): $(LDS)
@echo "build $@"
@cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) -DCODEC $(INCLUDES) $(TARGET) $(DEFINES) -E -P - >$@
$(SUBDIRS):
@echo "MAKE in $@"
@mkdir -p $(OBJDIR)/$@

View file

@ -67,22 +67,15 @@ alpine_cdc.c
#endif
#if CONFIG_HWCODEC == MASNONE /* software codec platforms */
#if 0
mpa2wav.c
a52towav.c
flac2wav.c
vorbis2wav.c
#ifdef IRIVER_H100
codecvorbis.c
codecmpa.c
codecflac.c
codecwav.c
codeca52.c
codecmpc.c
codecwavpack.c
#endif
wv2wav.c
mpc2wav.c
midi2wav.c
#endif
iriverify.c
#else
splitedit.c

View file

@ -1,210 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include <inttypes.h> /* Needed by a52.h */
#include <codecs/liba52/config-a52.h>
#include <codecs/liba52/a52.h>
#include "playback.h"
#include "lib/codeclib.h"
#define BUFFER_SIZE 4096
struct plugin_api* rb;
struct codec_api* ci;
static float gain = 1;
static a52_state_t * state;
unsigned long samplesdone;
unsigned long frequency;
/* Two buffers used outside liba52 */
static uint8_t buf[3840] IDATA_ATTR;
static int16_t int16_samples[256*2] IDATA_ATTR;
static inline int16_t convert (int32_t i)
{
i >>= 15;
return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i);
}
void output_audio(sample_t* samples,int flags) {
int i;
flags &= A52_CHANNEL_MASK | A52_LFE;
/* We may need to check the output format in flags - I'm not sure... */
for (i = 0; i < 256; i++) {
int16_samples[2*i] = convert (samples[i]);
int16_samples[2*i+1] = convert (samples[i+256]);
}
rb->yield();
while(!ci->audiobuffer_insert((unsigned char*)int16_samples,256*2*2))
rb->yield();
}
void a52_decode_data (uint8_t * start, uint8_t * end)
{
static uint8_t * bufptr = buf;
static uint8_t * bufpos = buf + 7;
/*
* sample_rate and flags are static because this routine could
* exit between the a52_syncinfo() and the ao_setup(), and we want
* to have the same values when we get back !
*/
static int sample_rate;
static int flags;
int bit_rate;
int len;
while (1) {
len = end - start;
if (!len)
break;
if (len > bufpos - bufptr)
len = bufpos - bufptr;
memcpy (bufptr, start, len);
bufptr += len;
start += len;
if (bufptr == bufpos) {
if (bufpos == buf + 7) {
int length;
length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
if (!length) {
DEBUGF("skip\n");
for (bufptr = buf; bufptr < buf + 6; bufptr++)
bufptr[0] = bufptr[1];
continue;
}
bufpos = buf + length;
} else {
// The following two defaults are taken from audio_out_oss.c:
level_t level;
sample_t bias;
int i;
/* This is the configuration for the downmixing: */
flags=A52_STEREO|A52_ADJUST_LEVEL|A52_LFE;
level=(1 << 26);
bias=0;
level = (level_t) (level * gain);
if (a52_frame (state, buf, &flags, &level, bias)) {
goto error;
}
// file_info->frames_decoded++;
// /* We assume this never changes */
// file_info->samplerate=sample_rate;
frequency=sample_rate;
// An A52 frame consists of 6 blocks of 256 samples
// So we decode and output them one block at a time
for (i = 0; i < 6; i++) {
if (a52_block (state)) {
goto error;
}
output_audio(a52_samples (state),flags);
samplesdone+=256;
}
ci->set_elapsed(samplesdone/(frequency/1000));
bufptr = buf;
bufpos = buf + 7;
continue;
error:
//logf("Error decoding A52 stream\n");
bufptr = buf;
bufpos = buf + 7;
}
}
}
}
#ifndef SIMULATOR
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
size_t n;
unsigned char* filebuf;
/* Generic plugin initialisation */
TEST_PLUGIN_API(api);
rb = api;
ci = (struct codec_api*)parm;
#ifndef SIMULATOR
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
next_track:
if (codec_init(api, ci)) {
return PLUGIN_ERROR;
}
/* Intialise the A52 decoder and check for success */
state = a52_init (0); // Parameter is "accel"
/* The main decoding loop */
samplesdone=0;
while (1) {
if (ci->stop_codec || ci->reload_codec) {
break;
}
filebuf=ci->request_buffer(&n,BUFFER_SIZE);
if (n==0) { /* End of Stream */
break;
}
a52_decode_data(filebuf,filebuf+n);
ci->advance_buffer(n);
}
if (ci->request_next_track())
goto next_track;
//NOT NEEDED??: a52_free (state);
return PLUGIN_OK;
}

View file

@ -1,248 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Björn Stenberg
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include <codecs/libFLAC/include/FLAC/seekable_stream_decoder.h>
#include "playback.h"
#include "lib/codeclib.h"
#define FLAC_MAX_SUPPORTED_BLOCKSIZE 4608
#define FLAC_MAX_SUPPORTED_CHANNELS 2
static struct plugin_api* rb;
static uint32_t samplesdone;
/* Called when the FLAC decoder needs some FLAC data to decode */
FLAC__SeekableStreamDecoderReadStatus flac_read_handler(const FLAC__SeekableStreamDecoder *dec,
FLAC__byte buffer[], unsigned *bytes, void *data)
{ struct codec_api* ci = (struct codec_api*)data;
(void)dec;
*bytes=(unsigned)(ci->read_filebuf(buffer,*bytes));
if (*bytes==0) {
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
} else {
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
}
static unsigned char pcmbuf[FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS*2] IDATA_ATTR;
/* Called when the FLAC decoder has some decoded PCM data to write */
FLAC__StreamDecoderWriteStatus flac_write_handler(const FLAC__SeekableStreamDecoder *dec,
const FLAC__Frame *frame,
const FLAC__int32 * const buf[],
void *data)
{
struct codec_api* ci = (struct codec_api*)data;
(void)dec;
unsigned int c_samp, c_chan, d_samp;
uint32_t data_size = frame->header.blocksize * frame->header.channels * 2; /* Assume 16-bit words */
uint32_t samples = frame->header.blocksize;
int yieldcounter = 0;
if (samples*frame->header.channels > (FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS)) {
// ERROR!!!
DEBUGF("ERROR: samples*frame->header.channels=%d\n",samples*frame->header.channels);
return(FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE);
}
(void)dec;
for(c_samp = d_samp = 0; c_samp < samples; c_samp++) {
for(c_chan = 0; c_chan < frame->header.channels; c_chan++, d_samp++) {
pcmbuf[d_samp*2] = (buf[c_chan][c_samp]&0xff00)>>8;
pcmbuf[(d_samp*2)+1] = buf[c_chan][c_samp]&0xff;
if (yieldcounter++ == 100) {
rb->yield();
yieldcounter = 0;
}
}
}
samplesdone+=samples;
ci->set_elapsed(samplesdone/(ci->id3->frequency/1000));
rb->yield();
while (!ci->audiobuffer_insert(pcmbuf, data_size))
rb->yield();
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
void flac_metadata_handler(const FLAC__SeekableStreamDecoder *dec,
const FLAC__StreamMetadata *meta, void *data)
{
/* Ignore metadata for now... */
(void)dec;
(void)meta;
(void)data;
}
void flac_error_handler(const FLAC__SeekableStreamDecoder *dec,
FLAC__StreamDecoderErrorStatus status, void *data)
{
(void)dec;
(void)status;
(void)data;
}
FLAC__SeekableStreamDecoderSeekStatus flac_seek_handler (const FLAC__SeekableStreamDecoder *decoder,
FLAC__uint64 absolute_byte_offset,
void *client_data)
{
(void)decoder;
struct codec_api* ci = (struct codec_api*)client_data;
if (ci->seek_buffer(absolute_byte_offset)) {
return(FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK);
} else {
return(FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR);
}
}
FLAC__SeekableStreamDecoderTellStatus flac_tell_handler (const FLAC__SeekableStreamDecoder *decoder,
FLAC__uint64 *absolute_byte_offset, void *client_data)
{
struct codec_api* ci = (struct codec_api*)client_data;
(void)decoder;
*absolute_byte_offset=ci->curpos;
return(FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK);
}
FLAC__SeekableStreamDecoderLengthStatus flac_length_handler (const FLAC__SeekableStreamDecoder *decoder,
FLAC__uint64 *stream_length, void *client_data)
{
struct codec_api* ci = (struct codec_api*)client_data;
(void)decoder;
*stream_length=ci->filesize;
return(FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK);
}
FLAC__bool flac_eof_handler (const FLAC__SeekableStreamDecoder *decoder,
void *client_data)
{
struct codec_api* ci = (struct codec_api*)client_data;
(void)decoder;
if (ci->curpos >= ci->filesize) {
return(true);
} else {
return(false);
}
}
#ifndef SIMULATOR
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
struct codec_api* ci = (struct codec_api*)parm;
FLAC__SeekableStreamDecoder* flacDecoder;
/* Generic plugin initialisation */
TEST_PLUGIN_API(api);
/* if you are using a global api pointer, don't forget to copy it!
otherwise you will get lovely "I04: IllInstr" errors... :-) */
rb = api;
#ifndef SIMULATOR
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10));
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
next_track:
if (codec_init(api, ci)) {
return PLUGIN_ERROR;
}
/* Create a decoder instance */
flacDecoder=FLAC__seekable_stream_decoder_new();
/* Set up the decoder and the callback functions - this must be done before init */
/* The following are required for stream_decoder and higher */
FLAC__seekable_stream_decoder_set_client_data(flacDecoder,ci);
FLAC__seekable_stream_decoder_set_write_callback(flacDecoder, flac_write_handler);
FLAC__seekable_stream_decoder_set_read_callback(flacDecoder, flac_read_handler);
FLAC__seekable_stream_decoder_set_metadata_callback(flacDecoder, flac_metadata_handler);
FLAC__seekable_stream_decoder_set_error_callback(flacDecoder, flac_error_handler);
FLAC__seekable_stream_decoder_set_metadata_respond(flacDecoder, FLAC__METADATA_TYPE_STREAMINFO);
/* The following are only for the seekable_stream_decoder */
FLAC__seekable_stream_decoder_set_seek_callback(flacDecoder, flac_seek_handler);
FLAC__seekable_stream_decoder_set_tell_callback(flacDecoder, flac_tell_handler);
FLAC__seekable_stream_decoder_set_length_callback(flacDecoder, flac_length_handler);
FLAC__seekable_stream_decoder_set_eof_callback(flacDecoder, flac_eof_handler);
/* QUESTION: What do we do when the init fails? */
if (FLAC__seekable_stream_decoder_init(flacDecoder)) {
return PLUGIN_ERROR;
}
/* The first thing to do is to parse the metadata */
FLAC__seekable_stream_decoder_process_until_end_of_metadata(flacDecoder);
samplesdone=0;
ci->set_elapsed(0);
/* The main decoder loop */
while (FLAC__seekable_stream_decoder_get_state(flacDecoder)!=FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM) {
rb->yield();
if (ci->stop_codec || ci->reload_codec) {
break;
}
if (ci->seek_time) {
int sample_loc;
sample_loc = ci->seek_time/1000 * ci->id3->frequency;
if (FLAC__seekable_stream_decoder_seek_absolute(flacDecoder,sample_loc)) {
samplesdone=sample_loc;
ci->set_elapsed(samplesdone/(ci->id3->frequency/1000));
}
ci->seek_time = 0;
}
FLAC__seekable_stream_decoder_process_single(flacDecoder);
}
/* Flush the libFLAC buffers */
FLAC__seekable_stream_decoder_finish(flacDecoder);
if (ci->request_next_track())
goto next_track;
return PLUGIN_OK;
}

View file

@ -1,520 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include <codecs/libmad/mad.h>
#include "playback.h"
#include "mp3data.h"
#include "lib/codeclib.h"
static struct plugin_api* rb;
struct mad_stream Stream IDATA_ATTR;
struct mad_frame Frame IDATA_ATTR;
struct mad_synth Synth IDATA_ATTR;
mad_timer_t Timer;
struct dither d0, d1;
/* The following function is used inside libmad - let's hope it's never
called.
*/
void abort(void) {
}
/* The "dither" code to convert the 24-bit samples produced by libmad was
taken from the coolplayer project - coolplayer.sourceforge.net */
struct dither {
mad_fixed_t error[3];
mad_fixed_t random;
};
# define SAMPLE_DEPTH 16
# define scale(x, y) dither((x), (y))
/*
* NAME: prng()
* DESCRIPTION: 32-bit pseudo-random number generator
*/
static __inline
unsigned long prng(unsigned long state)
{
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
}
/*
* NAME: dither()
* DESCRIPTION: dither and scale sample
*/
static __inline
signed int dither(mad_fixed_t sample, struct dither *dither)
{
unsigned int scalebits;
mad_fixed_t output, mask, random;
enum {
MIN = -MAD_F_ONE,
MAX = MAD_F_ONE - 1
};
/* noise shape */
sample += dither->error[0] - dither->error[1] + dither->error[2];
dither->error[2] = dither->error[1];
dither->error[1] = dither->error[0] / 2;
/* bias */
output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
scalebits = MAD_F_FRACBITS + 1 - SAMPLE_DEPTH;
mask = (1L << scalebits) - 1;
/* dither */
random = prng(dither->random);
output += (random & mask) - (dither->random & mask);
//dither->random = random;
/* clip */
if (output > MAX) {
output = MAX;
if (sample > MAX)
sample = MAX;
}
else if (output < MIN) {
output = MIN;
if (sample < MIN)
sample = MIN;
}
/* quantize */
output &= ~mask;
/* error feedback */
dither->error[0] = sample - output;
/* scale */
return output >> scalebits;
}
static __inline
signed int detect_silence(mad_fixed_t sample)
{
unsigned int scalebits;
mad_fixed_t output, mask;
enum {
MIN = -MAD_F_ONE,
MAX = MAD_F_ONE - 1
};
/* bias */
output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
scalebits = MAD_F_FRACBITS + 1 - SAMPLE_DEPTH;
mask = (1L << scalebits) - 1;
/* clip */
if (output > MAX) {
output = MAX;
if (sample > MAX)
sample = MAX;
}
else if (output < MIN) {
output = MIN;
if (sample < MIN)
sample = MIN;
}
/* quantize */
output &= ~mask;
/* scale */
output >>= scalebits + 4;
if (output == 0x00 || output == 0xff)
return 1;
return 0;
}
#define SHRT_MAX 32767
#define INPUT_CHUNK_SIZE 8192
#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
unsigned char *OutputPtr;
unsigned char *GuardPtr=NULL;
const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
long resampled_data[2][5000]; /* enough to cope with 11khz upsampling */
mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
unsigned char mad_main_data[MAD_BUFFER_MDLEN] IDATA_ATTR;
/* TODO: what latency does layer 1 have? */
int mpeg_latency[3] = { 0, 481, 529 };
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
#undef DEBUG_GAPLESS
struct resampler {
long last_sample, phase, delta;
};
#if CONFIG_CPU==MCF5249 && !defined(SIMULATOR)
#define INIT() asm volatile ("move.l #0xb0, %macsr") /* frac, round, clip */
#define FRACMUL(x, y) \
({ \
long t; \
asm volatile ("mac.l %[a], %[b], %%acc0\n\t" \
"movclr.l %%acc0, %[t]\n\t" \
: [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
t; \
})
#else
#define INIT()
#define FRACMUL(x, y) (long)(((long long)(x)*(long long)(y)) << 1)
#endif
/* linear resampling, introduces one sample delay, because of our inability to
look into the future at the end of a frame */
long downsample(long *in, long *out, int num, struct resampler *s)
{
long i = 1, pos;
long last = s->last_sample;
INIT();
pos = s->phase >> 16;
/* check if we need last sample of previous frame for interpolation */
if (pos > 0)
last = in[pos - 1];
out[0] = last + FRACMUL((s->phase & 0xffff) << 15, in[pos] - last);
s->phase += s->delta;
while ((pos = s->phase >> 16) < num) {
out[i++] = in[pos - 1] + FRACMUL((s->phase & 0xffff) << 15, in[pos] - in[pos - 1]);
s->phase += s->delta;
}
/* wrap phase accumulator back to start of next frame */
s->phase -= num << 16;
s->last_sample = in[num - 1];
return i;
}
long upsample(long *in, long *out, int num, struct resampler *s)
{
long i = 0, pos;
INIT();
while ((pos = s->phase >> 16) == 0) {
out[i++] = s->last_sample + FRACMUL((s->phase & 0xffff) << 15, in[pos] - s->last_sample);
s->phase += s->delta;
}
while ((pos = s->phase >> 16) < num) {
out[i++] = in[pos - 1] + FRACMUL((s->phase & 0xffff) << 15, in[pos] - in[pos - 1]);
s->phase += s->delta;
}
/* wrap phase accumulator back to start of next frame */
s->phase -= num << 16;
s->last_sample = in[num - 1];
return i;
}
long resample(long *in, long *out, int num, struct resampler *s)
{
if (s->delta >= (1 << 16))
return downsample(in, out, num, s);
else
return upsample(in, out, num, s);
}
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
struct codec_api *ci = (struct codec_api *)parm;
struct mp3info *info;
int Status=0;
size_t size;
int file_end;
unsigned short Sample;
char *InputBuffer;
unsigned int samplecount;
unsigned int samplesdone;
bool first_frame;
#ifdef DEBUG_GAPLESS
bool first = true;
int fd;
#endif
int i;
int yieldcounter = 0;
int stop_skip, start_skip;
struct resampler lr = { 0, 0, 0 }, rr = { 0, 0, 0 };
long length;
/* Generic plugin inititialisation */
TEST_PLUGIN_API(api);
rb = api;
#ifdef USE_IRAM
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
/* This function sets up the buffers and reads the file into RAM */
if (codec_init(api, ci)) {
return PLUGIN_ERROR;
}
/* Create a decoder instance */
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
memset(&Stream, 0, sizeof(struct mad_stream));
memset(&Frame, 0, sizeof(struct mad_frame));
memset(&Synth, 0, sizeof(struct mad_synth));
memset(&Timer, 0, sizeof(mad_timer_t));
mad_stream_init(&Stream);
mad_frame_init(&Frame);
mad_synth_init(&Synth);
mad_timer_reset(&Timer);
/* We do this so libmad doesn't try to call codec_calloc() */
memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
Frame.overlap = &mad_frame_overlap;
Stream.main_data = &mad_main_data;
/* This label might need to be moved above all the init code, but I don't
think reiniting the codec is necessary for MPEG. It might even be unwanted
for gapless playback */
next_track:
#ifdef DEBUG_GAPLESS
if (first)
fd = rb->open("/first.pcm", O_WRONLY | O_CREAT);
else
fd = rb->open("/second.pcm", O_WRONLY | O_CREAT);
first = false;
#endif
info = ci->mp3data;
first_frame = false;
file_end = 0;
OutputPtr = OutputBuffer;
while (!*ci->taginfo_ready)
rb->yield();
ci->request_buffer(&size, ci->id3->first_frame_offset);
ci->advance_buffer(size);
if (info->enc_delay >= 0 && info->enc_padding >= 0) {
stop_skip = info->enc_padding - mpeg_latency[info->layer];
if (stop_skip < 0) stop_skip = 0;
start_skip = info->enc_delay + mpeg_latency[info->layer];
} else {
stop_skip = 0;
/* We want to skip this amount anyway */
start_skip = mpeg_latency[info->layer];
}
/* NOTE: currently this doesn't work, the below calculated samples_count
seems to be right, but sometimes libmad just can't supply us with
all the data we need... */
if (info->frame_count) {
/* TODO: 1152 is the frame size in samples for MPEG1 layer 2 and layer 3,
it's probably not correct at all for MPEG2 and layer 1 */
samplecount = info->frame_count*1152 - (start_skip + stop_skip);
samplesdone = ci->id3->elapsed * (ci->id3->frequency / 100) / 10;
} else {
samplecount = ci->id3->length * (ci->id3->frequency / 100) / 10;
samplesdone = ci->id3->elapsed * (ci->id3->frequency / 100) / 10;
}
/* rb->snprintf(buf2, sizeof(buf2), "sc: %d", samplecount);
rb->splash(0, true, buf2);
rb->snprintf(buf2, sizeof(buf2), "length: %d", ci->id3->length);
rb->splash(HZ*5, true, buf2);
rb->snprintf(buf2, sizeof(buf2), "frequency: %d", ci->id3->frequency);
rb->splash(HZ*5, true, buf2); */
lr.delta = rr.delta = ci->id3->frequency*65536/44100;
/* This is the decoding loop. */
while (1) {
rb->yield();
if (ci->stop_codec || ci->reload_codec) {
break ;
}
if (ci->seek_time) {
unsigned int sample_loc;
int newpos;
sample_loc = ci->seek_time/1000 * ci->id3->frequency;
newpos = ci->mp3_get_filepos(ci->seek_time-1);
if (ci->seek_buffer(newpos)) {
if (sample_loc >= samplecount + samplesdone)
break ;
samplecount += samplesdone - sample_loc;
samplesdone = sample_loc;
}
ci->seek_time = 0;
}
/* Lock buffers */
if (Stream.error == 0) {
InputBuffer = ci->request_buffer(&size, INPUT_CHUNK_SIZE);
if (size == 0 || InputBuffer == NULL)
break ;
mad_stream_buffer(&Stream, InputBuffer, size);
}
//if ((int)ci->curpos >= ci->id3->first_frame_offset)
//first_frame = true;
if(mad_frame_decode(&Frame,&Stream))
{
if (Stream.error == MAD_FLAG_INCOMPLETE || Stream.error == MAD_ERROR_BUFLEN) {
// rb->splash(HZ*1, true, "Incomplete");
/* This makes the codec to support partially corrupted files too. */
if (file_end == 30)
break ;
/* Fill the buffer */
Stream.error = 0;
file_end++;
continue ;
}
else if(MAD_RECOVERABLE(Stream.error))
{
if(Stream.error!=MAD_ERROR_LOSTSYNC || Stream.this_frame!=GuardPtr)
{
// rb->splash(HZ*1, true, "Recoverable...!");
}
continue;
}
else if(Stream.error==MAD_ERROR_BUFLEN) {
//rb->splash(HZ*1, true, "Buflen error");
break ;
} else {
//rb->splash(HZ*1, true, "Unrecoverable error");
Status=1;
break;
}
}
if (Stream.next_frame)
ci->advance_buffer_loc((void *)Stream.next_frame);
file_end = false;
/* ?? Do we need the timer module? */
// 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);
//if (!first_frame) {
//samplecount -= Synth.pcm.length;
//continue ;
//}
/* Convert MAD's numbers to an array of 16-bit LE signed integers */
/* We skip start_skip number of samples here, this should only happen for
very first frame in the stream. */
/* TODO: possible for start_skip to exceed one frames worth of samples? */
length = resample((long *)&Synth.pcm.samples[0][start_skip], resampled_data[0], Synth.pcm.length, &lr);
if (MAD_NCHANNELS(&Frame.header) == 2)
resample((long *)&Synth.pcm.samples[1][start_skip], resampled_data[1], Synth.pcm.length, &rr);
for (i = 0;i<length;i++)
{
start_skip = 0; /* not very elegant, and might want to keep this value */
samplesdone++;
//if (ci->mp3data->padding > 0) {
// ci->mp3data->padding--;
// continue ;
//}
/*if (!first_frame) {
if (detect_silence(Synth.pcm.samples[0][i]))
continue ;
first_frame = true;
}*/
/* Left channel */
Sample=scale(resampled_data[0][i],&d0);
*(OutputPtr++)=Sample>>8;
*(OutputPtr++)=Sample&0xff;
/* Right channel. If the decoded stream is monophonic then
* the right output channel is the same as the left one.
*/
if(MAD_NCHANNELS(&Frame.header)==2)
Sample=scale(resampled_data[1][i],&d1);
*(OutputPtr++)=Sample>>8;
*(OutputPtr++)=Sample&0xff;
samplecount--;
if (samplecount == 0) {
#ifdef DEBUG_GAPLESS
rb->write(fd, OutputBuffer, (int)OutputPtr-(int)OutputBuffer);
#endif
while (!ci->audiobuffer_insert(OutputBuffer, (int)OutputPtr-(int)OutputBuffer))
rb->yield();
goto song_end;
}
if (yieldcounter++ == 200) {
rb->yield();
yieldcounter = 0;
}
/* Flush the buffer if it is full. */
if(OutputPtr==OutputBufferEnd)
{
#ifdef DEBUG_GAPLESS
rb->write(fd, OutputBuffer, OUTPUT_BUFFER_SIZE);
#endif
while (!ci->audiobuffer_insert(OutputBuffer, OUTPUT_BUFFER_SIZE))
rb->yield();
OutputPtr=OutputBuffer;
}
}
ci->set_elapsed(samplesdone / (ci->id3->frequency/1000));
}
song_end:
#ifdef DEBUG_GAPLESS
rb->close(fd);
#endif
Stream.error = 0;
if (ci->request_next_track())
goto next_track;
return PLUGIN_OK;
}

View file

@ -1,214 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Thom Johansen
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include "playback.h"
#include "lib/codeclib.h"
#include <codecs/libmusepack/musepack.h>
static struct plugin_api* rb;
mpc_decoder decoder;
/*
Our implementations of the mpc_reader callback functions.
*/
mpc_int32_t
read_impl(void *data, void *ptr, mpc_int32_t size)
{
struct codec_api* ci = (struct codec_api*)data;
return((mpc_int32_t)(ci->read_filebuf(ptr,size)));
}
bool
seek_impl(void *data, mpc_int32_t offset)
{
struct codec_api* ci = (struct codec_api*)data;
/* WARNING: assumes we don't need to skip too far into the past,
this might not be supported by the buffering layer yet */
return ci->seek_buffer(offset);
}
mpc_int32_t
tell_impl(void *data)
{
struct codec_api* ci = (struct codec_api*)data;
return ci->curpos;
}
mpc_int32_t
get_size_impl(void *data)
{
struct codec_api* ci = (struct codec_api*)data;
return ci->filesize;
}
bool
canseek_impl(void *data)
{
(void)data;
return false;
}
static int
shift_signed(MPC_SAMPLE_FORMAT val, int shift)
{
if (shift > 0)
val <<= shift;
else if (shift < 0)
val >>= -shift;
return (int)val;
}
#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
/* temporary, we probably have better use for iram than this */
MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH] IDATA_ATTR;
unsigned char *OutputPtr=OutputBuffer;
const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
struct codec_api* ci = (struct codec_api*)parm;
unsigned short Sample;
unsigned long samplesdone;
unsigned long frequency;
unsigned status = 1;
unsigned int i;
mpc_reader reader;
/* Generic plugin inititialisation */
TEST_PLUGIN_API(api);
rb = api;
#ifndef SIMULATOR
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
next_track:
if (codec_init(api, ci)) {
return PLUGIN_ERROR;
}
/* Create a decoder instance */
reader.read = read_impl;
reader.seek = seek_impl;
reader.tell = tell_impl;
reader.get_size = get_size_impl;
reader.canseek = canseek_impl;
reader.data = ci;
/* read file's streaminfo data */
mpc_streaminfo info;
mpc_streaminfo_init(&info);
if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) {
return PLUGIN_ERROR;
}
frequency=info.sample_freq;
/* instantiate a decoder with our file reader */
mpc_decoder_setup(&decoder, &reader);
if (!mpc_decoder_initialize(&decoder, &info)) {
return PLUGIN_ERROR;
}
/* Initialise the output buffer. */
OutputPtr=OutputBuffer;
OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
/* This is the decoding loop. */
samplesdone=0;
while (status != 0) {
if (ci->stop_codec || ci->reload_codec) {
break;
}
status = mpc_decoder_decode(&decoder, sample_buffer, 0, 0);
if (status == (unsigned)(-1)) {
//decode error
return PLUGIN_ERROR;
}
else //status>0
{
// file_info.current_sample += status;
// file_info.frames_decoded++;
/* Convert musepack's numbers to an array of 16-bit BE signed integers */
for(i = 0; i < status*info.channels; i += info.channels)
{
/* Left channel */
Sample=shift_signed(sample_buffer[i], 16 - MPC_FIXED_POINT_SCALE_SHIFT);
*(OutputPtr++)=Sample>>8;
*(OutputPtr++)=Sample&0xff;
/* Right channel. If the decoded stream is monophonic then
* the right output channel is the same as the left one.
*/
if(info.channels==2) {
Sample=shift_signed(sample_buffer[i + 1], 16 - MPC_FIXED_POINT_SCALE_SHIFT);
}
*(OutputPtr++)=Sample>>8;
*(OutputPtr++)=Sample&0xff;
samplesdone++;
/* Flush the buffer if it is full. */
if(OutputPtr==OutputBufferEnd)
{
rb->yield();
while (!ci->audiobuffer_insert(OutputBuffer, OUTPUT_BUFFER_SIZE)) {
rb->yield();
}
ci->set_elapsed(samplesdone/(frequency/1000));
OutputPtr=OutputBuffer;
}
}
}
}
/* Flush the remaining data in the output buffer */
if (OutputPtr > OutputBuffer) {
rb->yield();
while (!ci->audiobuffer_insert(OutputBuffer, OutputPtr-OutputBuffer)) {
rb->yield();
}
}
if (ci->request_next_track())
goto next_track;
return PLUGIN_OK;
}

View file

@ -1,166 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Björn Stenberg
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "kernel.h"
#include "plugin.h"
#include <codecs/Tremor/ivorbisfile.h>
#include "playback.h"
#include "lib/codeclib.h"
static struct plugin_api* rb;
/* Some standard functions and variables needed by Tremor */
int errno;
size_t strlen(const char *s) {
return(rb->strlen(s));
}
char *strcpy(char *dest, const char *src) {
return(rb->strcpy(dest,src));
}
char *strcat(char *dest, const char *src) {
return(rb->strcat(dest,src));
}
size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) {
struct codec_api *p = (struct codec_api *) datasource;
return p->read_filebuf(ptr, nmemb*size);
}
int seek_handler(void *datasource, ogg_int64_t offset, int whence) {
/* We are not seekable at the moment */
(void)datasource;
(void)offset;
(void)whence;
return -1;
}
int close_handler(void *datasource) {
(void)datasource;
return 0;
}
long tell_handler(void *datasource) {
struct codec_api *p = (struct codec_api *) datasource;
return p->curpos;
}
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
/* reserve the PCM buffer in the IRAM area */
static char pcmbuf[4096] IDATA_ATTR;
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
struct codec_api *ci = (struct codec_api *)parm;
ov_callbacks callbacks;
OggVorbis_File vf;
vorbis_info* vi;
int error;
long n;
int current_section;
int eof;
#if BYTE_ORDER == BIG_ENDIAN
int i;
char x;
#endif
TEST_PLUGIN_API(api);
/* if you are using a global api pointer, don't forget to copy it!
otherwise you will get lovely "I04: IllInstr" errors... :-) */
rb = api;
#ifdef USE_IRAM
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*64));
/* We need to flush reserver memory every track load. */
next_track:
if (codec_init(api, ci)) {
return PLUGIN_ERROR;
}
/* Create a decoder instance */
callbacks.read_func=read_handler;
callbacks.seek_func=seek_handler;
callbacks.tell_func=tell_handler;
callbacks.close_func=close_handler;
error=ov_open_callbacks(ci,&vf,NULL,0,callbacks);
vi=ov_info(&vf,-1);
if (vi==NULL) {
// rb->splash(HZ*2, true, "Vorbis Error");
return PLUGIN_ERROR;
}
eof=0;
while (!eof) {
/* Read host-endian signed 16 bit PCM samples */
n=ov_read(&vf,pcmbuf,sizeof(pcmbuf),&current_section);
if (n==0) {
eof=1;
} else if (n < 0) {
DEBUGF("Error decoding frame\n");
} else {
rb->yield();
if (ci->stop_codec || ci->reload_codec)
break ;
rb->yield();
while (!ci->audiobuffer_insert(pcmbuf, n))
rb->yield();
ci->set_elapsed(ov_time_tell(&vf));
#if BYTE_ORDER == BIG_ENDIAN
for (i=0;i<n;i+=2) {
x=pcmbuf[i]; pcmbuf[i]=pcmbuf[i+1]; pcmbuf[i+1]=x;
}
#endif
}
}
if (ci->request_next_track())
goto next_track;
return PLUGIN_OK;
}

View file

@ -1,136 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include "playback.h"
#include "lib/codeclib.h"
#define BYTESWAP(x) (((x>>8) & 0xff) | ((x<<8) & 0xff00))
/* Number of bytes to process in one iteration */
#define WAV_CHUNK_SIZE (1024*4)
#ifndef SIMULATOR
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
struct plugin_api* rb = (struct plugin_api*)api;
struct codec_api* ci = (struct codec_api*)parm;
unsigned long samplerate,numbytes,totalsamples,samplesdone,nsamples;
int channels,bytespersample,bitspersample;
unsigned int i;
size_t n;
int endofstream;
unsigned char* header;
unsigned short* wavbuf;
/* Generic plugin initialisation */
TEST_PLUGIN_API(api);
/* if you are using a global api pointer, don't forget to copy it!
otherwise you will get lovely "I04: IllInstr" errors... :-) */
rb = api;
#ifndef SIMULATOR
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10));
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
next_track:
if (codec_init(api, ci)) {
return PLUGIN_ERROR;
}
/* FIX: Correctly parse WAV header - we assume canonical 44-byte header */
header=ci->request_buffer(&n,44);
if (n!=44) {
return PLUGIN_ERROR;
}
if ((memcmp(header,"RIFF",4)!=0) || (memcmp(&header[8],"WAVEfmt",7)!=0)) {
return PLUGIN_ERROR;
}
samplerate=header[24]|(header[25]<<8)|(header[26]<<16)|(header[27]<<24);
bitspersample=header[34];
channels=header[22];
bytespersample=((bitspersample/8)*channels);
numbytes=(header[40]|(header[41]<<8)|(header[42]<<16)|(header[43]<<24));
totalsamples=numbytes/bytespersample;
if ((bitspersample!=16) || (channels != 2)) {
return PLUGIN_ERROR;
}
ci->advance_buffer(44);
/* The main decoder loop */
samplesdone=0;
ci->set_elapsed(0);
endofstream=0;
while (!endofstream) {
if (ci->stop_codec || ci->reload_codec) {
break;
}
wavbuf=ci->request_buffer(&n,WAV_CHUNK_SIZE);
if (n==0) break; /* End of stream */
nsamples=(n/bytespersample);
/* WAV files can contain extra data at the end - so we can't just
process until the end of the file */
if (samplesdone+nsamples > totalsamples) {
nsamples=(totalsamples-samplesdone);
n=nsamples*bytespersample;
endofstream=1;
}
/* Byte-swap data */
for (i=0;i<n/2;i++) {
wavbuf[i]=BYTESWAP(wavbuf[i]);
}
samplesdone+=nsamples;
ci->set_elapsed(samplesdone/(ci->id3->frequency/1000));
rb->yield();
while (!ci->audiobuffer_insert((unsigned char*)wavbuf, n))
rb->yield();
ci->advance_buffer(n);
}
if (ci->request_next_track())
goto next_track;
return PLUGIN_OK;
}

View file

@ -1,185 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 David Bryant
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include <codecs/libwavpack/wavpack.h>
#include "playback.h"
#include "lib/codeclib.h"
static struct plugin_api *rb;
static struct codec_api *ci;
#define BUFFER_SIZE 4096
static long temp_buffer [BUFFER_SIZE] IDATA_ATTR;
static long read_callback (void *buffer, long bytes)
{
return ci->read_filebuf (buffer, bytes);
}
#ifndef SIMULATOR
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parm)
{
WavpackContext *wpc;
char error [80];
int bps, nchans;
/* Generic plugin initialisation */
TEST_PLUGIN_API(api);
rb = api;
ci = (struct codec_api*) parm;
#ifndef SIMULATOR
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10));
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
next_track:
if (codec_init(api, ci))
return PLUGIN_ERROR;
/* Create a decoder instance */
wpc = WavpackOpenFileInput (read_callback, error);
if (!wpc)
return PLUGIN_ERROR;
bps = WavpackGetBytesPerSample (wpc);
nchans = WavpackGetReducedChannels (wpc);
ci->set_elapsed (0);
/* The main decoder loop */
while (1) {
long nsamples;
if (ci->seek_time && ci->taginfo_ready && ci->id3->length) {
int curpos_ms = (WavpackGetSampleIndex (wpc) + 220) / 441 * 10;
int n, d, skip;
if (ci->seek_time > curpos_ms) {
n = ci->seek_time - curpos_ms;
d = ci->id3->length - curpos_ms;
skip = (int)((long long)(ci->filesize - ci->curpos) * n / d);
ci->seek_buffer (ci->curpos + skip);
}
else {
n = curpos_ms - ci->seek_time;
d = curpos_ms;
skip = (int)((long long) ci->curpos * n / d);
ci->seek_buffer (ci->curpos - skip);
}
wpc = WavpackOpenFileInput (read_callback, error);
ci->seek_time = 0;
if (!wpc)
break;
ci->set_elapsed ((int)((long long) WavpackGetSampleIndex (wpc) * 1000 / 44100));
rb->yield ();
}
nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / 2);
if (!nsamples || ci->stop_codec || ci->reload_codec)
break;
/* convert mono to stereo here, in place */
if (nchans == 1) {
long *dst = temp_buffer + (nsamples * 2);
long *src = temp_buffer + nsamples;
long count = nsamples;
while (count--) {
*--dst = *--src;
*--dst = *src;
if (!(count & 0x7f))
rb->yield ();
}
}
if (bps == 1) {
short *dst = (short *) temp_buffer;
long *src = temp_buffer;
long count = nsamples;
while (count--) {
*dst++ = *src++ << 8;
*dst++ = *src++ << 8;
if (!(count & 0x7f))
rb->yield ();
}
}
else if (bps == 2) {
short *dst = (short *) temp_buffer;
long *src = temp_buffer;
long count = nsamples;
while (count--) {
*dst++ = *src++;
*dst++ = *src++;
if (!(count & 0x7f))
rb->yield ();
}
}
else {
short *dst = (short *) temp_buffer;
int shift = (bps - 2) * 8;
long *src = temp_buffer;
long count = nsamples;
while (count--) {
*dst++ = *src++ >> shift;
*dst++ = *src++ >> shift;
if (!(count & 0x7f))
rb->yield ();
}
}
if (ci->stop_codec || ci->reload_codec)
break;
while (!ci->audiobuffer_insert ((char *) temp_buffer, nsamples * 4))
rb->yield ();
ci->set_elapsed ((WavpackGetSampleIndex (wpc) + 220) / 441 * 10);
}
if (ci->request_next_track())
goto next_track;
return PLUGIN_OK;
}

View file

@ -34,9 +34,8 @@ gray_verline.c
#ifdef HAVE_LCD_CHARCELLS
playergfx.c
#endif
#if 0
#if CONFIG_HWCODEC == MASNONE /* software codec platforms */
xxx2wav.c
#ifdef IRIVER_H100
codeclib.c
#endif
#endif

View file

@ -1,37 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/* Various "helper functions" common to all the xxx2wav decoder plugins */
#include "plugin.h"
#include "playback.h"
#include "codeclib.h"
#include "xxx2wav.h"
struct plugin_api* local_rb;
int codec_init(struct plugin_api* rb, struct codec_api* ci) {
local_rb = rb;
xxx2wav_set_api(rb);
mem_ptr = 0;
mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize);
return 0;
}

View file

@ -1,46 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/* Various "helper functions" common to all the xxx2wav decoder plugins */
#if CONFIG_CPU == MCF5249 && !defined(SIMULATOR)
#define ICODE_ATTR __attribute__ ((section(".icode")))
#define IDATA_ATTR __attribute__ ((section(".idata")))
#define USE_IRAM 1
#else
#define ICODE_ATTR
#define IDATA_ATTR
#endif
extern int mem_ptr;
extern int bufsize;
extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
void* codec_malloc(size_t size);
void* codec_calloc(size_t nmemb, size_t size);
void* codec_alloca(size_t size);
void* codec_realloc(void* ptr, size_t size);
void codec_free(void* ptr);
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
void* memmove(const void *s1, const void *s2, size_t n);
int codec_init(struct plugin_api* rb, struct codec_api* ci);

View file

@ -1,259 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/* Various "helper functions" common to all the xxx2wav decoder plugins */
#if (CONFIG_HWCODEC == MASNONE)
/* software codec platforms, not for simulator */
#include "plugin.h"
#include "xxx2wav.h"
static struct plugin_api* local_rb;
int mem_ptr;
int bufsize;
unsigned char* audiobuf; // The actual audio buffer from Rockbox
unsigned char* mallocbuf; // 512K from the start of audio buffer
unsigned char* filebuf; // The rest of the audio buffer
void* codec_malloc(size_t size) {
void* x;
x=&mallocbuf[mem_ptr];
mem_ptr+=(size+3)&~3; // Keep memory 32-bit aligned (if it was already?)
/*
if(TIME_AFTER(*(local_rb->current_tick), last_tick + HZ)) {
char s[32];
static long last_tick = 0;
local_rb->snprintf(s,30,"Memory used: %d",mem_ptr);
local_rb->lcd_putsxy(0,80,s);
last_tick = *(local_rb->current_tick);
local_rb->lcd_update();
}*/
return(x);
}
void* codec_calloc(size_t nmemb, size_t size) {
void* x;
x = codec_malloc(nmemb*size);
local_rb->memset(x,0,nmemb*size);
return(x);
}
void* codec_alloca(size_t size) {
void* x;
x = codec_malloc(size);
return(x);
}
void codec_free(void* ptr) {
(void)ptr;
}
void* codec_realloc(void* ptr, size_t size) {
void* x;
(void)ptr;
x = codec_malloc(size);
return(x);
}
void *memcpy(void *dest, const void *src, size_t n) {
return(local_rb->memcpy(dest,src,n));
}
void *memset(void *s, int c, size_t n) {
return(local_rb->memset(s,c,n));
}
int memcmp(const void *s1, const void *s2, size_t n) {
return(local_rb->memcmp(s1,s2,n));
}
void* memchr(const void *s, int c, size_t n) {
/* TO DO: Implement for Tremor */
(void)s;
(void)c;
(void)n;
return(NULL);
}
void* memmove(const void *s1, const void *s2, size_t n) {
char* dest=(char*)s1;
char* src=(char*)s2;
size_t i;
for (i=0;i<n;i++) { dest[i]=src[i]; }
// while(n>0) { *(dest++)=*(src++); n--; }
return(dest);
}
void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) {
local_rb->qsort(base,nmemb,size,compar);
}
void display_status(file_info_struct* file_info) {
char s[32];
unsigned long ticks_taken;
unsigned long long speed;
unsigned long xspeed;
static long last_tick = 0;
if(TIME_AFTER(*(local_rb->current_tick), last_tick + HZ)) {
local_rb->snprintf(s,32,"Bytes read: %d",file_info->curpos);
local_rb->lcd_putsxy(0,0,s);
local_rb->snprintf(s,32,"Samples Decoded: %d",file_info->current_sample);
local_rb->lcd_putsxy(0,20,s);
local_rb->snprintf(s,32,"Frames Decoded: %d",file_info->frames_decoded);
local_rb->lcd_putsxy(0,40,s);
ticks_taken=*(local_rb->current_tick)-file_info->start_tick;
/* e.g.:
ticks_taken=500
sam_fmt.rate=44,100
samples_decoded=172,400
(samples_decoded/sam_fmt.rate)*100=400 (time it should have taken)
% Speed=(400/500)*100=80%
*/
if (ticks_taken==0) { ticks_taken=1; } // Avoid fp exception.
speed=(100*file_info->current_sample)/file_info->samplerate;
xspeed=(speed*10000)/ticks_taken;
local_rb->snprintf(s,32,"Speed %ld.%02ld %% Secs: %d",(xspeed/100),(xspeed%100),ticks_taken/100);
local_rb->lcd_putsxy(0,60,s);
last_tick = *(local_rb->current_tick);
local_rb->lcd_update();
}
}
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=16-bit)
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
};
void xxx2wav_set_api(struct plugin_api* rb)
{
local_rb = rb;
}
int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb) {
char s[32];
int i,n,bytesleft;
local_rb=rb;
mem_ptr=0;
audiobuf=local_rb->plugin_get_audio_buffer(&bufsize);
mallocbuf=audiobuf;
filebuf=&audiobuf[MALLOC_BUFSIZE];
local_rb->snprintf(s,32,"audio bufsize: %d",bufsize);
local_rb->lcd_putsxy(0,100,s);
local_rb->lcd_update();
file_info->infile=local_rb->open(infilename,O_RDONLY);
file_info->outfile=local_rb->creat(outfilename,O_WRONLY);
local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
file_info->curpos=0;
file_info->current_sample=0;
file_info->frames_decoded=0;
file_info->filesize=local_rb->filesize(file_info->infile);
local_rb->splash(HZ, true, "in: %d, size: %d", file_info->infile, file_info->filesize);
if (file_info->filesize > (bufsize-MALLOC_BUFSIZE)) {
local_rb->close(file_info->infile);
local_rb->splash(HZ*2, true, "File too large");
return(1);
}
local_rb->snprintf(s,32,"Loading file...");
local_rb->lcd_putsxy(0,0,s);
local_rb->lcd_update();
bytesleft=file_info->filesize;
i=0;
while (bytesleft > 0) {
n=local_rb->read(file_info->infile,&filebuf[i],bytesleft);
if (n < 0) {
local_rb->close(file_info->infile);
local_rb->splash(HZ*2, true, "ERROR READING FILE");
return(1);
}
i+=n; bytesleft-=n;
}
local_rb->close(file_info->infile);
local_rb->lcd_clear_display();
return(0);
}
void close_wav(file_info_struct* file_info) {
int x;
int filesize=local_rb->filesize(file_info->outfile);
/* We assume 16-bit, Stereo */
local_rb->lseek(file_info->outfile,0,SEEK_SET);
// 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;
// Samplerate
wav_header[24]=file_info->samplerate&0xff;
wav_header[25]=(file_info->samplerate&0xff00)>>8;
wav_header[26]=(file_info->samplerate&0xff0000)>>16;
wav_header[27]=(file_info->samplerate&0xff000000)>>24;
// ByteRate
x=file_info->samplerate*4;
wav_header[28]=(x&0xff);
wav_header[29]=(x&0xff00)>>8;
wav_header[30]=(x&0xff0000)>>16;
wav_header[31]=(x&0xff000000)>>24;
// 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;
local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
local_rb->close(file_info->outfile);
}
#endif /* CONFIG_HWCODEC == MASNONE */

View file

@ -1,67 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Dave Chapman
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/* Various "helper functions" common to all the xxx2wav decoder plugins */
#if CONFIG_CPU == MCF5249 && !defined(SIMULATOR)
#define ICODE_ATTR __attribute__ ((section(".icode")))
#define IDATA_ATTR __attribute__ ((section(".idata")))
#define USE_IRAM 1
#else
#define ICODE_ATTR
#define IDATA_ATTR
#endif
/* the main data structure of the program */
typedef struct {
int infile;
int outfile;
off_t curpos;
off_t filesize;
int samplerate;
int bitspersample;
int channels;
int frames_decoded;
unsigned long total_samples;
unsigned long current_sample;
unsigned long start_tick;
} file_info_struct;
#define MALLOC_BUFSIZE (512*1024)
extern int mem_ptr;
extern int bufsize;
extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox
extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
extern unsigned char* filebuf; // The rest of the MP3 buffer
void* codec_malloc(size_t size);
void* codec_calloc(size_t nmemb, size_t size);
void* codec_alloca(size_t size);
void* codec_realloc(void* ptr, size_t size);
void codec_free(void* ptr);
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
void* memmove(const void *s1, const void *s2, size_t n);
void display_status(file_info_struct* file_info);
int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb);
void close_wav(file_info_struct* file_info);
void xxx2wav_set_api(struct plugin_api* rb);