summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/mpa2wav.c52
1 files changed, 15 insertions, 37 deletions
diff --git a/apps/plugins/mpa2wav.c b/apps/plugins/mpa2wav.c
index 5ef6351a85..5a261d2b67 100644
--- a/apps/plugins/mpa2wav.c
+++ b/apps/plugins/mpa2wav.c
@@ -130,6 +130,9 @@ unsigned char *OutputPtr=OutputBuffer;
130unsigned char *GuardPtr=NULL; 130unsigned char *GuardPtr=NULL;
131const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE; 131const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
132 132
133mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
134unsigned char mad_main_data[MAD_BUFFER_MDLEN] IDATA_ATTR;
135
133#ifdef USE_IRAM 136#ifdef USE_IRAM
134extern char iramcopy[]; 137extern char iramcopy[];
135extern char iramstart[]; 138extern char iramstart[];
@@ -168,7 +171,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file)
168 mad_synth_init(&Synth); 171 mad_synth_init(&Synth);
169 mad_timer_reset(&Timer); 172 mad_timer_reset(&Timer);
170 173
171 //if error: return PLUGIN_ERROR; 174 /* We do this so libmad doesn't try to call codec_calloc() */
175 memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
176 Frame.overlap = &mad_frame_overlap;
177 Stream.main_data = &mad_main_data;
178
179 GuardPtr = &filebuf[file_info.filesize];
180 memset(GuardPtr,0,MAD_BUFFER_GUARD);
181 mad_stream_buffer(&Stream, filebuf,file_info.filesize);
172 182
173 file_info.curpos=0; 183 file_info.curpos=0;
174 file_info.start_tick=*(rb->current_tick); 184 file_info.start_tick=*(rb->current_tick);
@@ -176,42 +186,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file)
176 rb->button_clear_queue(); 186 rb->button_clear_queue();
177 187
178 /* This is the decoding loop. */ 188 /* This is the decoding loop. */
179 while (file_info.curpos < file_info.filesize) { 189 while (file_info.curpos < file_info.filesize &&
180 if(Stream.buffer==NULL || Stream.error==MAD_ERROR_BUFLEN) { 190 Stream.this_frame != GuardPtr &&
181 if(Stream.next_frame!=NULL) { 191 Stream.error != MAD_ERROR_BUFLEN) {
182 Remaining=Stream.bufend-Stream.next_frame; 192 file_info.curpos += (int)Stream.next_frame - (int)Stream.this_frame;
183 memmove(InputBuffer,Stream.next_frame,Remaining);
184 ReadStart=InputBuffer+Remaining;
185 ReadSize=INPUT_BUFFER_SIZE-Remaining;
186 } else {
187 ReadSize=INPUT_BUFFER_SIZE;
188 ReadStart=InputBuffer;
189 Remaining=0;
190 }
191
192 /* Fill-in the buffer. If an error occurs print a message
193 * and leave the decoding loop. If the end of stream is
194 * reached we also leave the loop but the return status is
195 * left untouched.
196 */
197
198 if ((file_info.filesize-file_info.curpos) < (int) ReadSize) {
199 ReadSize=file_info.filesize-file_info.curpos;
200 }
201 memcpy(ReadStart,&filebuf[file_info.curpos],ReadSize);
202 file_info.curpos+=ReadSize;
203
204 if (file_info.curpos >= file_info.filesize)
205 {
206 GuardPtr=ReadStart+ReadSize;
207 memset(GuardPtr,0,MAD_BUFFER_GUARD);
208 ReadSize+=MAD_BUFFER_GUARD;
209 }
210
211 /* Pipe the new buffer content to libmad's stream decoder facility */
212 mad_stream_buffer(&Stream,InputBuffer,ReadSize+Remaining);
213 Stream.error=0;
214 }
215 193
216 if(mad_frame_decode(&Frame,&Stream)) 194 if(mad_frame_decode(&Frame,&Stream))
217 { 195 {