summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2008-09-20 22:06:12 +0000
committerMichael Giacomelli <giac2000@hotmail.com>2008-09-20 22:06:12 +0000
commit4e36a2b991d58a40d7ea12c9bf41e93736b8b024 (patch)
treee26deeca8209a689bfebfcca18c4dad028d70260
parent3d0d6d6bb25eb933d60ca5451b170eaae17dbb65 (diff)
downloadrockbox-4e36a2b991d58a40d7ea12c9bf41e93736b8b024.tar.gz
rockbox-4e36a2b991d58a40d7ea12c9bf41e93736b8b024.zip
Commit FS#9318 - MP3 synthesis filter on COP. Loads the MP3 synth filer on to the CoProcessor on all PortalPlayer devices, resulting in an ~90% speedup according to test_codec on the Sansa. Real world improvement is somewhat less, but still considerable. Allows MP3 decoding at 30MHz without boosting, or use of more DSP/EQ with less boosting/skipping, thus improving battery life. Minor changes to mpegplayer to retain compatibility with libmad changes. Should be no significant changes for other targets or codecs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18557 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libmad/frame.c9
-rw-r--r--apps/codecs/libmad/frame.h15
-rw-r--r--apps/codecs/libmad/layer12.c16
-rw-r--r--apps/codecs/libmad/layer3.c2
-rw-r--r--apps/codecs/libmad/mad.h7
-rw-r--r--apps/codecs/libmad/synth.c14
-rw-r--r--apps/codecs/mpa.c142
-rw-r--r--apps/plugins/mpegplayer/Makefile2
-rw-r--r--apps/plugins/mpegplayer/audio_thread.c7
9 files changed, 181 insertions, 33 deletions
diff --git a/apps/codecs/libmad/frame.c b/apps/codecs/libmad/frame.c
index 91cf2f9a15..2c7fdca199 100644
--- a/apps/codecs/libmad/frame.c
+++ b/apps/codecs/libmad/frame.c
@@ -31,6 +31,7 @@
31# include "timer.h" 31# include "timer.h"
32# include "layer12.h" 32# include "layer12.h"
33# include "layer3.h" 33# include "layer3.h"
34# include "../lib/codeclib.h"
34 35
35static 36static
36unsigned long const bitrate_table[5][15] = { 37unsigned long const bitrate_table[5][15] = {
@@ -467,7 +468,9 @@ int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream)
467 468
468 mad_bit_finish(&next_frame); 469 mad_bit_finish(&next_frame);
469 } 470 }
470 471
472
473
471 return 0; 474 return 0;
472 475
473 fail: 476 fail:
@@ -485,8 +488,8 @@ void mad_frame_mute(struct mad_frame *frame)
485 488
486 for (s = 0; s < 36; ++s) { 489 for (s = 0; s < 36; ++s) {
487 for (sb = 0; sb < 32; ++sb) { 490 for (sb = 0; sb < 32; ++sb) {
488 frame->sbsample[0][s][sb] = 491 (*frame->sbsample)[0][s][sb] =
489 frame->sbsample[1][s][sb] = 0; 492 (*frame->sbsample)[1][s][sb] = 0;
490 } 493 }
491 } 494 }
492 495
diff --git a/apps/codecs/libmad/frame.h b/apps/codecs/libmad/frame.h
index dce573d021..d2d6dca3ef 100644
--- a/apps/codecs/libmad/frame.h
+++ b/apps/codecs/libmad/frame.h
@@ -65,12 +65,15 @@ struct mad_header {
65}; 65};
66 66
67struct mad_frame { 67struct mad_frame {
68 struct mad_header header; /* MPEG audio header */ 68 struct mad_header header; /* MPEG audio header */
69 69 int options; /* decoding options (from stream) */
70 int options; /* decoding options (from stream) */ 70
71 71 mad_fixed_t (*sbsample)[2][36][32]; /* synthesis subband filter samples */
72 mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples */ 72 mad_fixed_t (*sbsample_prev)[2][36][32]; /* synthesis subband filter samples
73 mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */ 73 from previous frame only needed
74 when synthesis is on cop */
75
76 mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */
74}; 77};
75 78
76# define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1) 79# define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1)
diff --git a/apps/codecs/libmad/layer12.c b/apps/codecs/libmad/layer12.c
index c71c005cf5..ccac392b42 100644
--- a/apps/codecs/libmad/layer12.c
+++ b/apps/codecs/libmad/layer12.c
@@ -185,7 +185,7 @@ int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame)
185 for (sb = 0; sb < bound; ++sb) { 185 for (sb = 0; sb < bound; ++sb) {
186 for (ch = 0; ch < nch; ++ch) { 186 for (ch = 0; ch < nch; ++ch) {
187 nb = allocation[ch][sb]; 187 nb = allocation[ch][sb];
188 frame->sbsample[ch][s][sb] = nb ? 188 (*frame->sbsample)[ch][s][sb] = nb ?
189 mad_f_mul(I_sample(&stream->ptr, nb), 189 mad_f_mul(I_sample(&stream->ptr, nb),
190 sf_table[scalefactor[ch][sb]]) : 0; 190 sf_table[scalefactor[ch][sb]]) : 0;
191 } 191 }
@@ -198,13 +198,13 @@ int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame)
198 sample = I_sample(&stream->ptr, nb); 198 sample = I_sample(&stream->ptr, nb);
199 199
200 for (ch = 0; ch < nch; ++ch) { 200 for (ch = 0; ch < nch; ++ch) {
201 frame->sbsample[ch][s][sb] = 201 (*frame->sbsample)[ch][s][sb] =
202 mad_f_mul(sample, sf_table[scalefactor[ch][sb]]); 202 mad_f_mul(sample, sf_table[scalefactor[ch][sb]]);
203 } 203 }
204 } 204 }
205 else { 205 else {
206 for (ch = 0; ch < nch; ++ch) 206 for (ch = 0; ch < nch; ++ch)
207 frame->sbsample[ch][s][sb] = 0; 207 (*frame->sbsample)[ch][s][sb] = 0;
208 } 208 }
209 } 209 }
210 } 210 }
@@ -492,13 +492,13 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
492 II_samples(&stream->ptr, &qc_table[index], samples); 492 II_samples(&stream->ptr, &qc_table[index], samples);
493 493
494 for (s = 0; s < 3; ++s) { 494 for (s = 0; s < 3; ++s) {
495 frame->sbsample[ch][3 * gr + s][sb] = 495 (*frame->sbsample)[ch][3 * gr + s][sb] =
496 mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]); 496 mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]);
497 } 497 }
498 } 498 }
499 else { 499 else {
500 for (s = 0; s < 3; ++s) 500 for (s = 0; s < 3; ++s)
501 frame->sbsample[ch][3 * gr + s][sb] = 0; 501 (*frame->sbsample)[ch][3 * gr + s][sb] = 0;
502 } 502 }
503 } 503 }
504 } 504 }
@@ -512,7 +512,7 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
512 512
513 for (ch = 0; ch < nch; ++ch) { 513 for (ch = 0; ch < nch; ++ch) {
514 for (s = 0; s < 3; ++s) { 514 for (s = 0; s < 3; ++s) {
515 frame->sbsample[ch][3 * gr + s][sb] = 515 (*frame->sbsample)[ch][3 * gr + s][sb] =
516 mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]); 516 mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]);
517 } 517 }
518 } 518 }
@@ -520,7 +520,7 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
520 else { 520 else {
521 for (ch = 0; ch < nch; ++ch) { 521 for (ch = 0; ch < nch; ++ch) {
522 for (s = 0; s < 3; ++s) 522 for (s = 0; s < 3; ++s)
523 frame->sbsample[ch][3 * gr + s][sb] = 0; 523 (*frame->sbsample)[ch][3 * gr + s][sb] = 0;
524 } 524 }
525 } 525 }
526 } 526 }
@@ -528,7 +528,7 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
528 for (ch = 0; ch < nch; ++ch) { 528 for (ch = 0; ch < nch; ++ch) {
529 for (s = 0; s < 3; ++s) { 529 for (s = 0; s < 3; ++s) {
530 for (sb = sblimit; sb < 32; ++sb) 530 for (sb = sblimit; sb < 32; ++sb)
531 frame->sbsample[ch][3 * gr + s][sb] = 0; 531 (*frame->sbsample)[ch][3 * gr + s][sb] = 0;
532 } 532 }
533 } 533 }
534 } 534 }
diff --git a/apps/codecs/libmad/layer3.c b/apps/codecs/libmad/layer3.c
index a95927e10f..0a53086d78 100644
--- a/apps/codecs/libmad/layer3.c
+++ b/apps/codecs/libmad/layer3.c
@@ -3112,7 +3112,7 @@ enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
3112 3112
3113 for (ch = 0; ch < nch; ++ch) { 3113 for (ch = 0; ch < nch; ++ch) {
3114 struct channel const *channel = &granule->ch[ch]; 3114 struct channel const *channel = &granule->ch[ch];
3115 mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr]; 3115 mad_fixed_t (*sample)[32] = &((*frame->sbsample)[ch][18 * gr]);
3116 unsigned int sb, l, i, sblimit; 3116 unsigned int sb, l, i, sblimit;
3117 mad_fixed_t output[36]; 3117 mad_fixed_t output[36];
3118 3118
diff --git a/apps/codecs/libmad/mad.h b/apps/codecs/libmad/mad.h
index f5d8f1dbcc..52a74d122c 100644
--- a/apps/codecs/libmad/mad.h
+++ b/apps/codecs/libmad/mad.h
@@ -777,10 +777,13 @@ struct mad_header {
777 777
778struct mad_frame { 778struct mad_frame {
779 struct mad_header header; /* MPEG audio header */ 779 struct mad_header header; /* MPEG audio header */
780
781 int options; /* decoding options (from stream) */ 780 int options; /* decoding options (from stream) */
782 781
783 mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples */ 782 mad_fixed_t (*sbsample)[2][36][32]; /* synthesis subband filter samples */
783 mad_fixed_t (*sbsample_prev)[2][36][32]; /* synthesis subband filter samples
784 from previous frame only needed
785 when synthesis is on cop */
786
784 mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */ 787 mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */
785}; 788};
786 789
diff --git a/apps/codecs/libmad/synth.c b/apps/codecs/libmad/synth.c
index c023f01ae5..b1a8491a69 100644
--- a/apps/codecs/libmad/synth.c
+++ b/apps/codecs/libmad/synth.c
@@ -592,14 +592,14 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
592 int sb; 592 int sb;
593 unsigned int phase, ch, s, p; 593 unsigned int phase, ch, s, p;
594 mad_fixed_t *pcm, (*filter)[2][2][16][8]; 594 mad_fixed_t *pcm, (*filter)[2][2][16][8];
595 mad_fixed_t const (*sbsample)[36][32]; 595 mad_fixed_t (*sbsample)[36][32];
596 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; 596 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
597 mad_fixed_t const (*D0ptr)[32]; 597 mad_fixed_t const (*D0ptr)[32];
598 mad_fixed_t const (*D1ptr)[32]; 598 mad_fixed_t const (*D1ptr)[32];
599 mad_fixed64hi_t hi0, hi1; 599 mad_fixed64hi_t hi0, hi1;
600 600
601 for (ch = 0; ch < nch; ++ch) { 601 for (ch = 0; ch < nch; ++ch) {
602 sbsample = &frame->sbsample[ch]; 602 sbsample = &*frame->sbsample_prev[ch];
603 filter = &synth->filter[ch]; 603 filter = &synth->filter[ch];
604 phase = synth->phase; 604 phase = synth->phase;
605 pcm = synth->pcm.samples[ch]; 605 pcm = synth->pcm.samples[ch];
@@ -1053,7 +1053,7 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
1053 int p; 1053 int p;
1054 unsigned int phase, ch, s; 1054 unsigned int phase, ch, s;
1055 mad_fixed_t *pcm, (*filter)[2][2][16][8]; 1055 mad_fixed_t *pcm, (*filter)[2][2][16][8];
1056 mad_fixed_t const (*sbsample)[36][32]; 1056 mad_fixed_t (*sbsample)[36][32];
1057 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; 1057 mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
1058 mad_fixed_t const (*D0ptr)[32], *ptr; 1058 mad_fixed_t const (*D0ptr)[32], *ptr;
1059 mad_fixed_t const (*D1ptr)[32]; 1059 mad_fixed_t const (*D1ptr)[32];
@@ -1061,7 +1061,7 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
1061 mad_fixed64lo_t lo; 1061 mad_fixed64lo_t lo;
1062 1062
1063 for (ch = 0; ch < nch; ++ch) { 1063 for (ch = 0; ch < nch; ++ch) {
1064 sbsample = &frame->sbsample[ch]; 1064 sbsample = &(*frame->sbsample_prev)[ch];
1065 filter = &synth->filter[ch]; 1065 filter = &synth->filter[ch];
1066 phase = synth->phase; 1066 phase = synth->phase;
1067 pcm = synth->pcm.samples[ch]; 1067 pcm = synth->pcm.samples[ch];
@@ -1202,7 +1202,7 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
1202 mad_fixed64lo_t lo; 1202 mad_fixed64lo_t lo;
1203 1203
1204 for (ch = 0; ch < nch; ++ch) { 1204 for (ch = 0; ch < nch; ++ch) {
1205 sbsample = &frame->sbsample[ch]; 1205 sbsample = &frame->sbsample_prev[ch];
1206 filter = &synth->filter[ch]; 1206 filter = &synth->filter[ch];
1207 phase = synth->phase; 1207 phase = synth->phase;
1208 pcm = synth->pcm.samples[ch]; 1208 pcm = synth->pcm.samples[ch];
@@ -1403,14 +1403,14 @@ void synth_half(struct mad_synth *synth, struct mad_frame const *frame,
1403{ 1403{
1404 unsigned int phase, ch, s, sb, pe, po; 1404 unsigned int phase, ch, s, sb, pe, po;
1405 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8]; 1405 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
1406 mad_fixed_t const (*sbsample)[36][32]; 1406 mad_fixed_t (*sbsample)[36][32];
1407 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; 1407 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
1408 register mad_fixed_t const (*Dptr)[32], *ptr; 1408 register mad_fixed_t const (*Dptr)[32], *ptr;
1409 register mad_fixed64hi_t hi; 1409 register mad_fixed64hi_t hi;
1410 register mad_fixed64lo_t lo; 1410 register mad_fixed64lo_t lo;
1411 1411
1412 for (ch = 0; ch < nch; ++ch) { 1412 for (ch = 0; ch < nch; ++ch) {
1413 sbsample = &frame->sbsample[ch]; 1413 sbsample = &(*frame->sbsample_prev)[ch];
1414 filter = &synth->filter[ch]; 1414 filter = &synth->filter[ch];
1415 phase = synth->phase; 1415 phase = synth->phase;
1416 pcm1 = synth->pcm.samples[ch]; 1416 pcm1 = synth->pcm.samples[ch];
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index 7ac96fb8b2..c916aefcaa 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -25,13 +25,34 @@
25 25
26CODEC_HEADER 26CODEC_HEADER
27 27
28#if (CONFIG_CPU == PP5024 || CONFIG_CPU == PP5022 || CONFIG_CPU == PP5020 \
29 || CONFIG_CPU == PP5002) && !defined(MPEGPLAYER)
30#define MPA_SYNTH_ON_COP
31#endif
32
28struct mad_stream stream IBSS_ATTR; 33struct mad_stream stream IBSS_ATTR;
29struct mad_frame frame IBSS_ATTR; 34struct mad_frame frame IBSS_ATTR;
30struct mad_synth synth IBSS_ATTR; 35struct mad_synth synth IBSS_ATTR;
31 36
37#ifdef MPA_SYNTH_ON_COP
38volatile short synth_running IBSS_ATTR; /*synthesis is running*/
39volatile short die IBSS_ATTR; /*thread should die*/
40
41#if (CONFIG_CPU == PP5024) || (CONFIG_CPU == PP5022)
42mad_fixed_t sbsample_prev[2][36][32] IBSS_ATTR;
43#else
44mad_fixed_t sbsample_prev[2][36][32] SHAREDBSS_ATTR;
45#endif
46
47struct semaphore synth_done_sem IBSS_ATTR;
48struct semaphore synth_pending_sem IBSS_ATTR;
49#endif
50
32#define INPUT_CHUNK_SIZE 8192 51#define INPUT_CHUNK_SIZE 8192
33 52
34mad_fixed_t mad_frame_overlap[2][32][18] IBSS_ATTR; 53mad_fixed_t mad_frame_overlap[2][32][18] IBSS_ATTR;
54mad_fixed_t sbsample[2][36][32] IBSS_ATTR;
55
35unsigned char mad_main_data[MAD_BUFFER_MDLEN] IBSS_ATTR; 56unsigned char mad_main_data[MAD_BUFFER_MDLEN] IBSS_ATTR;
36/* TODO: what latency does layer 1 have? */ 57/* TODO: what latency does layer 1 have? */
37int mpeg_latency[3] = { 0, 481, 529 }; 58int mpeg_latency[3] = { 0, 481, 529 };
@@ -43,6 +64,14 @@ void init_mad(void)
43 ci->memset(&frame, 0, sizeof(struct mad_frame)); 64 ci->memset(&frame, 0, sizeof(struct mad_frame));
44 ci->memset(&synth, 0, sizeof(struct mad_synth)); 65 ci->memset(&synth, 0, sizeof(struct mad_synth));
45 66
67#ifdef MPA_SYNTH_ON_COP
68 frame.sbsample_prev = &sbsample_prev;
69#else
70 frame.sbsample_prev = &sbsample;
71#endif
72
73 frame.sbsample=&sbsample;
74
46 mad_stream_init(&stream); 75 mad_stream_init(&stream);
47 mad_frame_init(&frame); 76 mad_frame_init(&frame);
48 mad_synth_init(&synth); 77 mad_synth_init(&synth);
@@ -51,6 +80,8 @@ void init_mad(void)
51 ci->memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap)); 80 ci->memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
52 frame.overlap = &mad_frame_overlap; 81 frame.overlap = &mad_frame_overlap;
53 stream.main_data = &mad_main_data; 82 stream.main_data = &mad_main_data;
83
84
54} 85}
55 86
56int get_file_pos(int newtime) 87int get_file_pos(int newtime)
@@ -159,6 +190,90 @@ static void set_elapsed(struct mp3entry* id3)
159 } 190 }
160} 191}
161 192
193#ifdef MPA_SYNTH_ON_COP
194
195/*
196 * Run the synthesis filter on the COProcessor
197 */
198
199static int mad_synth_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)/2] IBSS_ATTR;
200
201static const unsigned char * const mad_synth_thread_name = "mp3dec";
202static struct thread_entry *mad_synth_thread_p;
203
204
205static void mad_synth_thread(void){
206
207 while(1){
208 ci->semaphore_wait(&synth_pending_sem);
209
210 if(die){
211 die=0;
212 invalidate_icache();
213 return ;
214 }
215 synth_running = 1;
216 mad_synth_frame(&synth, &frame);
217 synth_running = 0;
218 ci->semaphore_release(&synth_done_sem);
219 }
220}
221
222
223static int mad_synth_thread_wait_pcm(void){
224 ci->semaphore_wait(&synth_done_sem);
225 return 0;
226}
227
228static void mad_synth_thread_ready(void){
229 mad_fixed_t (*temp)[2][36][32];
230 while(1){
231 /*check if synth is currently running before changing its inputs! */
232 if(!synth_running){
233 /*circular buffer that holds 2 frames' samples*/
234 temp=frame.sbsample;
235 frame.sbsample = frame.sbsample_prev;
236 frame.sbsample_prev=temp;
237
238 ci->semaphore_release(&synth_pending_sem);
239 return ;
240 }
241 ci->yield(); /*synth thread currently running, wait for it*/
242 }
243}
244
245static int mad_synth_thread_create(void){
246 synth_running=0;
247 die=0;
248
249 ci->semaphore_init(&synth_done_sem, 1, 0);
250 ci->semaphore_init(&synth_pending_sem, 1, 0);
251
252 mad_synth_thread_p = ci->create_thread(mad_synth_thread,
253 mad_synth_thread_stack,
254 sizeof(mad_synth_thread_stack), 0,
255 mad_synth_thread_name
256 IF_PRIO(, PRIORITY_PLAYBACK), COP);
257
258 if (mad_synth_thread_p == NULL)
259 return false;
260
261 return true;
262
263}
264#else
265static void mad_synth_thread_ready(void){
266 mad_synth_frame(&synth, &frame);
267}
268static int mad_synth_thread_create(void){
269 return 0;
270}
271static int mad_synth_thread_wait_pcm(void){
272 return 0;
273}
274
275#endif
276
162/* this is the codec entry point */ 277/* this is the codec entry point */
163enum codec_status codec_main(void) 278enum codec_status codec_main(void)
164{ 279{
@@ -180,8 +295,12 @@ enum codec_status codec_main(void)
180 /* Create a decoder instance */ 295 /* Create a decoder instance */
181 296
182 ci->configure(DSP_SET_SAMPLE_DEPTH, MAD_F_FRACBITS); 297 ci->configure(DSP_SET_SAMPLE_DEPTH, MAD_F_FRACBITS);
183 298
184next_track: 299next_track:
300
301 /*does nothing on 1 processor systems*/
302 mad_synth_thread_create();
303
185 status = CODEC_OK; 304 status = CODEC_OK;
186 305
187 /* Reinitializing seems to be necessary to avoid playback quircks when seeking. */ 306 /* Reinitializing seems to be necessary to avoid playback quircks when seeking. */
@@ -300,6 +419,9 @@ next_track:
300 data (not the one just decoded above). When we exit the decoding 419 data (not the one just decoded above). When we exit the decoding
301 loop we will need to process the final frame that was decoded. */ 420 loop we will need to process the final frame that was decoded. */
302 if (framelength > 0) { 421 if (framelength > 0) {
422
423 mad_synth_thread_wait_pcm();
424
303 /* In case of a mono file, the second array will be ignored. */ 425 /* In case of a mono file, the second array will be ignored. */
304 ci->pcmbuf_insert(&synth.pcm.samples[0][samples_to_skip], 426 ci->pcmbuf_insert(&synth.pcm.samples[0][samples_to_skip],
305 &synth.pcm.samples[1][samples_to_skip], 427 &synth.pcm.samples[1][samples_to_skip],
@@ -308,8 +430,9 @@ next_track:
308 /* Only skip samples for the first frame added. */ 430 /* Only skip samples for the first frame added. */
309 samples_to_skip = 0; 431 samples_to_skip = 0;
310 } 432 }
311 433
312 mad_synth_frame(&synth, &frame); 434 mad_synth_thread_ready();
435 //mad_synth_frame(&synth, &frame);
313 436
314 /* Check if sample rate and stereo settings changed in this frame. */ 437 /* Check if sample rate and stereo settings changed in this frame. */
315 if (frame.header.samplerate != current_frequency) { 438 if (frame.header.samplerate != current_frequency) {
@@ -345,11 +468,20 @@ next_track:
345 468
346 /* Finish the remaining decoded frame. 469 /* Finish the remaining decoded frame.
347 Cut the required samples from the end. */ 470 Cut the required samples from the end. */
348 if (framelength > stop_skip) 471 if (framelength > stop_skip){
472 mad_synth_thread_wait_pcm();
349 ci->pcmbuf_insert(synth.pcm.samples[0], synth.pcm.samples[1], 473 ci->pcmbuf_insert(synth.pcm.samples[0], synth.pcm.samples[1],
350 framelength - stop_skip); 474 framelength - stop_skip);
351 475}
476#ifdef MPA_SYNTH_ON_COP
477 /*mop up COP thread*/
478 die=1;
479 ci->semaphore_release(&synth_pending_sem);
480 ci->thread_wait(mad_synth_thread_p);
481 invalidate_icache();
352 stream.error = 0; 482 stream.error = 0;
483#endif
484
353 485
354 if (ci->request_next_track()) 486 if (ci->request_next_track())
355 goto next_track; 487 goto next_track;
diff --git a/apps/plugins/mpegplayer/Makefile b/apps/plugins/mpegplayer/Makefile
index 66a6142397..7f90cbcc8d 100644
--- a/apps/plugins/mpegplayer/Makefile
+++ b/apps/plugins/mpegplayer/Makefile
@@ -10,7 +10,7 @@
10INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \ 10INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
11 -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(APPSDIR)/plugins/lib -I$(OUTDIR) -I$(BUILDDIR) 11 -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(APPSDIR)/plugins/lib -I$(OUTDIR) -I$(BUILDDIR)
12CFLAGS = $(INCLUDES) $(GCCOPTS) -O2 $(TARGET) $(EXTRA_DEFINES) \ 12CFLAGS = $(INCLUDES) $(GCCOPTS) -O2 $(TARGET) $(EXTRA_DEFINES) \
13 -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN 13 -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN -DMPEGPLAYER
14 14
15ifdef APPEXTRA 15ifdef APPEXTRA
16 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA))) 16 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
diff --git a/apps/plugins/mpegplayer/audio_thread.c b/apps/plugins/mpegplayer/audio_thread.c
index 838dcad699..351581548f 100644
--- a/apps/plugins/mpegplayer/audio_thread.c
+++ b/apps/plugins/mpegplayer/audio_thread.c
@@ -55,6 +55,9 @@ static struct mad_stream stream IBSS_ATTR;
55static struct mad_frame frame IBSS_ATTR; 55static struct mad_frame frame IBSS_ATTR;
56static struct mad_synth synth IBSS_ATTR; 56static struct mad_synth synth IBSS_ATTR;
57 57
58/*sbsample buffer for mad_frame*/
59mad_fixed_t sbsample[2][36][32];
60
58/* 2567 bytes */ 61/* 2567 bytes */
59static unsigned char mad_main_data[MAD_BUFFER_MDLEN]; 62static unsigned char mad_main_data[MAD_BUFFER_MDLEN];
60 63
@@ -229,6 +232,10 @@ static int audio_buffer(struct stream *str, enum stream_parse_mode type)
229/* Initialise libmad */ 232/* Initialise libmad */
230static void init_mad(void) 233static void init_mad(void)
231{ 234{
235 /*init the sbsample buffer*/
236 frame.sbsample = &sbsample;
237 frame.sbsample_prev = &sbsample;
238
232 mad_stream_init(&stream); 239 mad_stream_init(&stream);
233 mad_frame_init(&frame); 240 mad_frame_init(&frame);
234 mad_synth_init(&synth); 241 mad_synth_init(&synth);