summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2009-08-12 19:00:31 +0000
committerJeffrey Goode <jeffg7@gmail.com>2009-08-12 19:00:31 +0000
commite3f36a1f473d2f9503c4e6adfc82de6db8ea1a20 (patch)
tree58a7caa3c3c63cc702eb2d5b4a3e0b82fae2f0c2
parent24bd4923fda2b1511ac1fe96338e50165fadf810 (diff)
downloadrockbox-e3f36a1f473d2f9503c4e6adfc82de6db8ea1a20.tar.gz
rockbox-e3f36a1f473d2f9503c4e6adfc82de6db8ea1a20.zip
FS#10446: Bug defense in dsp.c, minor tweaks and comments
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22282 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/dsp.c36
-rw-r--r--apps/pcmbuf.c4
2 files changed, 16 insertions, 24 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index f9b94e8228..61fc027e4c 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -343,11 +343,10 @@ static void sample_input_lte_native_mono(
343 int32_t *d = dst[0] = dst[1] = &sample_buf[SAMPLE_BUF_LEFT_CHANNEL]; 343 int32_t *d = dst[0] = dst[1] = &sample_buf[SAMPLE_BUF_LEFT_CHANNEL];
344 int scale = WORD_SHIFT; 344 int scale = WORD_SHIFT;
345 345
346 do 346 while (s < send)
347 { 347 {
348 *d++ = *s++ << scale; 348 *d++ = *s++ << scale;
349 } 349 }
350 while (s < send);
351 350
352 src[0] = (char *)s; 351 src[0] = (char *)s;
353} 352}
@@ -362,7 +361,7 @@ static void sample_input_lte_native_i_stereo(
362 int32_t *dr = dst[1] = &sample_buf[SAMPLE_BUF_RIGHT_CHANNEL]; 361 int32_t *dr = dst[1] = &sample_buf[SAMPLE_BUF_RIGHT_CHANNEL];
363 int scale = WORD_SHIFT; 362 int scale = WORD_SHIFT;
364 363
365 do 364 while (s < send)
366 { 365 {
367 int32_t slr = *s++; 366 int32_t slr = *s++;
368#ifdef ROCKBOX_LITTLE_ENDIAN 367#ifdef ROCKBOX_LITTLE_ENDIAN
@@ -373,7 +372,6 @@ static void sample_input_lte_native_i_stereo(
373 *dr++ = (slr >> 16) << scale; 372 *dr++ = (slr >> 16) << scale;
374#endif 373#endif
375 } 374 }
376 while (s < send);
377 375
378 src[0] = (char *)s; 376 src[0] = (char *)s;
379} 377}
@@ -389,12 +387,11 @@ static void sample_input_lte_native_ni_stereo(
389 int32_t *dr = dst[1] = &sample_buf[SAMPLE_BUF_RIGHT_CHANNEL]; 387 int32_t *dr = dst[1] = &sample_buf[SAMPLE_BUF_RIGHT_CHANNEL];
390 int scale = WORD_SHIFT; 388 int scale = WORD_SHIFT;
391 389
392 do 390 while (sl < slend)
393 { 391 {
394 *dl++ = *sl++ << scale; 392 *dl++ = *sl++ << scale;
395 *dr++ = *sr++ << scale; 393 *dr++ = *sr++ << scale;
396 } 394 }
397 while (sl < slend);
398 395
399 src[0] = (char *)sl; 396 src[0] = (char *)sl;
400 src[1] = (char *)sr; 397 src[1] = (char *)sr;
@@ -417,12 +414,11 @@ static void sample_input_gt_native_i_stereo(
417 int32_t *dl = dst[0] = &sample_buf[SAMPLE_BUF_LEFT_CHANNEL]; 414 int32_t *dl = dst[0] = &sample_buf[SAMPLE_BUF_LEFT_CHANNEL];
418 int32_t *dr = dst[1] = &sample_buf[SAMPLE_BUF_RIGHT_CHANNEL]; 415 int32_t *dr = dst[1] = &sample_buf[SAMPLE_BUF_RIGHT_CHANNEL];
419 416
420 do 417 while (s < send)
421 { 418 {
422 *dl++ = *s++; 419 *dl++ = *s++;
423 *dr++ = *s++; 420 *dr++ = *s++;
424 } 421 }
425 while (s < send);
426 422
427 src[0] = (char *)send; 423 src[0] = (char *)send;
428} 424}
@@ -451,12 +447,12 @@ static void sample_input_new_format(struct dsp_config *dsp)
451{ 447{
452 static const sample_input_fn_type sample_input_functions[] = 448 static const sample_input_fn_type sample_input_functions[] =
453 { 449 {
454 [SAMPLE_INPUT_LE_NATIVE_MONO] = sample_input_lte_native_mono,
455 [SAMPLE_INPUT_LE_NATIVE_I_STEREO] = sample_input_lte_native_i_stereo, 450 [SAMPLE_INPUT_LE_NATIVE_I_STEREO] = sample_input_lte_native_i_stereo,
456 [SAMPLE_INPUT_LE_NATIVE_NI_STEREO] = sample_input_lte_native_ni_stereo, 451 [SAMPLE_INPUT_LE_NATIVE_NI_STEREO] = sample_input_lte_native_ni_stereo,
457 [SAMPLE_INPUT_GT_NATIVE_MONO] = sample_input_gt_native_mono, 452 [SAMPLE_INPUT_LE_NATIVE_MONO] = sample_input_lte_native_mono,
458 [SAMPLE_INPUT_GT_NATIVE_I_STEREO] = sample_input_gt_native_i_stereo, 453 [SAMPLE_INPUT_GT_NATIVE_I_STEREO] = sample_input_gt_native_i_stereo,
459 [SAMPLE_INPUT_GT_NATIVE_NI_STEREO] = sample_input_gt_native_ni_stereo, 454 [SAMPLE_INPUT_GT_NATIVE_NI_STEREO] = sample_input_gt_native_ni_stereo,
455 [SAMPLE_INPUT_GT_NATIVE_MONO] = sample_input_gt_native_mono,
460 }; 456 };
461 457
462 int convert = dsp->stereo_mode; 458 int convert = dsp->stereo_mode;
@@ -477,13 +473,12 @@ static void sample_output_mono(int count, struct dsp_data *data,
477 const int scale = data->output_scale; 473 const int scale = data->output_scale;
478 const int dc_bias = 1 << (scale - 1); 474 const int dc_bias = 1 << (scale - 1);
479 475
480 do 476 while (count-- > 0)
481 { 477 {
482 int32_t lr = clip_sample_16((*s0++ + dc_bias) >> scale); 478 int32_t lr = clip_sample_16((*s0++ + dc_bias) >> scale);
483 *dst++ = lr; 479 *dst++ = lr;
484 *dst++ = lr; 480 *dst++ = lr;
485 } 481 }
486 while (--count > 0);
487} 482}
488#endif /* DSP_HAVE_ASM_SAMPLE_OUTPUT_MONO */ 483#endif /* DSP_HAVE_ASM_SAMPLE_OUTPUT_MONO */
489 484
@@ -497,12 +492,11 @@ static void sample_output_stereo(int count, struct dsp_data *data,
497 const int scale = data->output_scale; 492 const int scale = data->output_scale;
498 const int dc_bias = 1 << (scale - 1); 493 const int dc_bias = 1 << (scale - 1);
499 494
500 do 495 while (count-- > 0)
501 { 496 {
502 *dst++ = clip_sample_16((*s0++ + dc_bias) >> scale); 497 *dst++ = clip_sample_16((*s0++ + dc_bias) >> scale);
503 *dst++ = clip_sample_16((*s1++ + dc_bias) >> scale); 498 *dst++ = clip_sample_16((*s1++ + dc_bias) >> scale);
504 } 499 }
505 while (--count > 0);
506} 500}
507#endif /* DSP_HAVE_ASM_SAMPLE_OUTPUT_STEREO */ 501#endif /* DSP_HAVE_ASM_SAMPLE_OUTPUT_STEREO */
508 502
@@ -575,12 +569,11 @@ static void sample_output_dithered(int count, struct dsp_data *data,
575 pcm buffer and hardware is interleaved stereo */ 569 pcm buffer and hardware is interleaved stereo */
576 d = &dst[0]; 570 d = &dst[0];
577 571
578 do 572 while (count-- > 0)
579 { 573 {
580 int16_t s = *d++; 574 int16_t s = *d++;
581 *d++ = s; 575 *d++ = s;
582 } 576 }
583 while (--count > 0);
584} 577}
585 578
586/** 579/**
@@ -1043,13 +1036,12 @@ static void channels_process_sound_chan_mono(int count, int32_t *buf[])
1043{ 1036{
1044 int32_t *sl = buf[0], *sr = buf[1]; 1037 int32_t *sl = buf[0], *sr = buf[1];
1045 1038
1046 do 1039 while (count-- > 0)
1047 { 1040 {
1048 int32_t lr = *sl/2 + *sr/2; 1041 int32_t lr = *sl/2 + *sr/2;
1049 *sl++ = lr; 1042 *sl++ = lr;
1050 *sr++ = lr; 1043 *sr++ = lr;
1051 } 1044 }
1052 while (--count > 0);
1053} 1045}
1054#endif /* DSP_HAVE_ASM_SOUND_CHAN_MONO */ 1046#endif /* DSP_HAVE_ASM_SOUND_CHAN_MONO */
1055 1047
@@ -1060,14 +1052,13 @@ static void channels_process_sound_chan_custom(int count, int32_t *buf[])
1060 const int32_t cross = dsp_sw_cross; 1052 const int32_t cross = dsp_sw_cross;
1061 int32_t *sl = buf[0], *sr = buf[1]; 1053 int32_t *sl = buf[0], *sr = buf[1];
1062 1054
1063 do 1055 while (count-- > 0)
1064 { 1056 {
1065 int32_t l = *sl; 1057 int32_t l = *sl;
1066 int32_t r = *sr; 1058 int32_t r = *sr;
1067 *sl++ = FRACMUL(l, gain) + FRACMUL(r, cross); 1059 *sl++ = FRACMUL(l, gain) + FRACMUL(r, cross);
1068 *sr++ = FRACMUL(r, gain) + FRACMUL(l, cross); 1060 *sr++ = FRACMUL(r, gain) + FRACMUL(l, cross);
1069 } 1061 }
1070 while (--count > 0);
1071} 1062}
1072#endif /* DSP_HAVE_ASM_SOUND_CHAN_CUSTOM */ 1063#endif /* DSP_HAVE_ASM_SOUND_CHAN_CUSTOM */
1073 1064
@@ -1088,13 +1079,12 @@ static void channels_process_sound_chan_karaoke(int count, int32_t *buf[])
1088{ 1079{
1089 int32_t *sl = buf[0], *sr = buf[1]; 1080 int32_t *sl = buf[0], *sr = buf[1];
1090 1081
1091 do 1082 while (count-- > 0)
1092 { 1083 {
1093 int32_t ch = *sl/2 - *sr/2; 1084 int32_t ch = *sl/2 - *sr/2;
1094 *sl++ = ch; 1085 *sl++ = ch;
1095 *sr++ = -ch; 1086 *sr++ = -ch;
1096 } 1087 }
1097 while (--count > 0);
1098} 1088}
1099#endif /* DSP_HAVE_ASM_SOUND_CHAN_KARAOKE */ 1089#endif /* DSP_HAVE_ASM_SOUND_CHAN_KARAOKE */
1100 1090
@@ -1504,7 +1494,7 @@ void dsp_set_replaygain(void)
1504 } 1494 }
1505 } 1495 }
1506 1496
1507 /* Store in S8.23 format to simplify calculations. */ 1497 /* Store in S7.24 format to simplify calculations. */
1508 replaygain = gain; 1498 replaygain = gain;
1509 set_gain(&AUDIO_DSP); 1499 set_gain(&AUDIO_DSP);
1510} 1500}
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index e23f6d0fb6..319e3e8044 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -448,7 +448,7 @@ static size_t pcmbuf_get_next_required_pcmbuf_size(void)
448 /* Buffer has to be at least 2s long. */ 448 /* Buffer has to be at least 2s long. */
449 seconds += 2; 449 seconds += 2;
450#endif 450#endif
451 logf("pcmbuf len: %ld", seconds); 451 logf("pcmbuf len: %ld", (long)seconds);
452 return seconds * (NATIVE_FREQUENCY*4); /* 2 channels + 2 bytes/sample */ 452 return seconds * (NATIVE_FREQUENCY*4); /* 2 channels + 2 bytes/sample */
453} 453}
454 454
@@ -1166,6 +1166,8 @@ bool pcmbuf_is_crossfade_enabled(void)
1166 return crossfade_enabled; 1166 return crossfade_enabled;
1167} 1167}
1168 1168
1169/** PLAY LAST REMAINING SAMPLES AT END OF PLAYBACK
1170 * Commit any remaining samples in the PCM buffer for playback. */
1169void pcmbuf_play_remainder(void) 1171void pcmbuf_play_remainder(void)
1170{ 1172{
1171 if (audiobuffer_fillpos) 1173 if (audiobuffer_fillpos)