summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/a52towav.c10
-rw-r--r--apps/plugins/lib/SOURCES3
-rw-r--r--apps/plugins/lib/xxx2wav.c (renamed from apps/plugins/xxx2wav.h)109
-rw-r--r--apps/plugins/lib/xxx2wav.h55
-rw-r--r--apps/plugins/mpa2wav.c8
5 files changed, 112 insertions, 73 deletions
diff --git a/apps/plugins/a52towav.c b/apps/plugins/a52towav.c
index 3e81c9db0c..f62106a8c3 100644
--- a/apps/plugins/a52towav.c
+++ b/apps/plugins/a52towav.c
@@ -27,11 +27,9 @@
27#include <codecs/liba52/config.h> 27#include <codecs/liba52/config.h>
28#include <codecs/liba52/a52.h> 28#include <codecs/liba52/a52.h>
29 29
30static struct plugin_api* rb; 30#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
31
32/* Helper functions common to all decoder test viewers (uses rb) */
33 31
34#include "xxx2wav.h" 32static struct plugin_api* rb;
35 33
36/* FIX: We can remove this warning when the build system has a 34/* FIX: We can remove this warning when the build system has a
37 mechanism for auto-detecting the endianness of the target CPU - 35 mechanism for auto-detecting the endianness of the target CPU -
@@ -167,6 +165,8 @@ void a52_decode_data (file_info_struct* file_info, uint8_t * start, uint8_t * en
167/* this is the plugin entry point */ 165/* this is the plugin entry point */
168enum plugin_status plugin_start(struct plugin_api* api, void* file) 166enum plugin_status plugin_start(struct plugin_api* api, void* file)
169{ 167{
168 file_info_struct file_info;
169
170 /* Generic plugin initialisation */ 170 /* Generic plugin initialisation */
171 171
172 TEST_PLUGIN_API(api); 172 TEST_PLUGIN_API(api);
@@ -175,7 +175,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file)
175 175
176 /* This function sets up the buffers and reads the file into RAM */ 176 /* This function sets up the buffers and reads the file into RAM */
177 177
178 if (local_init(file,"/ac3test.wav",&file_info)) { 178 if (local_init(file,"/ac3test.wav",&file_info,api)) {
179 return PLUGIN_ERROR; 179 return PLUGIN_ERROR;
180 } 180 }
181 181
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index 8bd47a25b0..0e8e14cbdf 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -33,3 +33,6 @@ gray_verline.c
33#ifdef HAVE_LCD_CHARCELLS 33#ifdef HAVE_LCD_CHARCELLS
34playergfx.c 34playergfx.c
35#endif 35#endif
36#if CONFIG_HWCODEC == MASNONE /* software codec platforms */
37xxx2wav.c
38#endif
diff --git a/apps/plugins/xxx2wav.h b/apps/plugins/lib/xxx2wav.c
index 1b93cf9d31..92b7050f6d 100644
--- a/apps/plugins/xxx2wav.h
+++ b/apps/plugins/lib/xxx2wav.c
@@ -17,30 +17,12 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20/* Various "helper functions" common to all the xxx2wav decoder plugins 20/* Various "helper functions" common to all the xxx2wav decoder plugins */
21 21
22 We include them as a .h because the plugin build system links 22#include "plugin.h"
23 exactly one .c file with exactly one .rock file. 23#include "xxx2wav.h"
24 */
25 24
26 25static struct plugin_api* local_rb;
27/* the main data structure of the program */
28typedef struct {
29 int infile;
30 int outfile;
31 off_t curpos;
32 off_t filesize;
33 int samplerate;
34 int channels;
35 int frames_decoded;
36 unsigned long total_samples;
37 unsigned long current_sample;
38 unsigned long start_tick;
39} file_info_struct;
40
41file_info_struct file_info;
42
43#define MALLOC_BUFSIZE (512*1024)
44 26
45int mem_ptr; 27int mem_ptr;
46int bufsize; 28int bufsize;
@@ -55,16 +37,16 @@ void* malloc(size_t size) {
55 x=&mallocbuf[mem_ptr]; 37 x=&mallocbuf[mem_ptr];
56 mem_ptr+=size+(size%4); // Keep memory 32-bit aligned (if it was already?) 38 mem_ptr+=size+(size%4); // Keep memory 32-bit aligned (if it was already?)
57 39
58 rb->snprintf(s,30,"Memory used: %d",mem_ptr); 40 local_rb->snprintf(s,30,"Memory used: %d",mem_ptr);
59 rb->lcd_putsxy(0,80,s); 41 local_rb->lcd_putsxy(0,80,s);
60 rb->lcd_update(); 42 local_rb->lcd_update();
61 return(x); 43 return(x);
62} 44}
63 45
64void* calloc(size_t nmemb, size_t size) { 46void* calloc(size_t nmemb, size_t size) {
65 void* x; 47 void* x;
66 x=malloc(nmemb*size); 48 x=malloc(nmemb*size);
67 rb->memset(x,0,nmemb*size); 49 local_rb->memset(x,0,nmemb*size);
68 return(x); 50 return(x);
69} 51}
70 52
@@ -80,15 +62,15 @@ void* realloc(void* ptr, size_t size) {
80} 62}
81 63
82void *memcpy(void *dest, const void *src, size_t n) { 64void *memcpy(void *dest, const void *src, size_t n) {
83 return(rb->memcpy(dest,src,n)); 65 return(local_rb->memcpy(dest,src,n));
84} 66}
85 67
86void *memset(void *s, int c, size_t n) { 68void *memset(void *s, int c, size_t n) {
87 return(rb->memset(s,c,n)); 69 return(local_rb->memset(s,c,n));
88} 70}
89 71
90int memcmp(const void *s1, const void *s2, size_t n) { 72int memcmp(const void *s1, const void *s2, size_t n) {
91 return(rb->memcmp(s1,s2,n)); 73 return(local_rb->memcmp(s1,s2,n));
92} 74}
93 75
94void* memmove(const void *s1, const void *s2, size_t n) { 76void* memmove(const void *s1, const void *s2, size_t n) {
@@ -102,7 +84,7 @@ void* memmove(const void *s1, const void *s2, size_t n) {
102} 84}
103 85
104void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) { 86void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) {
105 rb->qsort(base,nmemb,size,compar); 87 local_rb->qsort(base,nmemb,size,compar);
106} 88}
107 89
108void display_status(file_info_struct* file_info) { 90void display_status(file_info_struct* file_info) {
@@ -111,14 +93,14 @@ void display_status(file_info_struct* file_info) {
111 unsigned long long speed; 93 unsigned long long speed;
112 unsigned long xspeed; 94 unsigned long xspeed;
113 95
114 rb->snprintf(s,32,"Bytes read: %d",file_info->curpos); 96 local_rb->snprintf(s,32,"Bytes read: %d",file_info->curpos);
115 rb->lcd_putsxy(0,0,s); 97 local_rb->lcd_putsxy(0,0,s);
116 rb->snprintf(s,32,"Samples Decoded: %d",file_info->current_sample); 98 local_rb->snprintf(s,32,"Samples Decoded: %d",file_info->current_sample);
117 rb->lcd_putsxy(0,20,s); 99 local_rb->lcd_putsxy(0,20,s);
118 rb->snprintf(s,32,"Frames Decoded: %d",file_info->frames_decoded); 100 local_rb->snprintf(s,32,"Frames Decoded: %d",file_info->frames_decoded);
119 rb->lcd_putsxy(0,40,s); 101 local_rb->lcd_putsxy(0,40,s);
120 102
121 ticks_taken=*(rb->current_tick)-file_info->start_tick; 103 ticks_taken=*(local_rb->current_tick)-file_info->start_tick;
122 104
123 /* e.g.: 105 /* e.g.:
124 ticks_taken=500 106 ticks_taken=500
@@ -132,10 +114,10 @@ void display_status(file_info_struct* file_info) {
132 114
133 speed=(100*file_info->current_sample)/file_info->samplerate; 115 speed=(100*file_info->current_sample)/file_info->samplerate;
134 xspeed=(speed*10000)/ticks_taken; 116 xspeed=(speed*10000)/ticks_taken;
135 rb->snprintf(s,32,"Speed %ld.%02ld %% Secs: %d",(xspeed/100),(xspeed%100),ticks_taken/100); 117 local_rb->snprintf(s,32,"Speed %ld.%02ld %% Secs: %d",(xspeed/100),(xspeed%100),ticks_taken/100);
136 rb->lcd_putsxy(0,60,s); 118 local_rb->lcd_putsxy(0,60,s);
137 119
138 rb->lcd_update(); 120 local_rb->lcd_update();
139} 121}
140 122
141static unsigned char wav_header[44]={'R','I','F','F', // 0 - ChunkID 123static unsigned char wav_header[44]={'R','I','F','F', // 0 - ChunkID
@@ -154,59 +136,61 @@ static unsigned char wav_header[44]={'R','I','F','F', // 0 - ChunkID
154 }; 136 };
155 137
156 138
157int local_init(char* infilename, char* outfilename, file_info_struct* file_info) { 139int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb) {
158 char s[32]; 140 char s[32];
159 int i,n,bytesleft; 141 int i,n,bytesleft;
160 142
143 local_rb=rb;
144
161 mem_ptr=0; 145 mem_ptr=0;
162 mp3buf=rb->plugin_get_mp3_buffer(&bufsize); 146 mp3buf=local_rb->plugin_get_mp3_buffer(&bufsize);
163 mallocbuf=mp3buf; 147 mallocbuf=mp3buf;
164 filebuf=&mp3buf[MALLOC_BUFSIZE]; 148 filebuf=&mp3buf[MALLOC_BUFSIZE];
165 149
166 rb->snprintf(s,32,"mp3 bufsize: %d",bufsize); 150 local_rb->snprintf(s,32,"mp3 bufsize: %d",bufsize);
167 rb->lcd_putsxy(0,100,s); 151 local_rb->lcd_putsxy(0,100,s);
168 rb->lcd_update(); 152 local_rb->lcd_update();
169 153
170 file_info->infile=rb->open(infilename,O_RDONLY); 154 file_info->infile=local_rb->open(infilename,O_RDONLY);
171 file_info->outfile=rb->creat(outfilename,O_WRONLY); 155 file_info->outfile=local_rb->creat(outfilename,O_WRONLY);
172 rb->write(file_info->outfile,wav_header,sizeof(wav_header)); 156 local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
173 file_info->curpos=0; 157 file_info->curpos=0;
174 file_info->current_sample=0; 158 file_info->current_sample=0;
175 file_info->frames_decoded=0; 159 file_info->frames_decoded=0;
176 file_info->filesize=rb->filesize(file_info->infile); 160 file_info->filesize=local_rb->filesize(file_info->infile);
177 161
178 if (file_info->filesize > (bufsize-MALLOC_BUFSIZE)) { 162 if (file_info->filesize > (bufsize-MALLOC_BUFSIZE)) {
179 rb->close(file_info->infile); 163 local_rb->close(file_info->infile);
180 rb->splash(HZ*2, true, "File too large"); 164 local_rb->splash(HZ*2, true, "File too large");
181 return(1); 165 return(1);
182 } 166 }
183 167
184 rb->snprintf(s,32,"Loading file..."); 168 local_rb->snprintf(s,32,"Loading file...");
185 rb->lcd_putsxy(0,0,s); 169 local_rb->lcd_putsxy(0,0,s);
186 rb->lcd_update(); 170 local_rb->lcd_update();
187 171
188 bytesleft=file_info->filesize; 172 bytesleft=file_info->filesize;
189 i=0; 173 i=0;
190 while (bytesleft > 0) { 174 while (bytesleft > 0) {
191 n=rb->read(file_info->infile,&filebuf[i],bytesleft); 175 n=local_rb->read(file_info->infile,&filebuf[i],bytesleft);
192 if (n < 0) { 176 if (n < 0) {
193 rb->close(file_info->infile); 177 local_rb->close(file_info->infile);
194 rb->splash(HZ*2, true, "ERROR READING FILE"); 178 local_rb->splash(HZ*2, true, "ERROR READING FILE");
195 return(1); 179 return(1);
196 } 180 }
197 i+=n; bytesleft-=n; 181 i+=n; bytesleft-=n;
198 } 182 }
199 rb->close(file_info->infile); 183 local_rb->close(file_info->infile);
200 return(0); 184 return(0);
201} 185}
202 186
203void close_wav(file_info_struct* file_info) { 187void close_wav(file_info_struct* file_info) {
204 int x; 188 int x;
205 int filesize=rb->filesize(file_info->outfile); 189 int filesize=local_rb->filesize(file_info->outfile);
206 190
207 /* We assume 16-bit, Stereo */ 191 /* We assume 16-bit, Stereo */
208 192
209 rb->lseek(file_info->outfile,0,SEEK_SET); 193 local_rb->lseek(file_info->outfile,0,SEEK_SET);
210 194
211 // ChunkSize 195 // ChunkSize
212 x=filesize-8; 196 x=filesize-8;
@@ -235,7 +219,6 @@ void close_wav(file_info_struct* file_info) {
235 wav_header[42]=(x&0xff0000)>>16; 219 wav_header[42]=(x&0xff0000)>>16;
236 wav_header[43]=(x&0xff000000)>>24; 220 wav_header[43]=(x&0xff000000)>>24;
237 221
238 rb->write(file_info->outfile,wav_header,sizeof(wav_header)); 222 local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
239 rb->close(file_info->outfile); 223 local_rb->close(file_info->outfile);
240} 224}
241
diff --git a/apps/plugins/lib/xxx2wav.h b/apps/plugins/lib/xxx2wav.h
new file mode 100644
index 0000000000..27e293f797
--- /dev/null
+++ b/apps/plugins/lib/xxx2wav.h
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Dave Chapman
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/* Various "helper functions" common to all the xxx2wav decoder plugins */
21
22/* the main data structure of the program */
23typedef struct {
24 int infile;
25 int outfile;
26 off_t curpos;
27 off_t filesize;
28 int samplerate;
29 int channels;
30 int frames_decoded;
31 unsigned long total_samples;
32 unsigned long current_sample;
33 unsigned long start_tick;
34} file_info_struct;
35
36#define MALLOC_BUFSIZE (512*1024)
37
38extern int mem_ptr;
39extern int bufsize;
40extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox
41extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
42extern unsigned char* filebuf; // The rest of the MP3 buffer
43
44void* malloc(size_t size);
45void* calloc(size_t nmemb, size_t size);
46void free(void* ptr);
47void* realloc(void* ptr, size_t size);
48void *memcpy(void *dest, const void *src, size_t n);
49void *memset(void *s, int c, size_t n);
50int memcmp(const void *s1, const void *s2, size_t n);
51void* memmove(const void *s1, const void *s2, size_t n);
52
53void display_status(file_info_struct* file_info);
54int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb);
55void close_wav(file_info_struct* file_info);
diff --git a/apps/plugins/mpa2wav.c b/apps/plugins/mpa2wav.c
index 2f1f329275..a4fbf79605 100644
--- a/apps/plugins/mpa2wav.c
+++ b/apps/plugins/mpa2wav.c
@@ -24,11 +24,9 @@
24 24
25#include <codecs/libmad/mad.h> 25#include <codecs/libmad/mad.h>
26 26
27static struct plugin_api* rb; 27#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
28
29/* Helper functions common to all decoder test viewers (uses rb) */
30 28
31#include "xxx2wav.h" 29static struct plugin_api* rb;
32 30
33struct mad_stream Stream; 31struct mad_stream Stream;
34struct mad_frame Frame; 32struct mad_frame Frame;
@@ -149,7 +147,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file)
149 147
150 /* This function sets up the buffers and reads the file into RAM */ 148 /* This function sets up the buffers and reads the file into RAM */
151 149
152 if (local_init(file,"/libmadtest.wav",&file_info)) { 150 if (local_init(file,"/libmadtest.wav",&file_info,api)) {
153 return PLUGIN_ERROR; 151 return PLUGIN_ERROR;
154 } 152 }
155 153