From 80da8b141c4672ca4380d66094976b6342ed5071 Mon Sep 17 00:00:00 2001 From: Tomasz Malesinski Date: Sun, 26 Nov 2006 18:31:41 +0000 Subject: FS#6357, patch 1: let iramcopy and bss share the same space in codecs and plugins. Currently, in case of plugins using IRAM bss is cleared twice, once in the loader, once in PLUGIN_IRAM_INIT. For codecs, bss is cleared only during codec initialization. Also, removed double variables in codecs storing a pointer to codec_api. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11606 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs.c | 6 --- apps/codecs.h | 6 +-- apps/codecs/Makefile | 16 +++--- apps/codecs/a52.c | 21 +------- apps/codecs/aac.c | 35 +++---------- apps/codecs/adx.c | 10 +--- apps/codecs/aiff.c | 23 +-------- apps/codecs/aiff_enc.c | 18 +------ apps/codecs/alac.c | 37 ++++---------- apps/codecs/codec.h | 2 + apps/codecs/codec_crt0.c | 46 +++++++++++++++++ apps/codecs/flac.c | 23 +-------- apps/codecs/lib/codeclib.c | 45 ++++++++--------- apps/codecs/lib/codeclib.h | 3 +- apps/codecs/mp3_enc.c | 18 +------ apps/codecs/mpa.c | 21 +------- apps/codecs/mpc.c | 18 +------ apps/codecs/shorten.c | 27 ++-------- apps/codecs/sid.c | 27 ++-------- apps/codecs/vorbis.c | 97 +++++++++++++++--------------------- apps/codecs/wav.c | 23 +-------- apps/codecs/wav_enc.c | 18 +------ apps/codecs/wavpack.c | 21 +------- apps/codecs/wavpack_enc.c | 18 +------ apps/plugin.c | 1 + apps/plugins/doom/rockdoom.c | 4 +- apps/plugins/midiplay.c | 6 +-- apps/plugins/mp3_encoder.c | 6 +-- apps/plugins/mpegplayer/mpegplayer.c | 9 ++-- apps/plugins/pacbox/pacbox.c | 3 +- apps/plugins/plugin.lds | 7 ++- apps/plugins/rockboy/rockboy.c | 4 +- apps/plugins/zxbox/zxbox.c | 8 +-- 33 files changed, 190 insertions(+), 437 deletions(-) create mode 100644 apps/codecs/codec_crt0.c diff --git a/apps/codecs.c b/apps/codecs.c index 4491dadf49..dd3dddfccc 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -243,9 +243,6 @@ int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, int copy_n; if ((char *)&codecbuf[0] != codecptr) { - /* zero out codec buffer to ensure a properly zeroed bss area */ - memset(codecbuf, 0, CODEC_SIZE); - size = MIN(size, CODEC_SIZE); copy_n = MIN(size, bufwrap); memcpy(codecbuf, codecptr, copy_n); @@ -308,9 +305,6 @@ int codec_load_file(const char *plugin, struct codec_api *api) codec_get_full_path(path, plugin); - /* zero out codec buffer to ensure a properly zeroed bss area */ - memset(codecbuf, 0, CODEC_SIZE); - fd = open(path, O_RDONLY); if (fd < 0) { snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", path); diff --git a/apps/codecs.h b/apps/codecs.h index 0b90ef9c19..dff219c058 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -61,9 +61,9 @@ #if defined(DEBUG) || defined(SIMULATOR) #undef DEBUGF -#define DEBUGF rb->debugf +#define DEBUGF ci->debugf #undef LDEBUGF -#define LDEBUGF rb->debugf +#define LDEBUGF ci->debugf #else #define DEBUGF(...) #define LDEBUGF(...) @@ -71,7 +71,7 @@ #ifdef ROCKBOX_HAS_LOGF #undef LOGF -#define LOGF rb->logf +#define LOGF ci->logf #else #define LOGF(...) #endif diff --git a/apps/codecs/Makefile b/apps/codecs/Makefile index 38723b7940..e964bf70a7 100644 --- a/apps/codecs/Makefile +++ b/apps/codecs/Makefile @@ -66,7 +66,7 @@ $(OBJDIR)/mp3_enc.elf: $(OBJDIR)/mp3_enc.o $(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o $(OBJDIR)/wavpack_enc.elf: $(OBJDIR)/wavpack_enc.o $(BUILDDIR)/libwavpack.a -$(OBJDIR)/%.elf: +$(OBJDIR)/%.elf: $(OBJDIR)/codec_crt0.o $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $^ -L$(BUILDDIR) -lcodec -lgcc -T$(LINKCODEC) -Wl,-Map,$(OBJDIR)/$*.map $(OBJDIR)/%.codec : $(OBJDIR)/%.elf @@ -77,8 +77,8 @@ ifeq ($(SIMVER), x11) ################################################### # This is the X11 simulator version -$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a $(OUTPUT) - $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@ +$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT) + $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< $(OBJDIR)/codec_crt0.o -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@ ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) # 'x' must be kept or you'll have "Win32 error 5" # $ fgrep 5 /usr/include/w32api/winerror.h | head -1 @@ -92,8 +92,8 @@ ifeq ($(SIMVER), sdl) ################################################### # This is the SDL simulator version -$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a $(OUTPUT) - $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@ +$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT) + $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< $(OBJDIR)/codec_crt0.o -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@ ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) # 'x' must be kept or you'll have "Win32 error 5" # $ fgrep 5 /usr/include/w32api/winerror.h | head -1 @@ -108,9 +108,9 @@ else # end of sdl-simulator DLLTOOLFLAGS = --export-all DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin -$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a $(OUTPUT) - $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< - $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< \ +$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT) + $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< $(OBJDIR)/codec_crt0.o + $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< $(OBJDIR)/codec_crt0.o\ $(BUILDDIR)/libcodec.a $(patsubst -l%,$(BUILDDIR)/lib%.a,$(CODECLIBS)) \ -o $@ ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) diff --git a/apps/codecs/a52.c b/apps/codecs/a52.c index b7190be71b..4f41bfeaf5 100644 --- a/apps/codecs/a52.c +++ b/apps/codecs/a52.c @@ -28,8 +28,6 @@ CODEC_HEADER #define A52_SAMPLESPERFRAME (6*256) -struct codec_api *ci; - static a52_state_t *state; unsigned long samplesdone; unsigned long frequency; @@ -117,16 +115,8 @@ void a52_decode_data(uint8_t *start, uint8_t *end) } } -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { size_t n; unsigned char *filebuf; @@ -134,19 +124,12 @@ enum codec_status codec_start(struct codec_api *api) int retval; /* Generic codec initialisation */ - ci = api; - - #ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); - #endif - ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*128)); next_track: - if (codec_init(api)) { + if (codec_init()) { retval = CODEC_ERROR; goto exit; } diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index 3c9a6372e9..4a9c7479f3 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -25,19 +25,8 @@ CODEC_HEADER -#ifndef SIMULATOR -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - -struct codec_api* rb; -struct codec_api* ci; - /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { /* Note that when dealing with QuickTime/MPEG4 files, terminology is * a bit confusing. Files with sound are split up in chunks, where @@ -62,14 +51,6 @@ enum codec_status codec_start(struct codec_api* api) unsigned char c = 0; /* Generic codec initialisation */ - rb = api; - ci = api; - -#ifndef SIMULATOR - ci->memcpy(iramstart, iramcopy, iramend-iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); @@ -79,7 +60,7 @@ enum codec_status codec_start(struct codec_api* api) next_track: err = CODEC_OK; - if (codec_init(api)) { + if (codec_init()) { LOGF("FAAD: Codec init error\n"); err = CODEC_ERROR; goto exit; @@ -90,8 +71,8 @@ next_track: sound_samples_done = ci->id3->offset; - ci->configure(DSP_SWITCH_FREQUENCY, (long *)(rb->id3->frequency)); - codec_set_replaygain(rb->id3); + ci->configure(DSP_SWITCH_FREQUENCY, (long *)(ci->id3->frequency)); + codec_set_replaygain(ci->id3); stream_create(&input_stream,ci); @@ -139,7 +120,7 @@ next_track: /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { - rb->yield(); + ci->yield(); if (ci->stop_codec || ci->new_track) { break; @@ -195,12 +176,12 @@ next_track: ci->advance_buffer(n); /* Output the audio */ - rb->yield(); - while (!rb->pcmbuf_insert_split(decoder->time_out[0], + ci->yield(); + while (!ci->pcmbuf_insert_split(decoder->time_out[0], decoder->time_out[1], frame_info.samples * 2)) { - rb->sleep(1); + ci->sleep(1); } /* Update the elapsed-time indicator */ diff --git a/apps/codecs/adx.c b/apps/codecs/adx.c index 803600b23e..608d9f0a3f 100644 --- a/apps/codecs/adx.c +++ b/apps/codecs/adx.c @@ -21,8 +21,6 @@ CODEC_HEADER -struct codec_api *rb; - /* Maximum number of bytes to process in one iteration */ #define WAV_CHUNK_SIZE (1024*2) @@ -38,9 +36,8 @@ struct codec_api *rb; static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR; /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { - struct codec_api *ci; int channels; int sampleswritten, i; uint8_t *buf; @@ -56,16 +53,13 @@ enum codec_status codec_start(struct codec_api *api) off_t chanstart, bufoff; /* Generic codec initialisation */ - rb = api; - ci = api; - /* we only render 16 bits */ ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)16); /*ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));*/ next_track: DEBUGF("ADX: next_track\n"); - if (codec_init(api)) { + if (codec_init()) { return CODEC_ERROR; } DEBUGF("ADX: after init\n"); diff --git a/apps/codecs/aiff.c b/apps/codecs/aiff.c index 479d405c41..d1bb14aa64 100644 --- a/apps/codecs/aiff.c +++ b/apps/codecs/aiff.c @@ -25,8 +25,6 @@ CODEC_HEADER /* Macro that sign extends an unsigned byte */ #define SE(x) ((int32_t)((int8_t)(x))) -struct codec_api *rb; - /* This codec supports AIFF files with the following formats: * - PCM, 8, 16 and 24 bits, mono or stereo */ @@ -43,19 +41,10 @@ enum /* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */ #define AIF_CHUNK_SIZE (1024*2) -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - static int32_t samples[AIF_CHUNK_SIZE] IBSS_ATTR; -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { - struct codec_api *ci; uint32_t numbytes, bytesdone; uint16_t num_channels = 0; uint32_t num_sample_frames = 0; @@ -73,20 +62,12 @@ enum codec_status codec_start(struct codec_api *api) off_t firstblockposn; /* position of the first block in file */ /* Generic codec initialisation */ - rb = api; - ci = api; - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); next_track: - if (codec_init(api)) { + if (codec_init()) { i = CODEC_ERROR; goto exit; } diff --git a/apps/codecs/aiff_enc.c b/apps/codecs/aiff_enc.c index 8b6e2217c9..4f9e0e06e2 100644 --- a/apps/codecs/aiff_enc.c +++ b/apps/codecs/aiff_enc.c @@ -24,14 +24,6 @@ CODEC_ENC_HEADER -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - struct aiff_header { uint8_t form_id[4]; /* 00h - 'FORM' */ @@ -77,7 +69,6 @@ struct aiff_header aiff_header = /* (*) updated when finalizing file */ -static struct codec_api *ci; static int num_channels; uint32_t sample_rate; uint32_t enc_size; @@ -332,17 +323,10 @@ static bool init_encoder(void) } /* init_encoder */ /* main codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_start(void) { bool cpu_boosted; - ci = api; /* copy to global api pointer */ - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - if (!init_encoder()) { ci->enc_codec_loaded = -1; diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c index 13423f4804..1c1b14a0da 100644 --- a/apps/codecs/alac.c +++ b/apps/codecs/alac.c @@ -23,21 +23,10 @@ CODEC_HEADER -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR; -struct codec_api* rb; -struct codec_api* ci; - /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { size_t n; demux_res_t demux_res; @@ -53,14 +42,6 @@ enum codec_status codec_start(struct codec_api* api) int retval; /* Generic codec initialisation */ - rb = api; - ci = api; - -#ifdef USE_IRAM - rb->memcpy(iramstart, iramcopy, iramend-iramstart); - rb->memset(iedata, 0, iend - iedata); -#endif - ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); @@ -69,7 +50,7 @@ enum codec_status codec_start(struct codec_api* api) next_track: - if (codec_init(api)) { + if (codec_init()) { LOGF("ALAC: Error initialising codec\n"); retval = CODEC_ERROR; goto exit; @@ -78,8 +59,8 @@ enum codec_status codec_start(struct codec_api* api) while (!*ci->taginfo_ready && !ci->stop_codec) ci->sleep(1); - ci->configure(DSP_SWITCH_FREQUENCY, (long *)(rb->id3->frequency)); - codec_set_replaygain(rb->id3); + ci->configure(DSP_SWITCH_FREQUENCY, (long *)(ci->id3->frequency)); + codec_set_replaygain(ci->id3); stream_create(&input_stream,ci); @@ -99,7 +80,7 @@ enum codec_status codec_start(struct codec_api* api) samplesdone=0; /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { - rb->yield(); + ci->yield(); if (ci->stop_codec || ci->new_track) { break; } @@ -132,18 +113,18 @@ enum codec_status codec_start(struct codec_api* api) } /* Decode one block - returned samples will be host-endian */ - rb->yield(); - samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, rb->yield); + ci->yield(); + samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield); /* Advance codec buffer n bytes */ ci->advance_buffer(n); /* Output the audio */ - rb->yield(); + ci->yield(); while(!ci->pcmbuf_insert_split(outputbuffer[0], outputbuffer[1], samplesdecoded*sizeof(int32_t))) - rb->yield(); + ci->yield(); /* Update the elapsed-time indicator */ samplesdone+=sample_duration; diff --git a/apps/codecs/codec.h b/apps/codecs/codec.h index daa7c19cd7..44d5a110bd 100644 --- a/apps/codecs/codec.h +++ b/apps/codecs/codec.h @@ -24,6 +24,8 @@ #include +extern struct codec_api *ci; + /* Get these functions 'out of the way' of the standard functions. Not doing * so confuses the cygwin linker, and maybe others. These functions need to * be implemented elsewhere */ diff --git a/apps/codecs/codec_crt0.c b/apps/codecs/codec_crt0.c new file mode 100644 index 0000000000..96dc862fb5 --- /dev/null +++ b/apps/codecs/codec_crt0.c @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 Tomasz Malesinski + * + * 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 "config.h" +#include "codeclib.h" + +struct codec_api *ci; + +extern unsigned char iramcopy[]; +extern unsigned char iramstart[]; +extern unsigned char iramend[]; +extern unsigned char iedata[]; +extern unsigned char iend[]; +extern unsigned char plugin_bss_start[]; +extern unsigned char plugin_end_addr[]; + +extern enum codec_status codec_main(void); + +enum codec_status codec_start(struct codec_api *api) +{ +#ifndef SIMULATOR +#ifdef USE_IRAM + api->memcpy(iramstart, iramcopy, iramend - iramstart); + api->memset(iedata, 0, iend - iedata); +#endif + api->memset(plugin_bss_start, 0, plugin_end_addr - plugin_bss_start); +#endif + ci = api; + return codec_main(); +} diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c index 4f5f0b1eaa..b3cba32c82 100644 --- a/apps/codecs/flac.c +++ b/apps/codecs/flac.c @@ -22,17 +22,6 @@ CODEC_HEADER -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - -struct codec_api* rb; -struct codec_api* ci; - /* The output buffers containing the decoded samples (channels 0 and 1) */ int32_t decoded0[MAX_BLOCKSIZE] IBSS_ATTR_FLAC_DECODED0; int32_t decoded1[MAX_BLOCKSIZE] IBSS_ATTR; @@ -423,7 +412,7 @@ bool flac_seek_offset(FLACContext* fc, uint32_t offset) { } /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { int8_t *buf; FLACContext fc; @@ -436,14 +425,6 @@ enum codec_status codec_start(struct codec_api* api) int retval; /* Generic codec initialisation */ - rb = api; - ci = api; - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend-iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); @@ -455,7 +436,7 @@ enum codec_status codec_start(struct codec_api* api) /* Need to save offset for later use (cleared indirectly by flac_init) */ samplesdone=ci->id3->offset; - if (codec_init(api)) { + if (codec_init()) { LOGF("FLAC: Error initialising codec\n"); retval = CODEC_ERROR; goto exit; diff --git a/apps/codecs/lib/codeclib.c b/apps/codecs/lib/codeclib.c index 4aa7d29e86..f6b2131e88 100644 --- a/apps/codecs/lib/codeclib.c +++ b/apps/codecs/lib/codeclib.c @@ -24,29 +24,26 @@ #include "codeclib.h" #include "id3.h" -struct codec_api *local_rb; - long mem_ptr; long bufsize; unsigned char* mp3buf; // The actual MP3 buffer from Rockbox unsigned char* mallocbuf; // 512K from the start of MP3 buffer unsigned char* filebuf; // The rest of the MP3 buffer -int codec_init(struct codec_api* rb) +int codec_init(void) { - local_rb = rb; mem_ptr = 0; - mallocbuf = (unsigned char *)rb->get_codec_memory((size_t *)&bufsize); + mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); return 0; } void codec_set_replaygain(struct mp3entry* id3) { - local_rb->configure(DSP_SET_TRACK_GAIN, (long *) id3->track_gain); - local_rb->configure(DSP_SET_ALBUM_GAIN, (long *) id3->album_gain); - local_rb->configure(DSP_SET_TRACK_PEAK, (long *) id3->track_peak); - local_rb->configure(DSP_SET_ALBUM_PEAK, (long *) id3->album_peak); + ci->configure(DSP_SET_TRACK_GAIN, (long *) id3->track_gain); + ci->configure(DSP_SET_ALBUM_GAIN, (long *) id3->album_gain); + ci->configure(DSP_SET_TRACK_PEAK, (long *) id3->track_peak); + ci->configure(DSP_SET_ALBUM_PEAK, (long *) id3->album_peak); } /* Various "helper functions" common to all the xxx2wav decoder plugins */ @@ -71,7 +68,7 @@ void* codec_calloc(size_t nmemb, size_t size) x = codec_malloc(nmemb*size); if (x == NULL) return NULL; - local_rb->memset(x,0,nmemb*size); + ci->memset(x,0,nmemb*size); return(x); } @@ -89,71 +86,71 @@ void* codec_realloc(void* ptr, size_t size) size_t strlen(const char *s) { - return(local_rb->strlen(s)); + return(ci->strlen(s)); } char *strcpy(char *dest, const char *src) { - return(local_rb->strcpy(dest,src)); + return(ci->strcpy(dest,src)); } char *strcat(char *dest, const char *src) { - return(local_rb->strcat(dest,src)); + return(ci->strcat(dest,src)); } int strcmp(const char *s1, const char *s2) { - return(local_rb->strcmp(s1,s2)); + return(ci->strcmp(s1,s2)); } int strncasecmp(const char *s1, const char *s2, size_t n) { - return(local_rb->strncasecmp(s1,s2,n)); + return(ci->strncasecmp(s1,s2,n)); } void *memcpy(void *dest, const void *src, size_t n) { - return(local_rb->memcpy(dest,src,n)); + return(ci->memcpy(dest,src,n)); } void *memset(void *s, int c, size_t n) { - return(local_rb->memset(s,c,n)); + return(ci->memset(s,c,n)); } int memcmp(const void *s1, const void *s2, size_t n) { - return(local_rb->memcmp(s1,s2,n)); + return(ci->memcmp(s1,s2,n)); } void* memchr(const void *s, int c, size_t n) { - return(local_rb->memchr(s,c,n)); + return(ci->memchr(s,c,n)); } void *memmove(void *dest, const void *src, size_t n) { - return(local_rb->memmove(dest,src,n)); + return(ci->memmove(dest,src,n)); } void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) { - local_rb->qsort(base,nmemb,size,compar); + ci->qsort(base,nmemb,size,compar); } #ifdef RB_PROFILE void __cyg_profile_func_enter(void *this_fn, void *call_site) { #ifdef CPU_COLDFIRE (void)call_site; - local_rb->profile_func_enter(this_fn, __builtin_return_address(1)); + ci->profile_func_enter(this_fn, __builtin_return_address(1)); #else - local_rb->profile_func_enter(this_fn, call_site); + ci->profile_func_enter(this_fn, call_site); #endif } void __cyg_profile_func_exit(void *this_fn, void *call_site) { - local_rb->profile_func_exit(this_fn,call_site); + ci->profile_func_exit(this_fn,call_site); } #endif diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h index 00b60c3e92..366d30e064 100644 --- a/apps/codecs/lib/codeclib.h +++ b/apps/codecs/lib/codeclib.h @@ -24,6 +24,7 @@ #define MALLOC_BUFSIZE (512*1024) +extern struct codec_api *ci; extern long mem_ptr; extern long bufsize; extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox @@ -55,7 +56,7 @@ void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, con /* Various codec helper functions */ -int codec_init(struct codec_api* rb); +int codec_init(void); void codec_set_replaygain(struct mp3entry* id3); #ifdef RB_PROFILE diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c index cb727ce01e..12a24a7c9b 100644 --- a/apps/codecs/mp3_enc.c +++ b/apps/codecs/mp3_enc.c @@ -53,14 +53,6 @@ CODEC_ENC_HEADER #define putlong(c, s) if(s+sz <= 32) { cc = (cc << s) | c; sz+= s; } \ else { putbits(cc, sz); cc = c; sz = s; } -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - typedef struct { int type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */ int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */ @@ -181,7 +173,6 @@ static unsigned pcm_chunk_size IBSS_ATTR; static unsigned samp_per_frame IBSS_ATTR; static config_t cfg IBSS_ATTR; -static struct codec_api *ci; static char *res_buffer; static const uint8_t ht_count_const[2][2][16] = @@ -2460,18 +2451,11 @@ static bool enc_init(void) return true; } /* enc_init */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { bool cpu_boosted; /* Generic codec initialisation */ - ci = api; - -#ifdef USE_IRAM - memcpy(iramstart, iramcopy, iramend - iramstart); - memset(iedata, 0, iend - iedata); -#endif - if (!enc_init()) { ci->enc_codec_loaded = -1; diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 94947a9d1c..6e474c1abb 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -42,16 +42,6 @@ unsigned char mad_main_data[MAD_BUFFER_MDLEN] IBSS_ATTR; int mpeg_latency[3] = { 0, 481, 529 }; int mpeg_framesize[3] = {384, 1152, 1152}; -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - -struct codec_api *ci; - void init_mad(void) { ci->memset(&stream, 0, sizeof(struct mad_stream)); @@ -69,7 +59,7 @@ void init_mad(void) } /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { int status; size_t size; @@ -83,14 +73,7 @@ enum codec_status codec_start(struct codec_api *api) int framelength; int padding = MAD_BUFFER_GUARD; /* to help mad decode the last frame */ - ci = api; - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - - if (codec_init(api)) + if (codec_init()) return CODEC_ERROR; /* Create a decoder instance */ diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index ad38185fe0..1075d88aa1 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c @@ -67,18 +67,9 @@ MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH] IBSS_ATTR_MPC_SAMPLE_BUF; mpc_uint32_t seek_table[10000]; -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { - struct codec_api *ci = api; mpc_int64_t samplesdone; unsigned long frequency; unsigned status; @@ -86,11 +77,6 @@ enum codec_status codec_start(struct codec_api *api) mpc_streaminfo info; int retval = CODEC_OK; - #ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); - #endif - ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)(28)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16)); ci->configure(CODEC_SET_FILEBUF_PRESEEK, (long *)(0)); @@ -109,7 +95,7 @@ enum codec_status codec_start(struct codec_api *api) mpc_decoder_set_seek_table(&decoder, seek_table, sizeof(seek_table)); next_track: - if (codec_init(api)) { + if (codec_init()) { retval = CODEC_ERROR; goto exit; } diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c index b48a91ea17..1b9563a676 100644 --- a/apps/codecs/shorten.c +++ b/apps/codecs/shorten.c @@ -20,23 +20,12 @@ #include "codeclib.h" #include -#ifndef IBSS_ATTR_SHORTEN_DECODED0 -#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR -#endif - CODEC_HEADER -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; +#ifndef IBSS_ATTR_SHORTEN_DECODED0 +#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR #endif -struct codec_api* rb; -struct codec_api* ci; - int32_t decoded0[MAX_DECODE_SIZE] IBSS_ATTR_SHORTEN_DECODED0; int32_t decoded1[MAX_DECODE_SIZE] IBSS_ATTR; @@ -46,7 +35,7 @@ int32_t offset1[MAX_OFFSET_SIZE] IBSS_ATTR; int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR; /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { ShortenContext sc; uint32_t samplesdone; @@ -56,14 +45,6 @@ enum codec_status codec_start(struct codec_api* api) size_t bytesleft; /* Generic codec initialisation */ - rb = api; - ci = api; - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend-iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); @@ -72,7 +53,7 @@ enum codec_status codec_start(struct codec_api* api) next_track: /* Codec initialization */ - if (codec_init(api)) { + if (codec_init()) { LOGF("Shorten: codec_init error\n"); return CODEC_ERROR; } diff --git a/apps/codecs/sid.c b/apps/codecs/sid.c index d356da7fee..58eb725057 100644 --- a/apps/codecs/sid.c +++ b/apps/codecs/sid.c @@ -65,21 +65,10 @@ CODEC_HEADER #define CHUNK_SIZE (1024*2) - -struct codec_api *rb; - /* This codec supports SID Files: * */ -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - static int32_t samples[CHUNK_SIZE] IBSS_ATTR; /* The sample buffer */ /* Static buffer for the plain SID-File */ @@ -1213,9 +1202,8 @@ unsigned short LoadSIDFromMemory(void *pSidData, unsigned short *load_addr, } -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { - struct codec_api *ci; size_t n, bytesfree; unsigned char *p; unsigned int filesize; @@ -1228,20 +1216,11 @@ enum codec_status codec_start(struct codec_api *api) int nSamplesToRender = 0; /* Generic codec initialisation */ - rb = api; - ci = api; - - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); next_track: - if (codec_init(api)) { + if (codec_init()) { return CODEC_ERROR; } @@ -1251,7 +1230,7 @@ next_track: /* Load SID file */ p = sidfile; bytesfree=sizeof(sidfile); - while ((n = rb->read_filebuf(p, bytesfree)) > 0) { + while ((n = ci->read_filebuf(p, bytesfree)) > 0) { p += n; bytesfree -= n; } diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index d08cb0e90d..ca4aa9dd12 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -23,14 +23,12 @@ CODEC_HEADER -static struct codec_api *rb; - /* Some standard functions and variables needed by Tremor */ size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) { (void)datasource; - return rb->read_filebuf(ptr, nmemb*size); + return ci->read_filebuf(ptr, nmemb*size); } int initial_seek_handler(void *datasource, ogg_int64_t offset, int whence) @@ -46,12 +44,12 @@ int seek_handler(void *datasource, ogg_int64_t offset, int whence) (void)datasource; if (whence == SEEK_CUR) { - offset += rb->curpos; + offset += ci->curpos; } else if (whence == SEEK_END) { - offset += rb->filesize; + offset += ci->filesize; } - if (rb->seek_buffer(offset)) { + if (ci->seek_buffer(offset)) { return 0; } @@ -67,7 +65,7 @@ int close_handler(void *datasource) long tell_handler(void *datasource) { (void)datasource; - return rb->curpos; + return ci->curpos; } /* This sets the DSP parameters based on the current logical bitstream @@ -81,32 +79,24 @@ bool vorbis_set_codec_parameters(OggVorbis_File *vf) vi = ov_info(vf, -1); if (vi == NULL) { - //rb->splash(HZ*2, true, "Vorbis Error"); + //ci->splash(HZ*2, true, "Vorbis Error"); return false; } - rb->configure(DSP_SWITCH_FREQUENCY, (int *)rb->id3->frequency); - codec_set_replaygain(rb->id3); + ci->configure(DSP_SWITCH_FREQUENCY, (int *)ci->id3->frequency); + codec_set_replaygain(ci->id3); if (vi->channels == 2) { - rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED); + ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED); } else if (vi->channels == 1) { - rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO); + ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO); } return true; } -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { ov_callbacks callbacks; OggVorbis_File vf; @@ -122,16 +112,9 @@ enum codec_status codec_start(struct codec_api *api) ogg_uint32_t vf_serialnos; ogg_int64_t vf_pcmlengths[2]; - rb = api; - - #ifdef USE_IRAM - rb->memcpy(iramstart, iramcopy, iramend - iramstart); - rb->memset(iedata, 0, iend - iedata); - #endif - - rb->configure(DSP_SET_SAMPLE_DEPTH, (long *)24); - rb->configure(DSP_SET_CLIP_MAX, (long *)((1 << 24) - 1)); - rb->configure(DSP_SET_CLIP_MIN, (long *)-((1 << 24) - 1)); + ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)24); + ci->configure(DSP_SET_CLIP_MAX, (long *)((1 << 24) - 1)); + ci->configure(DSP_SET_CLIP_MIN, (long *)-((1 << 24) - 1)); /* Note: These are sane defaults for these values. Perhaps * they should be set differently based on quality setting */ @@ -139,17 +122,17 @@ enum codec_status codec_start(struct codec_api *api) /* The chunk size below is magic. If set any lower, resume * doesn't work properly (ov_raw_seek() does the wrong thing). */ - rb->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256)); + ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256)); /* We need to flush reserver memory every track load. */ next_track: - if (codec_init(rb)) { + if (codec_init()) { error = CODEC_ERROR; goto exit; } - while (!*rb->taginfo_ready && !rb->stop_codec) - rb->sleep(1); + while (!*ci->taginfo_ready && !ci->stop_codec) + ci->sleep(1); /* Create a decoder instance */ callbacks.read_func = read_handler; @@ -158,14 +141,14 @@ next_track: callbacks.close_func = close_handler; /* Open a non-seekable stream */ - error = ov_open_callbacks(rb, &vf, NULL, 0, callbacks); + error = ov_open_callbacks(ci, &vf, NULL, 0, callbacks); /* If the non-seekable open was successful, we need to supply the missing * data to make it seekable. This is a hack, but it's reasonable since we * don't want to run the whole file through the buffer before we start * playing. Using Tremor's seekable open routine would cause us to do * this, so we pretend not to be seekable at first. Then we fill in the - * missing fields of vf with 1) information in rb->id3, and 2) info + * missing fields of vf with 1) information in ci->id3, and 2) info * obtained by Tremor in the above ov_open call. * * Note that this assumes there is only ONE logical Vorbis bitstream in our @@ -179,40 +162,40 @@ next_track: vf.pcmlengths = vf_pcmlengths; vf.offsets[0] = 0; - vf.offsets[1] = rb->id3->filesize; + vf.offsets[1] = ci->id3->filesize; vf.dataoffsets[0] = vf.offset; vf.pcmlengths[0] = 0; - vf.pcmlengths[1] = rb->id3->samples; + vf.pcmlengths[1] = ci->id3->samples; vf.serialnos[0] = vf.current_serialno; vf.callbacks.seek_func = seek_handler; vf.seekable = 1; - vf.end = rb->id3->filesize; + vf.end = ci->id3->filesize; vf.ready_state = OPENED; vf.links = 1; } else { - //rb->logf("ov_open: %d", error); + //ci->logf("ov_open: %d", error); error = CODEC_ERROR; goto done; } - if (rb->id3->offset) { - rb->advance_buffer(rb->id3->offset); - ov_raw_seek(&vf, rb->id3->offset); - rb->set_elapsed(ov_time_tell(&vf)); - rb->set_offset(ov_raw_tell(&vf)); + if (ci->id3->offset) { + ci->advance_buffer(ci->id3->offset); + ov_raw_seek(&vf, ci->id3->offset); + ci->set_elapsed(ov_time_tell(&vf)); + ci->set_offset(ov_raw_tell(&vf)); } eof = 0; while (!eof) { - rb->yield(); - if (rb->stop_codec || rb->new_track) + ci->yield(); + if (ci->stop_codec || ci->new_track) break; - if (rb->seek_time) { - if (ov_time_seek(&vf, rb->seek_time - 1)) { - //rb->logf("ov_time_seek failed"); + if (ci->seek_time) { + if (ov_time_seek(&vf, ci->seek_time - 1)) { + //ci->logf("ov_time_seek failed"); } - rb->seek_complete(); + ci->seek_complete(); } /* Read host-endian signed 24-bit PCM samples */ @@ -233,18 +216,18 @@ next_track: } else if (n < 0) { DEBUGF("Error decoding frame\n"); } else { - while (!rb->pcmbuf_insert_split(pcm[0], pcm[1], + while (!ci->pcmbuf_insert_split(pcm[0], pcm[1], n*sizeof(ogg_int32_t))) { - rb->sleep(1); + ci->sleep(1); } - rb->set_offset(ov_raw_tell(&vf)); - rb->set_elapsed(ov_time_tell(&vf)); + ci->set_offset(ov_raw_tell(&vf)); + ci->set_elapsed(ov_time_tell(&vf)); } } error = CODEC_OK; done: - if (rb->request_next_track()) { + if (ci->request_next_track()) { /* Clean things up for the next track */ vf.dataoffsets = NULL; vf.offsets = NULL; diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c index 9add1f512a..26cbf7f6a1 100644 --- a/apps/codecs/wav.c +++ b/apps/codecs/wav.c @@ -25,8 +25,6 @@ CODEC_HEADER /* Macro that sign extends an unsigned byte */ #define SE(x) ((int32_t)((int8_t)(x))) -struct codec_api *rb; - /* This codec support WAVE files with the following formats: * - PCM, up to 32 bits, supporting 32 bits playback when useful. * - ALAW and MULAW (16 bits compressed on 8 bits). @@ -95,14 +93,6 @@ enum /* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */ #define WAV_CHUNK_SIZE (1024*2) -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - static const int16_t alaw2linear16[256] ICONST_ATTR = { -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, -7552, -7296, -8064, -7808, -6528, -6272, @@ -213,9 +203,8 @@ decode_dvi_adpcm(struct codec_api *ci, size_t *pcmoutsize); /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api *api) +enum codec_status codec_main(void) { - struct codec_api *ci; uint32_t numbytes, bytesdone; uint32_t totalsamples = 0; uint16_t channels = 0; @@ -235,20 +224,12 @@ enum codec_status codec_start(struct codec_api *api) /* Generic codec initialisation */ - rb = api; - ci = api; - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); next_track: - if (codec_init(api)) { + if (codec_init()) { i = CODEC_ERROR; goto exit; } diff --git a/apps/codecs/wav_enc.c b/apps/codecs/wav_enc.c index 974a903310..ff49238303 100644 --- a/apps/codecs/wav_enc.c +++ b/apps/codecs/wav_enc.c @@ -24,14 +24,6 @@ CODEC_ENC_HEADER -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - struct riff_header { uint8_t riff_id[4]; /* 00h - "RIFF" */ @@ -65,7 +57,6 @@ struct riff_header #define PCM_SAMP_PER_CHUNK 2048 #define PCM_CHUNK_SIZE (PCM_SAMP_PER_CHUNK*4) -static struct codec_api *ci; static int num_channels; uint32_t sample_rate; uint32_t enc_size; @@ -321,17 +312,10 @@ static bool init_encoder(void) } /* init_encoder */ /* main codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { bool cpu_boosted; - ci = api; // copy to global api pointer - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - if (!init_encoder()) { ci->enc_codec_loaded = -1; diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c index 65280535e6..e2c19c82e4 100644 --- a/apps/codecs/wavpack.c +++ b/apps/codecs/wavpack.c @@ -22,8 +22,6 @@ CODEC_HEADER -static struct codec_api *ci; - #define BUFFER_SIZE 4096 static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR; @@ -35,16 +33,8 @@ static int32_t read_callback (void *buffer, int32_t bytes) return retval; } -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - /* this is the codec entry point */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { WavpackContext *wpc; char error [80]; @@ -52,13 +42,6 @@ enum codec_status codec_start(struct codec_api* api) int retval; /* Generic codec initialisation */ - ci = api; - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend-iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); @@ -66,7 +49,7 @@ enum codec_status codec_start(struct codec_api* api) next_track: - if (codec_init(api)) { + if (codec_init()) { retval = CODEC_ERROR; goto exit; } diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c index 5318abc8fb..cee8c40615 100644 --- a/apps/codecs/wavpack_enc.c +++ b/apps/codecs/wavpack_enc.c @@ -24,14 +24,6 @@ CODEC_ENC_HEADER -#ifdef USE_IRAM -extern char iramcopy[]; -extern char iramstart[]; -extern char iramend[]; -extern char iedata[]; -extern char iend[]; -#endif - /** Types **/ typedef struct { @@ -73,7 +65,6 @@ struct riff_header #define PCM_CHUNK_SIZE (4*PCM_SAMP_PER_CHUNK) /** Data **/ -static struct codec_api *ci; static int8_t input_buffer[PCM_CHUNK_SIZE*2] IBSS_ATTR; static WavpackConfig config IBSS_ATTR; static WavpackContext *wpc; @@ -381,17 +372,10 @@ static bool init_encoder(void) return true; } /* init_encoder */ -enum codec_status codec_start(struct codec_api* api) +enum codec_status codec_main(void) { bool cpu_boosted; - ci = api; /* copy to global api pointer */ - -#ifdef USE_IRAM - ci->memcpy(iramstart, iramcopy, iramend - iramstart); - ci->memset(iedata, 0, iend - iedata); -#endif - /* initialize params and config */ if (!init_encoder()) { diff --git a/apps/plugin.c b/apps/plugin.c index 21930ee3a8..e74e4a7d42 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -699,6 +699,7 @@ void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size, audio_iram_steal(); memcpy(iramstart, iramcopy, iram_size); memset(iedata, 0, iedata_size); + memset(iramcopy, 0, iram_size); } #endif /* IRAM_STEAL */ diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index 8b73a5bb96..d66d86d65d 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c @@ -769,6 +769,8 @@ extern int systemvol; /* this is the plugin entry point */ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { + PLUGIN_IRAM_INIT(api) + rb = api; (void)parameter; @@ -778,8 +780,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) rb->cpu_boost(true); #endif - PLUGIN_IRAM_INIT(rb) - rb->lcd_setfont(0); #ifdef FANCY_MENU diff --git a/apps/plugins/midiplay.c b/apps/plugins/midiplay.c index a0e7d0e3c2..759535ac9e 100644 --- a/apps/plugins/midiplay.c +++ b/apps/plugins/midiplay.c @@ -105,8 +105,10 @@ struct plugin_api * rb; enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { int retval = 0; - rb = api; + PLUGIN_IRAM_INIT(api) + + rb = api; if(parameter == NULL) { rb->splash(HZ*2, true, " Play .MID file "); @@ -114,8 +116,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) } rb->lcd_setfont(0); - PLUGIN_IRAM_INIT(rb) - #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(true); #endif diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c index 5bfd384349..da0245eb2a 100644 --- a/apps/plugins/mp3_encoder.c +++ b/apps/plugins/mp3_encoder.c @@ -2364,14 +2364,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) int brate[] = { 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }; (void)parameter; - rb = api; + + PLUGIN_IRAM_INIT(api) #ifdef CPU_COLDFIRE asm volatile ("move.l #0, %macsr"); /* integer mode */ #endif - PLUGIN_IRAM_INIT(rb) - + rb = api; rb->lcd_setfont(FONT_SYSFIXED); #ifdef HAVE_ADJUSTABLE_CPU_FREQ diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c index 0fbd0f01e6..8a839eb17b 100644 --- a/apps/plugins/mpegplayer/mpegplayer.c +++ b/apps/plugins/mpegplayer/mpegplayer.c @@ -297,10 +297,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) uint8_t* buffer; size_t buffer_size; - rb = api; - /* This also stops audio playback - so we do it before using IRAM */ - audiobuf = rb->plugin_get_audio_buffer(&audiosize); + audiobuf = api->plugin_get_audio_buffer(&audiosize); + + PLUGIN_IRAM_INIT(api) + rb = api; /* Initialise our malloc buffer */ mpeg2_alloc_init(audiobuf,audiosize); @@ -312,8 +313,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) if (buffer == NULL) return PLUGIN_ERROR; - PLUGIN_IRAM_INIT(rb) - rb->lcd_set_backdrop(NULL); #ifdef HAVE_LCD_COLOR diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c index 62f5bcd413..4c539c593f 100644 --- a/apps/plugins/pacbox/pacbox.c +++ b/apps/plugins/pacbox/pacbox.c @@ -364,10 +364,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { (void)parameter; + PLUGIN_IRAM_INIT(api) rb = api; - PLUGIN_IRAM_INIT(rb) - #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(true); #endif diff --git a/apps/plugins/plugin.lds b/apps/plugins/plugin.lds index ef0dece36f..f27733a185 100644 --- a/apps/plugins/plugin.lds +++ b/apps/plugins/plugin.lds @@ -115,12 +115,11 @@ SECTIONS . = ALIGN(0x4); iend = .; } > PLUGIN_IRAM - - .bss ADDR(.data) + SIZEOF(.data) + SIZEOF(.iram): -#else - .bss : #endif + + .bss (NOLOAD) : { + plugin_bss_start = .; *(.bss*) *(COMMON) . = ALIGN(0x4); diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index 6a72856bbb..cce0f8c863 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c @@ -157,6 +157,8 @@ void savesettings(void) /* this is the plugin entry point */ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { + PLUGIN_IRAM_INIT(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; @@ -181,8 +183,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) #endif setoptions(); - PLUGIN_IRAM_INIT(rb) - shut=0; cleanshut=0; diff --git a/apps/plugins/zxbox/zxbox.c b/apps/plugins/zxbox/zxbox.c index 753fb1ff5b..cfc4e5d1c4 100644 --- a/apps/plugins/zxbox/zxbox.c +++ b/apps/plugins/zxbox/zxbox.c @@ -61,14 +61,16 @@ long start_time IBSS_ATTR = 0; enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - rb = api; #if CODEC == SWCODEC && !defined SIMULATOR - rb->pcm_play_stop(); + api->pcm_play_stop(); #endif + + PLUGIN_IRAM_INIT(api) + + rb = api; rb->lcd_set_backdrop(NULL); rb->splash(HZ, true, "Welcome to ZXBox"); - PLUGIN_IRAM_INIT(rb) sp_init(); -- cgit v1.2.3