summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Malesinski <tomal@rockbox.org>2006-11-26 18:31:41 +0000
committerTomasz Malesinski <tomal@rockbox.org>2006-11-26 18:31:41 +0000
commit80da8b141c4672ca4380d66094976b6342ed5071 (patch)
tree631e9edd537ae9983524622a9e1ec82e24957280
parent8ef3c8a342d41c2aa5e5d8370fd4e89d4d8d937e (diff)
downloadrockbox-80da8b141c4672ca4380d66094976b6342ed5071.tar.gz
rockbox-80da8b141c4672ca4380d66094976b6342ed5071.zip
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
-rw-r--r--apps/codecs.c6
-rw-r--r--apps/codecs.h6
-rw-r--r--apps/codecs/Makefile16
-rw-r--r--apps/codecs/a52.c21
-rw-r--r--apps/codecs/aac.c35
-rw-r--r--apps/codecs/adx.c10
-rw-r--r--apps/codecs/aiff.c23
-rw-r--r--apps/codecs/aiff_enc.c18
-rw-r--r--apps/codecs/alac.c37
-rw-r--r--apps/codecs/codec.h2
-rw-r--r--apps/codecs/codec_crt0.c46
-rw-r--r--apps/codecs/flac.c23
-rw-r--r--apps/codecs/lib/codeclib.c45
-rw-r--r--apps/codecs/lib/codeclib.h3
-rw-r--r--apps/codecs/mp3_enc.c18
-rw-r--r--apps/codecs/mpa.c21
-rw-r--r--apps/codecs/mpc.c18
-rw-r--r--apps/codecs/shorten.c27
-rw-r--r--apps/codecs/sid.c27
-rw-r--r--apps/codecs/vorbis.c97
-rw-r--r--apps/codecs/wav.c23
-rw-r--r--apps/codecs/wav_enc.c18
-rw-r--r--apps/codecs/wavpack.c21
-rw-r--r--apps/codecs/wavpack_enc.c18
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/plugins/doom/rockdoom.c4
-rw-r--r--apps/plugins/midiplay.c6
-rw-r--r--apps/plugins/mp3_encoder.c6
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c9
-rw-r--r--apps/plugins/pacbox/pacbox.c3
-rw-r--r--apps/plugins/plugin.lds7
-rw-r--r--apps/plugins/rockboy/rockboy.c4
-rw-r--r--apps/plugins/zxbox/zxbox.c8
33 files changed, 190 insertions, 437 deletions
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,
243 int copy_n; 243 int copy_n;
244 244
245 if ((char *)&codecbuf[0] != codecptr) { 245 if ((char *)&codecbuf[0] != codecptr) {
246 /* zero out codec buffer to ensure a properly zeroed bss area */
247 memset(codecbuf, 0, CODEC_SIZE);
248
249 size = MIN(size, CODEC_SIZE); 246 size = MIN(size, CODEC_SIZE);
250 copy_n = MIN(size, bufwrap); 247 copy_n = MIN(size, bufwrap);
251 memcpy(codecbuf, codecptr, copy_n); 248 memcpy(codecbuf, codecptr, copy_n);
@@ -308,9 +305,6 @@ int codec_load_file(const char *plugin, struct codec_api *api)
308 305
309 codec_get_full_path(path, plugin); 306 codec_get_full_path(path, plugin);
310 307
311 /* zero out codec buffer to ensure a properly zeroed bss area */
312 memset(codecbuf, 0, CODEC_SIZE);
313
314 fd = open(path, O_RDONLY); 308 fd = open(path, O_RDONLY);
315 if (fd < 0) { 309 if (fd < 0) {
316 snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", path); 310 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 @@
61 61
62#if defined(DEBUG) || defined(SIMULATOR) 62#if defined(DEBUG) || defined(SIMULATOR)
63#undef DEBUGF 63#undef DEBUGF
64#define DEBUGF rb->debugf 64#define DEBUGF ci->debugf
65#undef LDEBUGF 65#undef LDEBUGF
66#define LDEBUGF rb->debugf 66#define LDEBUGF ci->debugf
67#else 67#else
68#define DEBUGF(...) 68#define DEBUGF(...)
69#define LDEBUGF(...) 69#define LDEBUGF(...)
@@ -71,7 +71,7 @@
71 71
72#ifdef ROCKBOX_HAS_LOGF 72#ifdef ROCKBOX_HAS_LOGF
73#undef LOGF 73#undef LOGF
74#define LOGF rb->logf 74#define LOGF ci->logf
75#else 75#else
76#define LOGF(...) 76#define LOGF(...)
77#endif 77#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
66$(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o 66$(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o
67$(OBJDIR)/wavpack_enc.elf: $(OBJDIR)/wavpack_enc.o $(BUILDDIR)/libwavpack.a 67$(OBJDIR)/wavpack_enc.elf: $(OBJDIR)/wavpack_enc.o $(BUILDDIR)/libwavpack.a
68 68
69$(OBJDIR)/%.elf: 69$(OBJDIR)/%.elf: $(OBJDIR)/codec_crt0.o
70 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $^ -L$(BUILDDIR) -lcodec -lgcc -T$(LINKCODEC) -Wl,-Map,$(OBJDIR)/$*.map 70 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $^ -L$(BUILDDIR) -lcodec -lgcc -T$(LINKCODEC) -Wl,-Map,$(OBJDIR)/$*.map
71 71
72$(OBJDIR)/%.codec : $(OBJDIR)/%.elf 72$(OBJDIR)/%.codec : $(OBJDIR)/%.elf
@@ -77,8 +77,8 @@ ifeq ($(SIMVER), x11)
77################################################### 77###################################################
78# This is the X11 simulator version 78# This is the X11 simulator version
79 79
80$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a $(OUTPUT) 80$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT)
81 $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@ 81 $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< $(OBJDIR)/codec_crt0.o -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
82ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) 82ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
83# 'x' must be kept or you'll have "Win32 error 5" 83# 'x' must be kept or you'll have "Win32 error 5"
84# $ fgrep 5 /usr/include/w32api/winerror.h | head -1 84# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
@@ -92,8 +92,8 @@ ifeq ($(SIMVER), sdl)
92################################################### 92###################################################
93# This is the SDL simulator version 93# This is the SDL simulator version
94 94
95$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a $(OUTPUT) 95$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT)
96 $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@ 96 $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< $(OBJDIR)/codec_crt0.o -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
97ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) 97ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
98# 'x' must be kept or you'll have "Win32 error 5" 98# 'x' must be kept or you'll have "Win32 error 5"
99# $ fgrep 5 /usr/include/w32api/winerror.h | head -1 99# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
@@ -108,9 +108,9 @@ else # end of sdl-simulator
108DLLTOOLFLAGS = --export-all 108DLLTOOLFLAGS = --export-all
109DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin 109DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin
110 110
111$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a $(OUTPUT) 111$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT)
112 $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< 112 $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< $(OBJDIR)/codec_crt0.o
113 $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< \ 113 $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< $(OBJDIR)/codec_crt0.o\
114 $(BUILDDIR)/libcodec.a $(patsubst -l%,$(BUILDDIR)/lib%.a,$(CODECLIBS)) \ 114 $(BUILDDIR)/libcodec.a $(patsubst -l%,$(BUILDDIR)/lib%.a,$(CODECLIBS)) \
115 -o $@ 115 -o $@
116ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) 116ifeq ($(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
28 28
29#define A52_SAMPLESPERFRAME (6*256) 29#define A52_SAMPLESPERFRAME (6*256)
30 30
31struct codec_api *ci;
32
33static a52_state_t *state; 31static a52_state_t *state;
34unsigned long samplesdone; 32unsigned long samplesdone;
35unsigned long frequency; 33unsigned long frequency;
@@ -117,16 +115,8 @@ void a52_decode_data(uint8_t *start, uint8_t *end)
117 } 115 }
118} 116}
119 117
120#ifdef USE_IRAM
121extern char iramcopy[];
122extern char iramstart[];
123extern char iramend[];
124extern char iedata[];
125extern char iend[];
126#endif
127
128/* this is the codec entry point */ 118/* this is the codec entry point */
129enum codec_status codec_start(struct codec_api *api) 119enum codec_status codec_main(void)
130{ 120{
131 size_t n; 121 size_t n;
132 unsigned char *filebuf; 122 unsigned char *filebuf;
@@ -134,19 +124,12 @@ enum codec_status codec_start(struct codec_api *api)
134 int retval; 124 int retval;
135 125
136 /* Generic codec initialisation */ 126 /* Generic codec initialisation */
137 ci = api;
138
139 #ifdef USE_IRAM
140 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
141 ci->memset(iedata, 0, iend - iedata);
142 #endif
143
144 ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED); 127 ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED);
145 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28); 128 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28);
146 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*128)); 129 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*128));
147 130
148next_track: 131next_track:
149 if (codec_init(api)) { 132 if (codec_init()) {
150 retval = CODEC_ERROR; 133 retval = CODEC_ERROR;
151 goto exit; 134 goto exit;
152 } 135 }
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 @@
25 25
26CODEC_HEADER 26CODEC_HEADER
27 27
28#ifndef SIMULATOR
29extern char iramcopy[];
30extern char iramstart[];
31extern char iramend[];
32extern char iedata[];
33extern char iend[];
34#endif
35
36struct codec_api* rb;
37struct codec_api* ci;
38
39/* this is the codec entry point */ 28/* this is the codec entry point */
40enum codec_status codec_start(struct codec_api* api) 29enum codec_status codec_main(void)
41{ 30{
42 /* Note that when dealing with QuickTime/MPEG4 files, terminology is 31 /* Note that when dealing with QuickTime/MPEG4 files, terminology is
43 * a bit confusing. Files with sound are split up in chunks, where 32 * 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)
62 unsigned char c = 0; 51 unsigned char c = 0;
63 52
64 /* Generic codec initialisation */ 53 /* Generic codec initialisation */
65 rb = api;
66 ci = api;
67
68#ifndef SIMULATOR
69 ci->memcpy(iramstart, iramcopy, iramend-iramstart);
70 ci->memset(iedata, 0, iend - iedata);
71#endif
72
73 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16)); 54 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
74 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 55 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
75 56
@@ -79,7 +60,7 @@ enum codec_status codec_start(struct codec_api* api)
79next_track: 60next_track:
80 err = CODEC_OK; 61 err = CODEC_OK;
81 62
82 if (codec_init(api)) { 63 if (codec_init()) {
83 LOGF("FAAD: Codec init error\n"); 64 LOGF("FAAD: Codec init error\n");
84 err = CODEC_ERROR; 65 err = CODEC_ERROR;
85 goto exit; 66 goto exit;
@@ -90,8 +71,8 @@ next_track:
90 71
91 sound_samples_done = ci->id3->offset; 72 sound_samples_done = ci->id3->offset;
92 73
93 ci->configure(DSP_SWITCH_FREQUENCY, (long *)(rb->id3->frequency)); 74 ci->configure(DSP_SWITCH_FREQUENCY, (long *)(ci->id3->frequency));
94 codec_set_replaygain(rb->id3); 75 codec_set_replaygain(ci->id3);
95 76
96 stream_create(&input_stream,ci); 77 stream_create(&input_stream,ci);
97 78
@@ -139,7 +120,7 @@ next_track:
139 120
140 /* The main decoding loop */ 121 /* The main decoding loop */
141 while (i < demux_res.num_sample_byte_sizes) { 122 while (i < demux_res.num_sample_byte_sizes) {
142 rb->yield(); 123 ci->yield();
143 124
144 if (ci->stop_codec || ci->new_track) { 125 if (ci->stop_codec || ci->new_track) {
145 break; 126 break;
@@ -195,12 +176,12 @@ next_track:
195 ci->advance_buffer(n); 176 ci->advance_buffer(n);
196 177
197 /* Output the audio */ 178 /* Output the audio */
198 rb->yield(); 179 ci->yield();
199 while (!rb->pcmbuf_insert_split(decoder->time_out[0], 180 while (!ci->pcmbuf_insert_split(decoder->time_out[0],
200 decoder->time_out[1], 181 decoder->time_out[1],
201 frame_info.samples * 2)) 182 frame_info.samples * 2))
202 { 183 {
203 rb->sleep(1); 184 ci->sleep(1);
204 } 185 }
205 186
206 /* Update the elapsed-time indicator */ 187 /* 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 @@
21 21
22CODEC_HEADER 22CODEC_HEADER
23 23
24struct codec_api *rb;
25
26/* Maximum number of bytes to process in one iteration */ 24/* Maximum number of bytes to process in one iteration */
27#define WAV_CHUNK_SIZE (1024*2) 25#define WAV_CHUNK_SIZE (1024*2)
28 26
@@ -38,9 +36,8 @@ struct codec_api *rb;
38static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR; 36static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR;
39 37
40/* this is the codec entry point */ 38/* this is the codec entry point */
41enum codec_status codec_start(struct codec_api *api) 39enum codec_status codec_main(void)
42{ 40{
43 struct codec_api *ci;
44 int channels; 41 int channels;
45 int sampleswritten, i; 42 int sampleswritten, i;
46 uint8_t *buf; 43 uint8_t *buf;
@@ -56,16 +53,13 @@ enum codec_status codec_start(struct codec_api *api)
56 off_t chanstart, bufoff; 53 off_t chanstart, bufoff;
57 54
58 /* Generic codec initialisation */ 55 /* Generic codec initialisation */
59 rb = api;
60 ci = api;
61
62 /* we only render 16 bits */ 56 /* we only render 16 bits */
63 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)16); 57 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)16);
64 /*ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));*/ 58 /*ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));*/
65 59
66next_track: 60next_track:
67 DEBUGF("ADX: next_track\n"); 61 DEBUGF("ADX: next_track\n");
68 if (codec_init(api)) { 62 if (codec_init()) {
69 return CODEC_ERROR; 63 return CODEC_ERROR;
70 } 64 }
71 DEBUGF("ADX: after init\n"); 65 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
25/* Macro that sign extends an unsigned byte */ 25/* Macro that sign extends an unsigned byte */
26#define SE(x) ((int32_t)((int8_t)(x))) 26#define SE(x) ((int32_t)((int8_t)(x)))
27 27
28struct codec_api *rb;
29
30/* This codec supports AIFF files with the following formats: 28/* This codec supports AIFF files with the following formats:
31 * - PCM, 8, 16 and 24 bits, mono or stereo 29 * - PCM, 8, 16 and 24 bits, mono or stereo
32 */ 30 */
@@ -43,19 +41,10 @@ enum
43/* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */ 41/* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */
44#define AIF_CHUNK_SIZE (1024*2) 42#define AIF_CHUNK_SIZE (1024*2)
45 43
46#ifdef USE_IRAM
47extern char iramcopy[];
48extern char iramstart[];
49extern char iramend[];
50extern char iedata[];
51extern char iend[];
52#endif
53
54static int32_t samples[AIF_CHUNK_SIZE] IBSS_ATTR; 44static int32_t samples[AIF_CHUNK_SIZE] IBSS_ATTR;
55 45
56enum codec_status codec_start(struct codec_api *api) 46enum codec_status codec_main(void)
57{ 47{
58 struct codec_api *ci;
59 uint32_t numbytes, bytesdone; 48 uint32_t numbytes, bytesdone;
60 uint16_t num_channels = 0; 49 uint16_t num_channels = 0;
61 uint32_t num_sample_frames = 0; 50 uint32_t num_sample_frames = 0;
@@ -73,20 +62,12 @@ enum codec_status codec_start(struct codec_api *api)
73 off_t firstblockposn; /* position of the first block in file */ 62 off_t firstblockposn; /* position of the first block in file */
74 63
75 /* Generic codec initialisation */ 64 /* Generic codec initialisation */
76 rb = api;
77 ci = api;
78
79#ifdef USE_IRAM
80 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
81 ci->memset(iedata, 0, iend - iedata);
82#endif
83
84 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28); 65 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28);
85 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 66 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
86 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); 67 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
87 68
88next_track: 69next_track:
89 if (codec_init(api)) { 70 if (codec_init()) {
90 i = CODEC_ERROR; 71 i = CODEC_ERROR;
91 goto exit; 72 goto exit;
92 } 73 }
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 @@
24 24
25CODEC_ENC_HEADER 25CODEC_ENC_HEADER
26 26
27#ifdef USE_IRAM
28extern char iramcopy[];
29extern char iramstart[];
30extern char iramend[];
31extern char iedata[];
32extern char iend[];
33#endif
34
35struct aiff_header 27struct aiff_header
36{ 28{
37 uint8_t form_id[4]; /* 00h - 'FORM' */ 29 uint8_t form_id[4]; /* 00h - 'FORM' */
@@ -77,7 +69,6 @@ struct aiff_header aiff_header =
77 69
78/* (*) updated when finalizing file */ 70/* (*) updated when finalizing file */
79 71
80static struct codec_api *ci;
81static int num_channels; 72static int num_channels;
82uint32_t sample_rate; 73uint32_t sample_rate;
83uint32_t enc_size; 74uint32_t enc_size;
@@ -332,17 +323,10 @@ static bool init_encoder(void)
332} /* init_encoder */ 323} /* init_encoder */
333 324
334/* main codec entry point */ 325/* main codec entry point */
335enum codec_status codec_start(struct codec_api* api) 326enum codec_status codec_start(void)
336{ 327{
337 bool cpu_boosted; 328 bool cpu_boosted;
338 329
339 ci = api; /* copy to global api pointer */
340
341#ifdef USE_IRAM
342 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
343 ci->memset(iedata, 0, iend - iedata);
344#endif
345
346 if (!init_encoder()) 330 if (!init_encoder())
347 { 331 {
348 ci->enc_codec_loaded = -1; 332 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 @@
23 23
24CODEC_HEADER 24CODEC_HEADER
25 25
26#ifdef USE_IRAM
27extern char iramcopy[];
28extern char iramstart[];
29extern char iramend[];
30extern char iedata[];
31extern char iend[];
32#endif
33
34int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR; 26int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR;
35 27
36struct codec_api* rb;
37struct codec_api* ci;
38
39/* this is the codec entry point */ 28/* this is the codec entry point */
40enum codec_status codec_start(struct codec_api* api) 29enum codec_status codec_main(void)
41{ 30{
42 size_t n; 31 size_t n;
43 demux_res_t demux_res; 32 demux_res_t demux_res;
@@ -53,14 +42,6 @@ enum codec_status codec_start(struct codec_api* api)
53 int retval; 42 int retval;
54 43
55 /* Generic codec initialisation */ 44 /* Generic codec initialisation */
56 rb = api;
57 ci = api;
58
59#ifdef USE_IRAM
60 rb->memcpy(iramstart, iramcopy, iramend-iramstart);
61 rb->memset(iedata, 0, iend - iedata);
62#endif
63
64 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 45 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
65 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); 46 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
66 47
@@ -69,7 +50,7 @@ enum codec_status codec_start(struct codec_api* api)
69 50
70 next_track: 51 next_track:
71 52
72 if (codec_init(api)) { 53 if (codec_init()) {
73 LOGF("ALAC: Error initialising codec\n"); 54 LOGF("ALAC: Error initialising codec\n");
74 retval = CODEC_ERROR; 55 retval = CODEC_ERROR;
75 goto exit; 56 goto exit;
@@ -78,8 +59,8 @@ enum codec_status codec_start(struct codec_api* api)
78 while (!*ci->taginfo_ready && !ci->stop_codec) 59 while (!*ci->taginfo_ready && !ci->stop_codec)
79 ci->sleep(1); 60 ci->sleep(1);
80 61
81 ci->configure(DSP_SWITCH_FREQUENCY, (long *)(rb->id3->frequency)); 62 ci->configure(DSP_SWITCH_FREQUENCY, (long *)(ci->id3->frequency));
82 codec_set_replaygain(rb->id3); 63 codec_set_replaygain(ci->id3);
83 64
84 stream_create(&input_stream,ci); 65 stream_create(&input_stream,ci);
85 66
@@ -99,7 +80,7 @@ enum codec_status codec_start(struct codec_api* api)
99 samplesdone=0; 80 samplesdone=0;
100 /* The main decoding loop */ 81 /* The main decoding loop */
101 while (i < demux_res.num_sample_byte_sizes) { 82 while (i < demux_res.num_sample_byte_sizes) {
102 rb->yield(); 83 ci->yield();
103 if (ci->stop_codec || ci->new_track) { 84 if (ci->stop_codec || ci->new_track) {
104 break; 85 break;
105 } 86 }
@@ -132,18 +113,18 @@ enum codec_status codec_start(struct codec_api* api)
132 } 113 }
133 114
134 /* Decode one block - returned samples will be host-endian */ 115 /* Decode one block - returned samples will be host-endian */
135 rb->yield(); 116 ci->yield();
136 samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, rb->yield); 117 samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield);
137 118
138 /* Advance codec buffer n bytes */ 119 /* Advance codec buffer n bytes */
139 ci->advance_buffer(n); 120 ci->advance_buffer(n);
140 121
141 /* Output the audio */ 122 /* Output the audio */
142 rb->yield(); 123 ci->yield();
143 while(!ci->pcmbuf_insert_split(outputbuffer[0], 124 while(!ci->pcmbuf_insert_split(outputbuffer[0],
144 outputbuffer[1], 125 outputbuffer[1],
145 samplesdecoded*sizeof(int32_t))) 126 samplesdecoded*sizeof(int32_t)))
146 rb->yield(); 127 ci->yield();
147 128
148 /* Update the elapsed-time indicator */ 129 /* Update the elapsed-time indicator */
149 samplesdone+=sample_duration; 130 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 @@
24 24
25#include <sys/types.h> 25#include <sys/types.h>
26 26
27extern struct codec_api *ci;
28
27/* Get these functions 'out of the way' of the standard functions. Not doing 29/* Get these functions 'out of the way' of the standard functions. Not doing
28 * so confuses the cygwin linker, and maybe others. These functions need to 30 * so confuses the cygwin linker, and maybe others. These functions need to
29 * be implemented elsewhere */ 31 * 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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Tomasz Malesinski
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "config.h"
21#include "codeclib.h"
22
23struct codec_api *ci;
24
25extern unsigned char iramcopy[];
26extern unsigned char iramstart[];
27extern unsigned char iramend[];
28extern unsigned char iedata[];
29extern unsigned char iend[];
30extern unsigned char plugin_bss_start[];
31extern unsigned char plugin_end_addr[];
32
33extern enum codec_status codec_main(void);
34
35enum codec_status codec_start(struct codec_api *api)
36{
37#ifndef SIMULATOR
38#ifdef USE_IRAM
39 api->memcpy(iramstart, iramcopy, iramend - iramstart);
40 api->memset(iedata, 0, iend - iedata);
41#endif
42 api->memset(plugin_bss_start, 0, plugin_end_addr - plugin_bss_start);
43#endif
44 ci = api;
45 return codec_main();
46}
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 @@
22 22
23CODEC_HEADER 23CODEC_HEADER
24 24
25#ifdef USE_IRAM
26extern char iramcopy[];
27extern char iramstart[];
28extern char iramend[];
29extern char iedata[];
30extern char iend[];
31#endif
32
33struct codec_api* rb;
34struct codec_api* ci;
35
36/* The output buffers containing the decoded samples (channels 0 and 1) */ 25/* The output buffers containing the decoded samples (channels 0 and 1) */
37int32_t decoded0[MAX_BLOCKSIZE] IBSS_ATTR_FLAC_DECODED0; 26int32_t decoded0[MAX_BLOCKSIZE] IBSS_ATTR_FLAC_DECODED0;
38int32_t decoded1[MAX_BLOCKSIZE] IBSS_ATTR; 27int32_t decoded1[MAX_BLOCKSIZE] IBSS_ATTR;
@@ -423,7 +412,7 @@ bool flac_seek_offset(FLACContext* fc, uint32_t offset) {
423} 412}
424 413
425/* this is the codec entry point */ 414/* this is the codec entry point */
426enum codec_status codec_start(struct codec_api* api) 415enum codec_status codec_main(void)
427{ 416{
428 int8_t *buf; 417 int8_t *buf;
429 FLACContext fc; 418 FLACContext fc;
@@ -436,14 +425,6 @@ enum codec_status codec_start(struct codec_api* api)
436 int retval; 425 int retval;
437 426
438 /* Generic codec initialisation */ 427 /* Generic codec initialisation */
439 rb = api;
440 ci = api;
441
442#ifdef USE_IRAM
443 ci->memcpy(iramstart, iramcopy, iramend-iramstart);
444 ci->memset(iedata, 0, iend - iedata);
445#endif
446
447 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 428 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
448 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); 429 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
449 430
@@ -455,7 +436,7 @@ enum codec_status codec_start(struct codec_api* api)
455 /* Need to save offset for later use (cleared indirectly by flac_init) */ 436 /* Need to save offset for later use (cleared indirectly by flac_init) */
456 samplesdone=ci->id3->offset; 437 samplesdone=ci->id3->offset;
457 438
458 if (codec_init(api)) { 439 if (codec_init()) {
459 LOGF("FLAC: Error initialising codec\n"); 440 LOGF("FLAC: Error initialising codec\n");
460 retval = CODEC_ERROR; 441 retval = CODEC_ERROR;
461 goto exit; 442 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 @@
24#include "codeclib.h" 24#include "codeclib.h"
25#include "id3.h" 25#include "id3.h"
26 26
27struct codec_api *local_rb;
28
29long mem_ptr; 27long mem_ptr;
30long bufsize; 28long bufsize;
31unsigned char* mp3buf; // The actual MP3 buffer from Rockbox 29unsigned char* mp3buf; // The actual MP3 buffer from Rockbox
32unsigned char* mallocbuf; // 512K from the start of MP3 buffer 30unsigned char* mallocbuf; // 512K from the start of MP3 buffer
33unsigned char* filebuf; // The rest of the MP3 buffer 31unsigned char* filebuf; // The rest of the MP3 buffer
34 32
35int codec_init(struct codec_api* rb) 33int codec_init(void)
36{ 34{
37 local_rb = rb;
38 mem_ptr = 0; 35 mem_ptr = 0;
39 mallocbuf = (unsigned char *)rb->get_codec_memory((size_t *)&bufsize); 36 mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize);
40 37
41 return 0; 38 return 0;
42} 39}
43 40
44void codec_set_replaygain(struct mp3entry* id3) 41void codec_set_replaygain(struct mp3entry* id3)
45{ 42{
46 local_rb->configure(DSP_SET_TRACK_GAIN, (long *) id3->track_gain); 43 ci->configure(DSP_SET_TRACK_GAIN, (long *) id3->track_gain);
47 local_rb->configure(DSP_SET_ALBUM_GAIN, (long *) id3->album_gain); 44 ci->configure(DSP_SET_ALBUM_GAIN, (long *) id3->album_gain);
48 local_rb->configure(DSP_SET_TRACK_PEAK, (long *) id3->track_peak); 45 ci->configure(DSP_SET_TRACK_PEAK, (long *) id3->track_peak);
49 local_rb->configure(DSP_SET_ALBUM_PEAK, (long *) id3->album_peak); 46 ci->configure(DSP_SET_ALBUM_PEAK, (long *) id3->album_peak);
50} 47}
51 48
52/* Various "helper functions" common to all the xxx2wav decoder plugins */ 49/* Various "helper functions" common to all the xxx2wav decoder plugins */
@@ -71,7 +68,7 @@ void* codec_calloc(size_t nmemb, size_t size)
71 x = codec_malloc(nmemb*size); 68 x = codec_malloc(nmemb*size);
72 if (x == NULL) 69 if (x == NULL)
73 return NULL; 70 return NULL;
74 local_rb->memset(x,0,nmemb*size); 71 ci->memset(x,0,nmemb*size);
75 return(x); 72 return(x);
76} 73}
77 74
@@ -89,71 +86,71 @@ void* codec_realloc(void* ptr, size_t size)
89 86
90size_t strlen(const char *s) 87size_t strlen(const char *s)
91{ 88{
92 return(local_rb->strlen(s)); 89 return(ci->strlen(s));
93} 90}
94 91
95char *strcpy(char *dest, const char *src) 92char *strcpy(char *dest, const char *src)
96{ 93{
97 return(local_rb->strcpy(dest,src)); 94 return(ci->strcpy(dest,src));
98} 95}
99 96
100char *strcat(char *dest, const char *src) 97char *strcat(char *dest, const char *src)
101{ 98{
102 return(local_rb->strcat(dest,src)); 99 return(ci->strcat(dest,src));
103} 100}
104 101
105int strcmp(const char *s1, const char *s2) 102int strcmp(const char *s1, const char *s2)
106{ 103{
107 return(local_rb->strcmp(s1,s2)); 104 return(ci->strcmp(s1,s2));
108} 105}
109 106
110int strncasecmp(const char *s1, const char *s2, size_t n) 107int strncasecmp(const char *s1, const char *s2, size_t n)
111{ 108{
112 return(local_rb->strncasecmp(s1,s2,n)); 109 return(ci->strncasecmp(s1,s2,n));
113} 110}
114 111
115void *memcpy(void *dest, const void *src, size_t n) 112void *memcpy(void *dest, const void *src, size_t n)
116{ 113{
117 return(local_rb->memcpy(dest,src,n)); 114 return(ci->memcpy(dest,src,n));
118} 115}
119 116
120void *memset(void *s, int c, size_t n) 117void *memset(void *s, int c, size_t n)
121{ 118{
122 return(local_rb->memset(s,c,n)); 119 return(ci->memset(s,c,n));
123} 120}
124 121
125int memcmp(const void *s1, const void *s2, size_t n) 122int memcmp(const void *s1, const void *s2, size_t n)
126{ 123{
127 return(local_rb->memcmp(s1,s2,n)); 124 return(ci->memcmp(s1,s2,n));
128} 125}
129 126
130void* memchr(const void *s, int c, size_t n) 127void* memchr(const void *s, int c, size_t n)
131{ 128{
132 return(local_rb->memchr(s,c,n)); 129 return(ci->memchr(s,c,n));
133} 130}
134 131
135void *memmove(void *dest, const void *src, size_t n) 132void *memmove(void *dest, const void *src, size_t n)
136{ 133{
137 return(local_rb->memmove(dest,src,n)); 134 return(ci->memmove(dest,src,n));
138} 135}
139 136
140void qsort(void *base, size_t nmemb, size_t size, 137void qsort(void *base, size_t nmemb, size_t size,
141 int(*compar)(const void *, const void *)) 138 int(*compar)(const void *, const void *))
142{ 139{
143 local_rb->qsort(base,nmemb,size,compar); 140 ci->qsort(base,nmemb,size,compar);
144} 141}
145 142
146#ifdef RB_PROFILE 143#ifdef RB_PROFILE
147void __cyg_profile_func_enter(void *this_fn, void *call_site) { 144void __cyg_profile_func_enter(void *this_fn, void *call_site) {
148#ifdef CPU_COLDFIRE 145#ifdef CPU_COLDFIRE
149 (void)call_site; 146 (void)call_site;
150 local_rb->profile_func_enter(this_fn, __builtin_return_address(1)); 147 ci->profile_func_enter(this_fn, __builtin_return_address(1));
151#else 148#else
152 local_rb->profile_func_enter(this_fn, call_site); 149 ci->profile_func_enter(this_fn, call_site);
153#endif 150#endif
154} 151}
155 152
156void __cyg_profile_func_exit(void *this_fn, void *call_site) { 153void __cyg_profile_func_exit(void *this_fn, void *call_site) {
157 local_rb->profile_func_exit(this_fn,call_site); 154 ci->profile_func_exit(this_fn,call_site);
158} 155}
159#endif 156#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 @@
24 24
25#define MALLOC_BUFSIZE (512*1024) 25#define MALLOC_BUFSIZE (512*1024)
26 26
27extern struct codec_api *ci;
27extern long mem_ptr; 28extern long mem_ptr;
28extern long bufsize; 29extern long bufsize;
29extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox 30extern 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
55 56
56/* Various codec helper functions */ 57/* Various codec helper functions */
57 58
58int codec_init(struct codec_api* rb); 59int codec_init(void);
59void codec_set_replaygain(struct mp3entry* id3); 60void codec_set_replaygain(struct mp3entry* id3);
60 61
61#ifdef RB_PROFILE 62#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
53#define putlong(c, s) if(s+sz <= 32) { cc = (cc << s) | c; sz+= s; } \ 53#define putlong(c, s) if(s+sz <= 32) { cc = (cc << s) | c; sz+= s; } \
54 else { putbits(cc, sz); cc = c; sz = s; } 54 else { putbits(cc, sz); cc = c; sz = s; }
55 55
56#ifdef USE_IRAM
57extern char iramcopy[];
58extern char iramstart[];
59extern char iramend[];
60extern char iedata[];
61extern char iend[];
62#endif
63
64typedef struct { 56typedef struct {
65 int type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */ 57 int type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */
66 int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */ 58 int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */
@@ -181,7 +173,6 @@ static unsigned pcm_chunk_size IBSS_ATTR;
181static unsigned samp_per_frame IBSS_ATTR; 173static unsigned samp_per_frame IBSS_ATTR;
182 174
183static config_t cfg IBSS_ATTR; 175static config_t cfg IBSS_ATTR;
184static struct codec_api *ci;
185static char *res_buffer; 176static char *res_buffer;
186 177
187static const uint8_t ht_count_const[2][2][16] = 178static const uint8_t ht_count_const[2][2][16] =
@@ -2460,18 +2451,11 @@ static bool enc_init(void)
2460 return true; 2451 return true;
2461} /* enc_init */ 2452} /* enc_init */
2462 2453
2463enum codec_status codec_start(struct codec_api* api) 2454enum codec_status codec_main(void)
2464{ 2455{
2465 bool cpu_boosted; 2456 bool cpu_boosted;
2466 2457
2467 /* Generic codec initialisation */ 2458 /* Generic codec initialisation */
2468 ci = api;
2469
2470#ifdef USE_IRAM
2471 memcpy(iramstart, iramcopy, iramend - iramstart);
2472 memset(iedata, 0, iend - iedata);
2473#endif
2474
2475 if (!enc_init()) 2459 if (!enc_init())
2476 { 2460 {
2477 ci->enc_codec_loaded = -1; 2461 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;
42int mpeg_latency[3] = { 0, 481, 529 }; 42int mpeg_latency[3] = { 0, 481, 529 };
43int mpeg_framesize[3] = {384, 1152, 1152}; 43int mpeg_framesize[3] = {384, 1152, 1152};
44 44
45#ifdef USE_IRAM
46extern char iramcopy[];
47extern char iramstart[];
48extern char iramend[];
49extern char iedata[];
50extern char iend[];
51#endif
52
53struct codec_api *ci;
54
55void init_mad(void) 45void init_mad(void)
56{ 46{
57 ci->memset(&stream, 0, sizeof(struct mad_stream)); 47 ci->memset(&stream, 0, sizeof(struct mad_stream));
@@ -69,7 +59,7 @@ void init_mad(void)
69} 59}
70 60
71/* this is the codec entry point */ 61/* this is the codec entry point */
72enum codec_status codec_start(struct codec_api *api) 62enum codec_status codec_main(void)
73{ 63{
74 int status; 64 int status;
75 size_t size; 65 size_t size;
@@ -83,14 +73,7 @@ enum codec_status codec_start(struct codec_api *api)
83 int framelength; 73 int framelength;
84 int padding = MAD_BUFFER_GUARD; /* to help mad decode the last frame */ 74 int padding = MAD_BUFFER_GUARD; /* to help mad decode the last frame */
85 75
86 ci = api; 76 if (codec_init())
87
88#ifdef USE_IRAM
89 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
90 ci->memset(iedata, 0, iend - iedata);
91#endif
92
93 if (codec_init(api))
94 return CODEC_ERROR; 77 return CODEC_ERROR;
95 78
96 /* Create a decoder instance */ 79 /* 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]
67IBSS_ATTR_MPC_SAMPLE_BUF; 67IBSS_ATTR_MPC_SAMPLE_BUF;
68mpc_uint32_t seek_table[10000]; 68mpc_uint32_t seek_table[10000];
69 69
70#ifdef USE_IRAM
71extern char iramcopy[];
72extern char iramstart[];
73extern char iramend[];
74extern char iedata[];
75extern char iend[];
76#endif
77
78/* this is the codec entry point */ 70/* this is the codec entry point */
79enum codec_status codec_start(struct codec_api *api) 71enum codec_status codec_main(void)
80{ 72{
81 struct codec_api *ci = api;
82 mpc_int64_t samplesdone; 73 mpc_int64_t samplesdone;
83 unsigned long frequency; 74 unsigned long frequency;
84 unsigned status; 75 unsigned status;
@@ -86,11 +77,6 @@ enum codec_status codec_start(struct codec_api *api)
86 mpc_streaminfo info; 77 mpc_streaminfo info;
87 int retval = CODEC_OK; 78 int retval = CODEC_OK;
88 79
89 #ifdef USE_IRAM
90 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
91 ci->memset(iedata, 0, iend - iedata);
92 #endif
93
94 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)(28)); 80 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)(28));
95 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16)); 81 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16));
96 ci->configure(CODEC_SET_FILEBUF_PRESEEK, (long *)(0)); 82 ci->configure(CODEC_SET_FILEBUF_PRESEEK, (long *)(0));
@@ -109,7 +95,7 @@ enum codec_status codec_start(struct codec_api *api)
109 mpc_decoder_set_seek_table(&decoder, seek_table, sizeof(seek_table)); 95 mpc_decoder_set_seek_table(&decoder, seek_table, sizeof(seek_table));
110 96
111next_track: 97next_track:
112 if (codec_init(api)) { 98 if (codec_init()) {
113 retval = CODEC_ERROR; 99 retval = CODEC_ERROR;
114 goto exit; 100 goto exit;
115 } 101 }
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 @@
20#include "codeclib.h" 20#include "codeclib.h"
21#include <codecs/libffmpegFLAC/shndec.h> 21#include <codecs/libffmpegFLAC/shndec.h>
22 22
23#ifndef IBSS_ATTR_SHORTEN_DECODED0
24#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR
25#endif
26
27CODEC_HEADER 23CODEC_HEADER
28 24
29#ifdef USE_IRAM 25#ifndef IBSS_ATTR_SHORTEN_DECODED0
30extern char iramcopy[]; 26#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR
31extern char iramstart[];
32extern char iramend[];
33extern char iedata[];
34extern char iend[];
35#endif 27#endif
36 28
37struct codec_api* rb;
38struct codec_api* ci;
39
40int32_t decoded0[MAX_DECODE_SIZE] IBSS_ATTR_SHORTEN_DECODED0; 29int32_t decoded0[MAX_DECODE_SIZE] IBSS_ATTR_SHORTEN_DECODED0;
41int32_t decoded1[MAX_DECODE_SIZE] IBSS_ATTR; 30int32_t decoded1[MAX_DECODE_SIZE] IBSS_ATTR;
42 31
@@ -46,7 +35,7 @@ int32_t offset1[MAX_OFFSET_SIZE] IBSS_ATTR;
46int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR; 35int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR;
47 36
48/* this is the codec entry point */ 37/* this is the codec entry point */
49enum codec_status codec_start(struct codec_api* api) 38enum codec_status codec_main(void)
50{ 39{
51 ShortenContext sc; 40 ShortenContext sc;
52 uint32_t samplesdone; 41 uint32_t samplesdone;
@@ -56,14 +45,6 @@ enum codec_status codec_start(struct codec_api* api)
56 size_t bytesleft; 45 size_t bytesleft;
57 46
58 /* Generic codec initialisation */ 47 /* Generic codec initialisation */
59 rb = api;
60 ci = api;
61
62#ifdef USE_IRAM
63 ci->memcpy(iramstart, iramcopy, iramend-iramstart);
64 ci->memset(iedata, 0, iend - iedata);
65#endif
66
67 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 48 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
68 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); 49 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
69 50
@@ -72,7 +53,7 @@ enum codec_status codec_start(struct codec_api* api)
72 53
73next_track: 54next_track:
74 /* Codec initialization */ 55 /* Codec initialization */
75 if (codec_init(api)) { 56 if (codec_init()) {
76 LOGF("Shorten: codec_init error\n"); 57 LOGF("Shorten: codec_init error\n");
77 return CODEC_ERROR; 58 return CODEC_ERROR;
78 } 59 }
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
65 65
66#define CHUNK_SIZE (1024*2) 66#define CHUNK_SIZE (1024*2)
67 67
68
69struct codec_api *rb;
70
71/* This codec supports SID Files: 68/* This codec supports SID Files:
72 * 69 *
73 */ 70 */
74 71
75#ifdef USE_IRAM
76extern char iramcopy[];
77extern char iramstart[];
78extern char iramend[];
79extern char iedata[];
80extern char iend[];
81#endif
82
83static int32_t samples[CHUNK_SIZE] IBSS_ATTR; /* The sample buffer */ 72static int32_t samples[CHUNK_SIZE] IBSS_ATTR; /* The sample buffer */
84 73
85/* Static buffer for the plain SID-File */ 74/* Static buffer for the plain SID-File */
@@ -1213,9 +1202,8 @@ unsigned short LoadSIDFromMemory(void *pSidData, unsigned short *load_addr,
1213} 1202}
1214 1203
1215 1204
1216enum codec_status codec_start(struct codec_api *api) 1205enum codec_status codec_main(void)
1217{ 1206{
1218 struct codec_api *ci;
1219 size_t n, bytesfree; 1207 size_t n, bytesfree;
1220 unsigned char *p; 1208 unsigned char *p;
1221 unsigned int filesize; 1209 unsigned int filesize;
@@ -1228,20 +1216,11 @@ enum codec_status codec_start(struct codec_api *api)
1228 int nSamplesToRender = 0; 1216 int nSamplesToRender = 0;
1229 1217
1230 /* Generic codec initialisation */ 1218 /* Generic codec initialisation */
1231 rb = api;
1232 ci = api;
1233
1234
1235#ifdef USE_IRAM
1236 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
1237 ci->memset(iedata, 0, iend - iedata);
1238#endif
1239
1240 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 1219 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
1241 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); 1220 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
1242 1221
1243next_track: 1222next_track:
1244 if (codec_init(api)) { 1223 if (codec_init()) {
1245 return CODEC_ERROR; 1224 return CODEC_ERROR;
1246 } 1225 }
1247 1226
@@ -1251,7 +1230,7 @@ next_track:
1251 /* Load SID file */ 1230 /* Load SID file */
1252 p = sidfile; 1231 p = sidfile;
1253 bytesfree=sizeof(sidfile); 1232 bytesfree=sizeof(sidfile);
1254 while ((n = rb->read_filebuf(p, bytesfree)) > 0) { 1233 while ((n = ci->read_filebuf(p, bytesfree)) > 0) {
1255 p += n; 1234 p += n;
1256 bytesfree -= n; 1235 bytesfree -= n;
1257 } 1236 }
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 @@
23 23
24CODEC_HEADER 24CODEC_HEADER
25 25
26static struct codec_api *rb;
27
28/* Some standard functions and variables needed by Tremor */ 26/* Some standard functions and variables needed by Tremor */
29 27
30size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) 28size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource)
31{ 29{
32 (void)datasource; 30 (void)datasource;
33 return rb->read_filebuf(ptr, nmemb*size); 31 return ci->read_filebuf(ptr, nmemb*size);
34} 32}
35 33
36int initial_seek_handler(void *datasource, ogg_int64_t offset, int whence) 34int 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)
46 (void)datasource; 44 (void)datasource;
47 45
48 if (whence == SEEK_CUR) { 46 if (whence == SEEK_CUR) {
49 offset += rb->curpos; 47 offset += ci->curpos;
50 } else if (whence == SEEK_END) { 48 } else if (whence == SEEK_END) {
51 offset += rb->filesize; 49 offset += ci->filesize;
52 } 50 }
53 51
54 if (rb->seek_buffer(offset)) { 52 if (ci->seek_buffer(offset)) {
55 return 0; 53 return 0;
56 } 54 }
57 55
@@ -67,7 +65,7 @@ int close_handler(void *datasource)
67long tell_handler(void *datasource) 65long tell_handler(void *datasource)
68{ 66{
69 (void)datasource; 67 (void)datasource;
70 return rb->curpos; 68 return ci->curpos;
71} 69}
72 70
73/* This sets the DSP parameters based on the current logical bitstream 71/* This sets the DSP parameters based on the current logical bitstream
@@ -81,32 +79,24 @@ bool vorbis_set_codec_parameters(OggVorbis_File *vf)
81 vi = ov_info(vf, -1); 79 vi = ov_info(vf, -1);
82 80
83 if (vi == NULL) { 81 if (vi == NULL) {
84 //rb->splash(HZ*2, true, "Vorbis Error"); 82 //ci->splash(HZ*2, true, "Vorbis Error");
85 return false; 83 return false;
86 } 84 }
87 85
88 rb->configure(DSP_SWITCH_FREQUENCY, (int *)rb->id3->frequency); 86 ci->configure(DSP_SWITCH_FREQUENCY, (int *)ci->id3->frequency);
89 codec_set_replaygain(rb->id3); 87 codec_set_replaygain(ci->id3);
90 88
91 if (vi->channels == 2) { 89 if (vi->channels == 2) {
92 rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED); 90 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED);
93 } else if (vi->channels == 1) { 91 } else if (vi->channels == 1) {
94 rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO); 92 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
95 } 93 }
96 94
97 return true; 95 return true;
98} 96}
99 97
100#ifdef USE_IRAM
101extern char iramcopy[];
102extern char iramstart[];
103extern char iramend[];
104extern char iedata[];
105extern char iend[];
106#endif
107
108/* this is the codec entry point */ 98/* this is the codec entry point */
109enum codec_status codec_start(struct codec_api *api) 99enum codec_status codec_main(void)
110{ 100{
111 ov_callbacks callbacks; 101 ov_callbacks callbacks;
112 OggVorbis_File vf; 102 OggVorbis_File vf;
@@ -122,16 +112,9 @@ enum codec_status codec_start(struct codec_api *api)
122 ogg_uint32_t vf_serialnos; 112 ogg_uint32_t vf_serialnos;
123 ogg_int64_t vf_pcmlengths[2]; 113 ogg_int64_t vf_pcmlengths[2];
124 114
125 rb = api; 115 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)24);
126 116 ci->configure(DSP_SET_CLIP_MAX, (long *)((1 << 24) - 1));
127 #ifdef USE_IRAM 117 ci->configure(DSP_SET_CLIP_MIN, (long *)-((1 << 24) - 1));
128 rb->memcpy(iramstart, iramcopy, iramend - iramstart);
129 rb->memset(iedata, 0, iend - iedata);
130 #endif
131
132 rb->configure(DSP_SET_SAMPLE_DEPTH, (long *)24);
133 rb->configure(DSP_SET_CLIP_MAX, (long *)((1 << 24) - 1));
134 rb->configure(DSP_SET_CLIP_MIN, (long *)-((1 << 24) - 1));
135 /* Note: These are sane defaults for these values. Perhaps 118 /* Note: These are sane defaults for these values. Perhaps
136 * they should be set differently based on quality setting 119 * they should be set differently based on quality setting
137 */ 120 */
@@ -139,17 +122,17 @@ enum codec_status codec_start(struct codec_api *api)
139 /* The chunk size below is magic. If set any lower, resume 122 /* The chunk size below is magic. If set any lower, resume
140 * doesn't work properly (ov_raw_seek() does the wrong thing). 123 * doesn't work properly (ov_raw_seek() does the wrong thing).
141 */ 124 */
142 rb->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256)); 125 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256));
143 126
144/* We need to flush reserver memory every track load. */ 127/* We need to flush reserver memory every track load. */
145next_track: 128next_track:
146 if (codec_init(rb)) { 129 if (codec_init()) {
147 error = CODEC_ERROR; 130 error = CODEC_ERROR;
148 goto exit; 131 goto exit;
149 } 132 }
150 133
151 while (!*rb->taginfo_ready && !rb->stop_codec) 134 while (!*ci->taginfo_ready && !ci->stop_codec)
152 rb->sleep(1); 135 ci->sleep(1);
153 136
154 /* Create a decoder instance */ 137 /* Create a decoder instance */
155 callbacks.read_func = read_handler; 138 callbacks.read_func = read_handler;
@@ -158,14 +141,14 @@ next_track:
158 callbacks.close_func = close_handler; 141 callbacks.close_func = close_handler;
159 142
160 /* Open a non-seekable stream */ 143 /* Open a non-seekable stream */
161 error = ov_open_callbacks(rb, &vf, NULL, 0, callbacks); 144 error = ov_open_callbacks(ci, &vf, NULL, 0, callbacks);
162 145
163 /* If the non-seekable open was successful, we need to supply the missing 146 /* If the non-seekable open was successful, we need to supply the missing
164 * data to make it seekable. This is a hack, but it's reasonable since we 147 * data to make it seekable. This is a hack, but it's reasonable since we
165 * don't want to run the whole file through the buffer before we start 148 * don't want to run the whole file through the buffer before we start
166 * playing. Using Tremor's seekable open routine would cause us to do 149 * playing. Using Tremor's seekable open routine would cause us to do
167 * this, so we pretend not to be seekable at first. Then we fill in the 150 * this, so we pretend not to be seekable at first. Then we fill in the
168 * missing fields of vf with 1) information in rb->id3, and 2) info 151 * missing fields of vf with 1) information in ci->id3, and 2) info
169 * obtained by Tremor in the above ov_open call. 152 * obtained by Tremor in the above ov_open call.
170 * 153 *
171 * Note that this assumes there is only ONE logical Vorbis bitstream in our 154 * Note that this assumes there is only ONE logical Vorbis bitstream in our
@@ -179,40 +162,40 @@ next_track:
179 vf.pcmlengths = vf_pcmlengths; 162 vf.pcmlengths = vf_pcmlengths;
180 163
181 vf.offsets[0] = 0; 164 vf.offsets[0] = 0;
182 vf.offsets[1] = rb->id3->filesize; 165 vf.offsets[1] = ci->id3->filesize;
183 vf.dataoffsets[0] = vf.offset; 166 vf.dataoffsets[0] = vf.offset;
184 vf.pcmlengths[0] = 0; 167 vf.pcmlengths[0] = 0;
185 vf.pcmlengths[1] = rb->id3->samples; 168 vf.pcmlengths[1] = ci->id3->samples;
186 vf.serialnos[0] = vf.current_serialno; 169 vf.serialnos[0] = vf.current_serialno;
187 vf.callbacks.seek_func = seek_handler; 170 vf.callbacks.seek_func = seek_handler;
188 vf.seekable = 1; 171 vf.seekable = 1;
189 vf.end = rb->id3->filesize; 172 vf.end = ci->id3->filesize;
190 vf.ready_state = OPENED; 173 vf.ready_state = OPENED;
191 vf.links = 1; 174 vf.links = 1;
192 } else { 175 } else {
193 //rb->logf("ov_open: %d", error); 176 //ci->logf("ov_open: %d", error);
194 error = CODEC_ERROR; 177 error = CODEC_ERROR;
195 goto done; 178 goto done;
196 } 179 }
197 180
198 if (rb->id3->offset) { 181 if (ci->id3->offset) {
199 rb->advance_buffer(rb->id3->offset); 182 ci->advance_buffer(ci->id3->offset);
200 ov_raw_seek(&vf, rb->id3->offset); 183 ov_raw_seek(&vf, ci->id3->offset);
201 rb->set_elapsed(ov_time_tell(&vf)); 184 ci->set_elapsed(ov_time_tell(&vf));
202 rb->set_offset(ov_raw_tell(&vf)); 185 ci->set_offset(ov_raw_tell(&vf));
203 } 186 }
204 187
205 eof = 0; 188 eof = 0;
206 while (!eof) { 189 while (!eof) {
207 rb->yield(); 190 ci->yield();
208 if (rb->stop_codec || rb->new_track) 191 if (ci->stop_codec || ci->new_track)
209 break; 192 break;
210 193
211 if (rb->seek_time) { 194 if (ci->seek_time) {
212 if (ov_time_seek(&vf, rb->seek_time - 1)) { 195 if (ov_time_seek(&vf, ci->seek_time - 1)) {
213 //rb->logf("ov_time_seek failed"); 196 //ci->logf("ov_time_seek failed");
214 } 197 }
215 rb->seek_complete(); 198 ci->seek_complete();
216 } 199 }
217 200
218 /* Read host-endian signed 24-bit PCM samples */ 201 /* Read host-endian signed 24-bit PCM samples */
@@ -233,18 +216,18 @@ next_track:
233 } else if (n < 0) { 216 } else if (n < 0) {
234 DEBUGF("Error decoding frame\n"); 217 DEBUGF("Error decoding frame\n");
235 } else { 218 } else {
236 while (!rb->pcmbuf_insert_split(pcm[0], pcm[1], 219 while (!ci->pcmbuf_insert_split(pcm[0], pcm[1],
237 n*sizeof(ogg_int32_t))) { 220 n*sizeof(ogg_int32_t))) {
238 rb->sleep(1); 221 ci->sleep(1);
239 } 222 }
240 rb->set_offset(ov_raw_tell(&vf)); 223 ci->set_offset(ov_raw_tell(&vf));
241 rb->set_elapsed(ov_time_tell(&vf)); 224 ci->set_elapsed(ov_time_tell(&vf));
242 } 225 }
243 } 226 }
244 error = CODEC_OK; 227 error = CODEC_OK;
245 228
246done: 229done:
247 if (rb->request_next_track()) { 230 if (ci->request_next_track()) {
248 /* Clean things up for the next track */ 231 /* Clean things up for the next track */
249 vf.dataoffsets = NULL; 232 vf.dataoffsets = NULL;
250 vf.offsets = NULL; 233 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
25/* Macro that sign extends an unsigned byte */ 25/* Macro that sign extends an unsigned byte */
26#define SE(x) ((int32_t)((int8_t)(x))) 26#define SE(x) ((int32_t)((int8_t)(x)))
27 27
28struct codec_api *rb;
29
30/* This codec support WAVE files with the following formats: 28/* This codec support WAVE files with the following formats:
31 * - PCM, up to 32 bits, supporting 32 bits playback when useful. 29 * - PCM, up to 32 bits, supporting 32 bits playback when useful.
32 * - ALAW and MULAW (16 bits compressed on 8 bits). 30 * - ALAW and MULAW (16 bits compressed on 8 bits).
@@ -95,14 +93,6 @@ enum
95/* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */ 93/* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */
96#define WAV_CHUNK_SIZE (1024*2) 94#define WAV_CHUNK_SIZE (1024*2)
97 95
98#ifdef USE_IRAM
99extern char iramcopy[];
100extern char iramstart[];
101extern char iramend[];
102extern char iedata[];
103extern char iend[];
104#endif
105
106static const int16_t alaw2linear16[256] ICONST_ATTR = { 96static const int16_t alaw2linear16[256] ICONST_ATTR = {
107 -5504, -5248, -6016, -5760, -4480, -4224, -4992, 97 -5504, -5248, -6016, -5760, -4480, -4224, -4992,
108 -4736, -7552, -7296, -8064, -7808, -6528, -6272, 98 -4736, -7552, -7296, -8064, -7808, -6528, -6272,
@@ -213,9 +203,8 @@ decode_dvi_adpcm(struct codec_api *ci,
213 size_t *pcmoutsize); 203 size_t *pcmoutsize);
214 204
215/* this is the codec entry point */ 205/* this is the codec entry point */
216enum codec_status codec_start(struct codec_api *api) 206enum codec_status codec_main(void)
217{ 207{
218 struct codec_api *ci;
219 uint32_t numbytes, bytesdone; 208 uint32_t numbytes, bytesdone;
220 uint32_t totalsamples = 0; 209 uint32_t totalsamples = 0;
221 uint16_t channels = 0; 210 uint16_t channels = 0;
@@ -235,20 +224,12 @@ enum codec_status codec_start(struct codec_api *api)
235 224
236 225
237 /* Generic codec initialisation */ 226 /* Generic codec initialisation */
238 rb = api;
239 ci = api;
240
241#ifdef USE_IRAM
242 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
243 ci->memset(iedata, 0, iend - iedata);
244#endif
245
246 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28); 227 ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28);
247 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 228 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
248 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); 229 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
249 230
250next_track: 231next_track:
251 if (codec_init(api)) { 232 if (codec_init()) {
252 i = CODEC_ERROR; 233 i = CODEC_ERROR;
253 goto exit; 234 goto exit;
254 } 235 }
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 @@
24 24
25CODEC_ENC_HEADER 25CODEC_ENC_HEADER
26 26
27#ifdef USE_IRAM
28extern char iramcopy[];
29extern char iramstart[];
30extern char iramend[];
31extern char iedata[];
32extern char iend[];
33#endif
34
35struct riff_header 27struct riff_header
36{ 28{
37 uint8_t riff_id[4]; /* 00h - "RIFF" */ 29 uint8_t riff_id[4]; /* 00h - "RIFF" */
@@ -65,7 +57,6 @@ struct riff_header
65#define PCM_SAMP_PER_CHUNK 2048 57#define PCM_SAMP_PER_CHUNK 2048
66#define PCM_CHUNK_SIZE (PCM_SAMP_PER_CHUNK*4) 58#define PCM_CHUNK_SIZE (PCM_SAMP_PER_CHUNK*4)
67 59
68static struct codec_api *ci;
69static int num_channels; 60static int num_channels;
70uint32_t sample_rate; 61uint32_t sample_rate;
71uint32_t enc_size; 62uint32_t enc_size;
@@ -321,17 +312,10 @@ static bool init_encoder(void)
321} /* init_encoder */ 312} /* init_encoder */
322 313
323/* main codec entry point */ 314/* main codec entry point */
324enum codec_status codec_start(struct codec_api* api) 315enum codec_status codec_main(void)
325{ 316{
326 bool cpu_boosted; 317 bool cpu_boosted;
327 318
328 ci = api; // copy to global api pointer
329
330#ifdef USE_IRAM
331 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
332 ci->memset(iedata, 0, iend - iedata);
333#endif
334
335 if (!init_encoder()) 319 if (!init_encoder())
336 { 320 {
337 ci->enc_codec_loaded = -1; 321 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 @@
22 22
23CODEC_HEADER 23CODEC_HEADER
24 24
25static struct codec_api *ci;
26
27#define BUFFER_SIZE 4096 25#define BUFFER_SIZE 4096
28 26
29static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR; 27static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR;
@@ -35,16 +33,8 @@ static int32_t read_callback (void *buffer, int32_t bytes)
35 return retval; 33 return retval;
36} 34}
37 35
38#ifdef USE_IRAM
39extern char iramcopy[];
40extern char iramstart[];
41extern char iramend[];
42extern char iedata[];
43extern char iend[];
44#endif
45
46/* this is the codec entry point */ 36/* this is the codec entry point */
47enum codec_status codec_start(struct codec_api* api) 37enum codec_status codec_main(void)
48{ 38{
49 WavpackContext *wpc; 39 WavpackContext *wpc;
50 char error [80]; 40 char error [80];
@@ -52,13 +42,6 @@ enum codec_status codec_start(struct codec_api* api)
52 int retval; 42 int retval;
53 43
54 /* Generic codec initialisation */ 44 /* Generic codec initialisation */
55 ci = api;
56
57#ifdef USE_IRAM
58 ci->memcpy(iramstart, iramcopy, iramend-iramstart);
59 ci->memset(iedata, 0, iend - iedata);
60#endif
61
62 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); 45 ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
63 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); 46 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
64 47
@@ -66,7 +49,7 @@ enum codec_status codec_start(struct codec_api* api)
66 49
67 next_track: 50 next_track:
68 51
69 if (codec_init(api)) { 52 if (codec_init()) {
70 retval = CODEC_ERROR; 53 retval = CODEC_ERROR;
71 goto exit; 54 goto exit;
72 } 55 }
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 @@
24 24
25CODEC_ENC_HEADER 25CODEC_ENC_HEADER
26 26
27#ifdef USE_IRAM
28extern char iramcopy[];
29extern char iramstart[];
30extern char iramend[];
31extern char iedata[];
32extern char iend[];
33#endif
34
35/** Types **/ 27/** Types **/
36typedef struct 28typedef struct
37{ 29{
@@ -73,7 +65,6 @@ struct riff_header
73#define PCM_CHUNK_SIZE (4*PCM_SAMP_PER_CHUNK) 65#define PCM_CHUNK_SIZE (4*PCM_SAMP_PER_CHUNK)
74 66
75/** Data **/ 67/** Data **/
76static struct codec_api *ci;
77static int8_t input_buffer[PCM_CHUNK_SIZE*2] IBSS_ATTR; 68static int8_t input_buffer[PCM_CHUNK_SIZE*2] IBSS_ATTR;
78static WavpackConfig config IBSS_ATTR; 69static WavpackConfig config IBSS_ATTR;
79static WavpackContext *wpc; 70static WavpackContext *wpc;
@@ -381,17 +372,10 @@ static bool init_encoder(void)
381 return true; 372 return true;
382} /* init_encoder */ 373} /* init_encoder */
383 374
384enum codec_status codec_start(struct codec_api* api) 375enum codec_status codec_main(void)
385{ 376{
386 bool cpu_boosted; 377 bool cpu_boosted;
387 378
388 ci = api; /* copy to global api pointer */
389
390#ifdef USE_IRAM
391 ci->memcpy(iramstart, iramcopy, iramend - iramstart);
392 ci->memset(iedata, 0, iend - iedata);
393#endif
394
395 /* initialize params and config */ 379 /* initialize params and config */
396 if (!init_encoder()) 380 if (!init_encoder())
397 { 381 {
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,
699 audio_iram_steal(); 699 audio_iram_steal();
700 memcpy(iramstart, iramcopy, iram_size); 700 memcpy(iramstart, iramcopy, iram_size);
701 memset(iedata, 0, iedata_size); 701 memset(iedata, 0, iedata_size);
702 memset(iramcopy, 0, iram_size);
702} 703}
703#endif /* IRAM_STEAL */ 704#endif /* IRAM_STEAL */
704 705
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;
769/* this is the plugin entry point */ 769/* this is the plugin entry point */
770enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 770enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
771{ 771{
772 PLUGIN_IRAM_INIT(api)
773
772 rb = api; 774 rb = api;
773 (void)parameter; 775 (void)parameter;
774 776
@@ -778,8 +780,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
778 rb->cpu_boost(true); 780 rb->cpu_boost(true);
779#endif 781#endif
780 782
781 PLUGIN_IRAM_INIT(rb)
782
783 rb->lcd_setfont(0); 783 rb->lcd_setfont(0);
784 784
785#ifdef FANCY_MENU 785#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;
105enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 105enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
106{ 106{
107 int retval = 0; 107 int retval = 0;
108 rb = api;
109 108
109 PLUGIN_IRAM_INIT(api)
110
111 rb = api;
110 if(parameter == NULL) 112 if(parameter == NULL)
111 { 113 {
112 rb->splash(HZ*2, true, " Play .MID file "); 114 rb->splash(HZ*2, true, " Play .MID file ");
@@ -114,8 +116,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
114 } 116 }
115 rb->lcd_setfont(0); 117 rb->lcd_setfont(0);
116 118
117 PLUGIN_IRAM_INIT(rb)
118
119#if defined(HAVE_ADJUSTABLE_CPU_FREQ) 119#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
120 rb->cpu_boost(true); 120 rb->cpu_boost(true);
121#endif 121#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)
2364 int brate[] = { 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }; 2364 int brate[] = { 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 };
2365 2365
2366 (void)parameter; 2366 (void)parameter;
2367 rb = api; 2367
2368 PLUGIN_IRAM_INIT(api)
2368 2369
2369#ifdef CPU_COLDFIRE 2370#ifdef CPU_COLDFIRE
2370 asm volatile ("move.l #0, %macsr"); /* integer mode */ 2371 asm volatile ("move.l #0, %macsr"); /* integer mode */
2371#endif 2372#endif
2372 2373
2373 PLUGIN_IRAM_INIT(rb) 2374 rb = api;
2374
2375 rb->lcd_setfont(FONT_SYSFIXED); 2375 rb->lcd_setfont(FONT_SYSFIXED);
2376 2376
2377#ifdef HAVE_ADJUSTABLE_CPU_FREQ 2377#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)
297 uint8_t* buffer; 297 uint8_t* buffer;
298 size_t buffer_size; 298 size_t buffer_size;
299 299
300 rb = api;
301
302 /* This also stops audio playback - so we do it before using IRAM */ 300 /* This also stops audio playback - so we do it before using IRAM */
303 audiobuf = rb->plugin_get_audio_buffer(&audiosize); 301 audiobuf = api->plugin_get_audio_buffer(&audiosize);
302
303 PLUGIN_IRAM_INIT(api)
304 rb = api;
304 305
305 /* Initialise our malloc buffer */ 306 /* Initialise our malloc buffer */
306 mpeg2_alloc_init(audiobuf,audiosize); 307 mpeg2_alloc_init(audiobuf,audiosize);
@@ -312,8 +313,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
312 if (buffer == NULL) 313 if (buffer == NULL)
313 return PLUGIN_ERROR; 314 return PLUGIN_ERROR;
314 315
315 PLUGIN_IRAM_INIT(rb)
316
317 rb->lcd_set_backdrop(NULL); 316 rb->lcd_set_backdrop(NULL);
318 317
319#ifdef HAVE_LCD_COLOR 318#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)
364{ 364{
365 (void)parameter; 365 (void)parameter;
366 366
367 PLUGIN_IRAM_INIT(api)
367 rb = api; 368 rb = api;
368 369
369 PLUGIN_IRAM_INIT(rb)
370
371#ifdef HAVE_ADJUSTABLE_CPU_FREQ 370#ifdef HAVE_ADJUSTABLE_CPU_FREQ
372 rb->cpu_boost(true); 371 rb->cpu_boost(true);
373#endif 372#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
115 . = ALIGN(0x4); 115 . = ALIGN(0x4);
116 iend = .; 116 iend = .;
117 } > PLUGIN_IRAM 117 } > PLUGIN_IRAM
118
119 .bss ADDR(.data) + SIZEOF(.data) + SIZEOF(.iram):
120#else
121 .bss :
122#endif 118#endif
119
120 .bss (NOLOAD) :
123 { 121 {
122 plugin_bss_start = .;
124 *(.bss*) 123 *(.bss*)
125 *(COMMON) 124 *(COMMON)
126 . = ALIGN(0x4); 125 . = 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)
157/* this is the plugin entry point */ 157/* this is the plugin entry point */
158enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 158enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
159{ 159{
160 PLUGIN_IRAM_INIT(api)
161
160 /* if you are using a global api pointer, don't forget to copy it! 162 /* if you are using a global api pointer, don't forget to copy it!
161 otherwise you will get lovely "I04: IllInstr" errors... :-) */ 163 otherwise you will get lovely "I04: IllInstr" errors... :-) */
162 rb = api; 164 rb = api;
@@ -181,8 +183,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
181#endif 183#endif
182 setoptions(); 184 setoptions();
183 185
184 PLUGIN_IRAM_INIT(rb)
185
186 shut=0; 186 shut=0;
187 cleanshut=0; 187 cleanshut=0;
188 188
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;
61enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 61enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
62{ 62{
63 63
64 rb = api;
65#if CODEC == SWCODEC && !defined SIMULATOR 64#if CODEC == SWCODEC && !defined SIMULATOR
66 rb->pcm_play_stop(); 65 api->pcm_play_stop();
67#endif 66#endif
67
68 PLUGIN_IRAM_INIT(api)
69
70 rb = api;
68 rb->lcd_set_backdrop(NULL); 71 rb->lcd_set_backdrop(NULL);
69 rb->splash(HZ, true, "Welcome to ZXBox"); 72 rb->splash(HZ, true, "Welcome to ZXBox");
70 73
71 PLUGIN_IRAM_INIT(rb)
72 74
73 sp_init(); 75 sp_init();
74 76