diff options
author | Dave Chapman <dave@dchapman.com> | 2005-02-16 18:51:21 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2005-02-16 18:51:21 +0000 |
commit | 9b32a1988f848145d96ba2be8cba86e837196df3 (patch) | |
tree | 006a5e22ffbc054a1504f69c14567ad6e7707236 /apps/plugins/lib | |
parent | 711f763a127b5be80018c49db333841178103913 (diff) | |
download | rockbox-9b32a1988f848145d96ba2be8cba86e837196df3.tar.gz rockbox-9b32a1988f848145d96ba2be8cba86e837196df3.zip |
Move contents of plugins/xxx2wav.h into the plugin library
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5982 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/SOURCES | 3 | ||||
-rw-r--r-- | apps/plugins/lib/xxx2wav.c | 224 | ||||
-rw-r--r-- | apps/plugins/lib/xxx2wav.h | 55 |
3 files changed, 282 insertions, 0 deletions
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 |
34 | playergfx.c | 34 | playergfx.c |
35 | #endif | 35 | #endif |
36 | #if CONFIG_HWCODEC == MASNONE /* software codec platforms */ | ||
37 | xxx2wav.c | ||
38 | #endif | ||
diff --git a/apps/plugins/lib/xxx2wav.c b/apps/plugins/lib/xxx2wav.c new file mode 100644 index 0000000000..92b7050f6d --- /dev/null +++ b/apps/plugins/lib/xxx2wav.c | |||
@@ -0,0 +1,224 @@ | |||
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 | #include "plugin.h" | ||
23 | #include "xxx2wav.h" | ||
24 | |||
25 | static struct plugin_api* local_rb; | ||
26 | |||
27 | int mem_ptr; | ||
28 | int bufsize; | ||
29 | unsigned char* mp3buf; // The actual MP3 buffer from Rockbox | ||
30 | unsigned char* mallocbuf; // 512K from the start of MP3 buffer | ||
31 | unsigned char* filebuf; // The rest of the MP3 buffer | ||
32 | |||
33 | void* malloc(size_t size) { | ||
34 | void* x; | ||
35 | char s[32]; | ||
36 | |||
37 | x=&mallocbuf[mem_ptr]; | ||
38 | mem_ptr+=size+(size%4); // Keep memory 32-bit aligned (if it was already?) | ||
39 | |||
40 | local_rb->snprintf(s,30,"Memory used: %d",mem_ptr); | ||
41 | local_rb->lcd_putsxy(0,80,s); | ||
42 | local_rb->lcd_update(); | ||
43 | return(x); | ||
44 | } | ||
45 | |||
46 | void* calloc(size_t nmemb, size_t size) { | ||
47 | void* x; | ||
48 | x=malloc(nmemb*size); | ||
49 | local_rb->memset(x,0,nmemb*size); | ||
50 | return(x); | ||
51 | } | ||
52 | |||
53 | void free(void* ptr) { | ||
54 | (void)ptr; | ||
55 | } | ||
56 | |||
57 | void* realloc(void* ptr, size_t size) { | ||
58 | void* x; | ||
59 | (void)ptr; | ||
60 | x=malloc(size); | ||
61 | return(x); | ||
62 | } | ||
63 | |||
64 | void *memcpy(void *dest, const void *src, size_t n) { | ||
65 | return(local_rb->memcpy(dest,src,n)); | ||
66 | } | ||
67 | |||
68 | void *memset(void *s, int c, size_t n) { | ||
69 | return(local_rb->memset(s,c,n)); | ||
70 | } | ||
71 | |||
72 | int memcmp(const void *s1, const void *s2, size_t n) { | ||
73 | return(local_rb->memcmp(s1,s2,n)); | ||
74 | } | ||
75 | |||
76 | void* memmove(const void *s1, const void *s2, size_t n) { | ||
77 | char* dest=(char*)s1; | ||
78 | char* src=(char*)s2; | ||
79 | size_t i; | ||
80 | |||
81 | for (i=0;i<n;i++) { dest[i]=src[i]; } | ||
82 | // while(n>0) { *(dest++)=*(src++); n--; } | ||
83 | return(dest); | ||
84 | } | ||
85 | |||
86 | void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) { | ||
87 | local_rb->qsort(base,nmemb,size,compar); | ||
88 | } | ||
89 | |||
90 | void display_status(file_info_struct* file_info) { | ||
91 | char s[32]; | ||
92 | unsigned long ticks_taken; | ||
93 | unsigned long long speed; | ||
94 | unsigned long xspeed; | ||
95 | |||
96 | local_rb->snprintf(s,32,"Bytes read: %d",file_info->curpos); | ||
97 | local_rb->lcd_putsxy(0,0,s); | ||
98 | local_rb->snprintf(s,32,"Samples Decoded: %d",file_info->current_sample); | ||
99 | local_rb->lcd_putsxy(0,20,s); | ||
100 | local_rb->snprintf(s,32,"Frames Decoded: %d",file_info->frames_decoded); | ||
101 | local_rb->lcd_putsxy(0,40,s); | ||
102 | |||
103 | ticks_taken=*(local_rb->current_tick)-file_info->start_tick; | ||
104 | |||
105 | /* e.g.: | ||
106 | ticks_taken=500 | ||
107 | sam_fmt.rate=44,100 | ||
108 | samples_decoded=172,400 | ||
109 | (samples_decoded/sam_fmt.rate)*100=400 (time it should have taken) | ||
110 | % Speed=(400/500)*100=80% | ||
111 | */ | ||
112 | |||
113 | if (ticks_taken==0) { ticks_taken=1; } // Avoid fp exception. | ||
114 | |||
115 | speed=(100*file_info->current_sample)/file_info->samplerate; | ||
116 | xspeed=(speed*10000)/ticks_taken; | ||
117 | local_rb->snprintf(s,32,"Speed %ld.%02ld %% Secs: %d",(xspeed/100),(xspeed%100),ticks_taken/100); | ||
118 | local_rb->lcd_putsxy(0,60,s); | ||
119 | |||
120 | local_rb->lcd_update(); | ||
121 | } | ||
122 | |||
123 | static unsigned char wav_header[44]={'R','I','F','F', // 0 - ChunkID | ||
124 | 0,0,0,0, // 4 - ChunkSize (filesize-8) | ||
125 | 'W','A','V','E', // 8 - Format | ||
126 | 'f','m','t',' ', // 12 - SubChunkID | ||
127 | 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM | ||
128 | 1,0, // 20 - AudioFormat (1=16-bit) | ||
129 | 2,0, // 22 - NumChannels | ||
130 | 0,0,0,0, // 24 - SampleRate in Hz | ||
131 | 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8) | ||
132 | 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8) | ||
133 | 16,0, // 34 - BitsPerSample | ||
134 | 'd','a','t','a', // 36 - Subchunk2ID | ||
135 | 0,0,0,0 // 40 - Subchunk2Size | ||
136 | }; | ||
137 | |||
138 | |||
139 | int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb) { | ||
140 | char s[32]; | ||
141 | int i,n,bytesleft; | ||
142 | |||
143 | local_rb=rb; | ||
144 | |||
145 | mem_ptr=0; | ||
146 | mp3buf=local_rb->plugin_get_mp3_buffer(&bufsize); | ||
147 | mallocbuf=mp3buf; | ||
148 | filebuf=&mp3buf[MALLOC_BUFSIZE]; | ||
149 | |||
150 | local_rb->snprintf(s,32,"mp3 bufsize: %d",bufsize); | ||
151 | local_rb->lcd_putsxy(0,100,s); | ||
152 | local_rb->lcd_update(); | ||
153 | |||
154 | file_info->infile=local_rb->open(infilename,O_RDONLY); | ||
155 | file_info->outfile=local_rb->creat(outfilename,O_WRONLY); | ||
156 | local_rb->write(file_info->outfile,wav_header,sizeof(wav_header)); | ||
157 | file_info->curpos=0; | ||
158 | file_info->current_sample=0; | ||
159 | file_info->frames_decoded=0; | ||
160 | file_info->filesize=local_rb->filesize(file_info->infile); | ||
161 | |||
162 | if (file_info->filesize > (bufsize-MALLOC_BUFSIZE)) { | ||
163 | local_rb->close(file_info->infile); | ||
164 | local_rb->splash(HZ*2, true, "File too large"); | ||
165 | return(1); | ||
166 | } | ||
167 | |||
168 | local_rb->snprintf(s,32,"Loading file..."); | ||
169 | local_rb->lcd_putsxy(0,0,s); | ||
170 | local_rb->lcd_update(); | ||
171 | |||
172 | bytesleft=file_info->filesize; | ||
173 | i=0; | ||
174 | while (bytesleft > 0) { | ||
175 | n=local_rb->read(file_info->infile,&filebuf[i],bytesleft); | ||
176 | if (n < 0) { | ||
177 | local_rb->close(file_info->infile); | ||
178 | local_rb->splash(HZ*2, true, "ERROR READING FILE"); | ||
179 | return(1); | ||
180 | } | ||
181 | i+=n; bytesleft-=n; | ||
182 | } | ||
183 | local_rb->close(file_info->infile); | ||
184 | return(0); | ||
185 | } | ||
186 | |||
187 | void close_wav(file_info_struct* file_info) { | ||
188 | int x; | ||
189 | int filesize=local_rb->filesize(file_info->outfile); | ||
190 | |||
191 | /* We assume 16-bit, Stereo */ | ||
192 | |||
193 | local_rb->lseek(file_info->outfile,0,SEEK_SET); | ||
194 | |||
195 | // ChunkSize | ||
196 | x=filesize-8; | ||
197 | wav_header[4]=(x&0xff); | ||
198 | wav_header[5]=(x&0xff00)>>8; | ||
199 | wav_header[6]=(x&0xff0000)>>16; | ||
200 | wav_header[7]=(x&0xff000000)>>24; | ||
201 | |||
202 | // Samplerate | ||
203 | wav_header[24]=file_info->samplerate&0xff; | ||
204 | wav_header[25]=(file_info->samplerate&0xff00)>>8; | ||
205 | wav_header[26]=(file_info->samplerate&0xff0000)>>16; | ||
206 | wav_header[27]=(file_info->samplerate&0xff000000)>>24; | ||
207 | |||
208 | // ByteRate | ||
209 | x=file_info->samplerate*4; | ||
210 | wav_header[28]=(x&0xff); | ||
211 | wav_header[29]=(x&0xff00)>>8; | ||
212 | wav_header[30]=(x&0xff0000)>>16; | ||
213 | wav_header[31]=(x&0xff000000)>>24; | ||
214 | |||
215 | // Subchunk2Size | ||
216 | x=filesize-44; | ||
217 | wav_header[40]=(x&0xff); | ||
218 | wav_header[41]=(x&0xff00)>>8; | ||
219 | wav_header[42]=(x&0xff0000)>>16; | ||
220 | wav_header[43]=(x&0xff000000)>>24; | ||
221 | |||
222 | local_rb->write(file_info->outfile,wav_header,sizeof(wav_header)); | ||
223 | local_rb->close(file_info->outfile); | ||
224 | } | ||
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 */ | ||
23 | typedef 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 | |||
38 | extern int mem_ptr; | ||
39 | extern int bufsize; | ||
40 | extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox | ||
41 | extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer | ||
42 | extern unsigned char* filebuf; // The rest of the MP3 buffer | ||
43 | |||
44 | void* malloc(size_t size); | ||
45 | void* calloc(size_t nmemb, size_t size); | ||
46 | void free(void* ptr); | ||
47 | void* realloc(void* ptr, size_t size); | ||
48 | void *memcpy(void *dest, const void *src, size_t n); | ||
49 | void *memset(void *s, int c, size_t n); | ||
50 | int memcmp(const void *s1, const void *s2, size_t n); | ||
51 | void* memmove(const void *s1, const void *s2, size_t n); | ||
52 | |||
53 | void display_status(file_info_struct* file_info); | ||
54 | int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb); | ||
55 | void close_wav(file_info_struct* file_info); | ||