summaryrefslogtreecommitdiff
path: root/apps/dsp.c
diff options
context:
space:
mode:
authorThom Johansen <thomj@rockbox.org>2006-03-19 16:31:45 +0000
committerThom Johansen <thomj@rockbox.org>2006-03-19 16:31:45 +0000
commitea4ccb5abab7f3a775b0c1fee1a50a8840b09d47 (patch)
tree24d2d5d5da23c90eb25c23fa43c036710f5cb046 /apps/dsp.c
parentf383cc14bd7d1c567fb283af4b3af252a2a3f6c9 (diff)
downloadrockbox-ea4ccb5abab7f3a775b0c1fee1a50a8840b09d47.tar.gz
rockbox-ea4ccb5abab7f3a775b0c1fee1a50a8840b09d47.zip
Samples should always be 32 bit on all platforms, so change most
occurences of long to int32_t to enable working sounds also on 64 bit sims. Note that some codecs (MP3 and Wavpack) still have other 64 bit related problems. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9120 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/dsp.c')
-rw-r--r--apps/dsp.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index 0c376a14ea..de88c97ca6 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -192,7 +192,7 @@ struct dsp_config
192struct resample_data 192struct resample_data
193{ 193{
194 long phase, delta; 194 long phase, delta;
195 long last_sample[2]; 195 int32_t last_sample[2];
196}; 196};
197 197
198struct dither_data 198struct dither_data
@@ -203,9 +203,9 @@ struct dither_data
203 203
204struct crossfeed_data 204struct crossfeed_data
205{ 205{
206 long lowpass[2]; 206 int32_t lowpass[2];
207 long highpass[2]; 207 int32_t highpass[2];
208 long delay[2][13]; 208 int32_t delay[2][13];
209 int index; 209 int index;
210}; 210};
211 211
@@ -233,8 +233,8 @@ struct dsp_config *dsp;
233 * of copying needed is minimized for that case. 233 * of copying needed is minimized for that case.
234 */ 234 */
235 235
236static long sample_buf[SAMPLE_BUF_SIZE] IBSS_ATTR; 236static int32_t sample_buf[SAMPLE_BUF_SIZE] IBSS_ATTR;
237static long resample_buf[RESAMPLE_BUF_SIZE] IBSS_ATTR; 237static int32_t resample_buf[RESAMPLE_BUF_SIZE] IBSS_ATTR;
238 238
239int sound_get_pitch(void) 239int sound_get_pitch(void)
240{ 240{
@@ -254,7 +254,7 @@ void sound_set_pitch(int permille)
254 * consume. Note that for mono, dst[0] equals dst[1], as there is no point 254 * consume. Note that for mono, dst[0] equals dst[1], as there is no point
255 * in processing the same data twice. 255 * in processing the same data twice.
256 */ 256 */
257static int convert_to_internal(const char* src[], int count, long* dst[]) 257static int convert_to_internal(const char* src[], int count, int32_t* dst[])
258{ 258{
259 count = MIN(SAMPLE_BUF_SIZE / 2, count); 259 count = MIN(SAMPLE_BUF_SIZE / 2, count);
260 260
@@ -267,15 +267,15 @@ static int convert_to_internal(const char* src[], int count, long* dst[])
267 } 267 }
268 else 268 else
269 { 269 {
270 dst[0] = (long*) src[0]; 270 dst[0] = (int32_t*) src[0];
271 dst[1] = (long*) ((dsp->stereo_mode == STEREO_MONO) ? src[0] : src[1]); 271 dst[1] = (int32_t*) ((dsp->stereo_mode == STEREO_MONO) ? src[0] : src[1]);
272 } 272 }
273 273
274 if (dsp->sample_depth <= NATIVE_DEPTH) 274 if (dsp->sample_depth <= NATIVE_DEPTH)
275 { 275 {
276 short* s0 = (short*) src[0]; 276 short* s0 = (short*) src[0];
277 long* d0 = dst[0]; 277 int32_t* d0 = dst[0];
278 long* d1 = dst[1]; 278 int32_t* d1 = dst[1];
279 int scale = WORD_SHIFT; 279 int scale = WORD_SHIFT;
280 int i; 280 int i;
281 281
@@ -307,9 +307,9 @@ static int convert_to_internal(const char* src[], int count, long* dst[])
307 } 307 }
308 else if (dsp->stereo_mode == STEREO_INTERLEAVED) 308 else if (dsp->stereo_mode == STEREO_INTERLEAVED)
309 { 309 {
310 long* s0 = (long*) src[0]; 310 int32_t* s0 = (int32_t*) src[0];
311 long* d0 = dst[0]; 311 int32_t* d0 = dst[0];
312 long* d1 = dst[1]; 312 int32_t* d1 = dst[1];
313 int i; 313 int i;
314 314
315 for (i = 0; i < count; i++) 315 for (i = 0; i < count; i++)
@@ -348,13 +348,13 @@ static void resampler_set_delta(int frequency)
348 348
349/* TODO: we really should have a separate set of resample functions for both 349/* TODO: we really should have a separate set of resample functions for both
350 mono and stereo to avoid all this internal branching and looping. */ 350 mono and stereo to avoid all this internal branching and looping. */
351static long downsample(long **dst, long **src, int count, 351static long downsample(int32_t **dst, int32_t **src, int count,
352 struct resample_data *r) 352 struct resample_data *r)
353{ 353{
354 long phase = r->phase; 354 long phase = r->phase;
355 long delta = r->delta; 355 long delta = r->delta;
356 long last_sample; 356 int32_t last_sample;
357 long *d[2] = { dst[0], dst[1] }; 357 int32_t *d[2] = { dst[0], dst[1] };
358 int pos = phase >> 16; 358 int pos = phase >> 16;
359 int i = 1, j; 359 int i = 1, j;
360 int num_channels = dsp->stereo_mode == STEREO_MONO ? 1 : 2; 360 int num_channels = dsp->stereo_mode == STEREO_MONO ? 1 : 2;
@@ -388,11 +388,11 @@ static long downsample(long **dst, long **src, int count,
388 return i; 388 return i;
389} 389}
390 390
391static long upsample(long **dst, long **src, int count, struct resample_data *r) 391static long upsample(int32_t **dst, int32_t **src, int count, struct resample_data *r)
392{ 392{
393 long phase = r->phase; 393 long phase = r->phase;
394 long delta = r->delta; 394 long delta = r->delta;
395 long *d[2] = { dst[0], dst[1] }; 395 int32_t *d[2] = { dst[0], dst[1] };
396 int i = 0, j; 396 int i = 0, j;
397 int pos; 397 int pos;
398 int num_channels = dsp->stereo_mode == STEREO_MONO ? 1 : 2; 398 int num_channels = dsp->stereo_mode == STEREO_MONO ? 1 : 2;
@@ -427,13 +427,13 @@ static long upsample(long **dst, long **src, int count, struct resample_data *r)
427 * done, to refer to the resampled data. Returns number of stereo samples 427 * done, to refer to the resampled data. Returns number of stereo samples
428 * for further processing. 428 * for further processing.
429 */ 429 */
430static inline int resample(long* src[], int count) 430static inline int resample(int32_t* src[], int count)
431{ 431{
432 long new_count; 432 long new_count;
433 433
434 if (dsp->frequency != NATIVE_FREQUENCY) 434 if (dsp->frequency != NATIVE_FREQUENCY)
435 { 435 {
436 long* dst[2] = {&resample_buf[0], &resample_buf[RESAMPLE_BUF_SIZE / 2]}; 436 int32_t* dst[2] = {&resample_buf[0], &resample_buf[RESAMPLE_BUF_SIZE / 2]};
437 437
438 if (dsp->frequency < NATIVE_FREQUENCY) 438 if (dsp->frequency < NATIVE_FREQUENCY)
439 { 439 {
@@ -460,7 +460,7 @@ static inline int resample(long* src[], int count)
460 return new_count; 460 return new_count;
461} 461}
462 462
463static inline long clip_sample(long sample, long min, long max) 463static inline long clip_sample(int32_t sample, int32_t min, int32_t max)
464{ 464{
465 if (sample > max) 465 if (sample > max)
466 { 466 {
@@ -478,13 +478,13 @@ static inline long clip_sample(long sample, long min, long max)
478 * taken from the coolplayer project - coolplayer.sourceforge.net 478 * taken from the coolplayer project - coolplayer.sourceforge.net
479 */ 479 */
480 480
481static long dither_sample(long sample, long bias, long mask, 481static long dither_sample(int32_t sample, int32_t bias, int32_t mask,
482 struct dither_data* dither) 482 struct dither_data* dither)
483{ 483{
484 long output; 484 int32_t output;
485 long random; 485 int32_t random;
486 long min; 486 int32_t min;
487 long max; 487 int32_t max;
488 488
489 /* Noise shape and bias */ 489 /* Noise shape and bias */
490 490
@@ -523,7 +523,7 @@ static const long crossfeed_coefs[6] ICONST_ATTR = {
523 LOW, LOW_COMP, HIGH_NEG, HIGH_COMP, ATT, ATT_COMP 523 LOW, LOW_COMP, HIGH_NEG, HIGH_COMP, ATT, ATT_COMP
524}; 524};
525 525
526static void apply_crossfeed(long* src[], int count) 526static void apply_crossfeed(int32_t* src[], int count)
527{ 527{
528 asm volatile ( 528 asm volatile (
529 "lea.l crossfeed_data, %%a1 \n" 529 "lea.l crossfeed_data, %%a1 \n"
@@ -598,20 +598,20 @@ static void apply_crossfeed(long* src[], int count)
598 ); 598 );
599} 599}
600#else 600#else
601static void apply_crossfeed(long* src[], int count) 601static void apply_crossfeed(int32_t* src[], int count)
602{ 602{
603 long a; /* accumulator */ 603 int32_t a; /* accumulator */
604 604
605 long low_left = crossfeed_data.lowpass[0]; 605 int32_t low_left = crossfeed_data.lowpass[0];
606 long low_right = crossfeed_data.lowpass[1]; 606 int32_t low_right = crossfeed_data.lowpass[1];
607 long high_left = crossfeed_data.highpass[0]; 607 int32_t high_left = crossfeed_data.highpass[0];
608 long high_right = crossfeed_data.highpass[1]; 608 int32_t high_right = crossfeed_data.highpass[1];
609 unsigned int index = crossfeed_data.index; 609 unsigned int index = crossfeed_data.index;
610 610
611 long left, right; 611 int32_t left, right;
612 612
613 long * delay_l = crossfeed_data.delay[0]; 613 int32_t* delay_l = crossfeed_data.delay[0];
614 long * delay_r = crossfeed_data.delay[1]; 614 int32_t* delay_r = crossfeed_data.delay[1];
615 615
616 int i; 616 int i;
617 617
@@ -711,7 +711,7 @@ void dsp_eq_update_data(bool enabled, int band)
711} 711}
712 712
713/* Apply EQ filters to those bands that have got it switched on. */ 713/* Apply EQ filters to those bands that have got it switched on. */
714static void eq_process(long **x, unsigned num) 714static void eq_process(int32_t **x, unsigned num)
715{ 715{
716 int i; 716 int i;
717 unsigned int channels = dsp->stereo_mode != STEREO_MONO ? 2 : 1; 717 unsigned int channels = dsp->stereo_mode != STEREO_MONO ? 2 : 1;
@@ -736,19 +736,19 @@ static void eq_process(long **x, unsigned num)
736 * the src array if gain was applied. 736 * the src array if gain was applied.
737 * Note that this must be called before the resampler. 737 * Note that this must be called before the resampler.
738 */ 738 */
739static void apply_gain(long* _src[], int _count) 739static void apply_gain(int32_t* _src[], int _count)
740{ 740{
741 struct dsp_config *my_dsp = dsp; 741 struct dsp_config *my_dsp = dsp;
742 if (my_dsp->replaygain) 742 if (my_dsp->replaygain)
743 { 743 {
744 long** src = _src; 744 int32_t** src = _src;
745 int count = _count; 745 int count = _count;
746 long* s0 = src[0]; 746 int32_t* s0 = src[0];
747 long* s1 = src[1]; 747 int32_t* s1 = src[1];
748 long gain = my_dsp->replaygain; 748 long gain = my_dsp->replaygain;
749 long s; 749 int32_t s;
750 int i; 750 int i;
751 long *d; 751 int32_t *d;
752 752
753 if (s0 != s1) 753 if (s0 != s1)
754 { 754 {
@@ -773,10 +773,10 @@ static void apply_gain(long* _src[], int _count)
773 } 773 }
774} 774}
775 775
776static void write_samples(short* dst, long* src[], int count) 776static void write_samples(short* dst, int32_t* src[], int count)
777{ 777{
778 long* s0 = src[0]; 778 int32_t* s0 = src[0];
779 long* s1 = src[1]; 779 int32_t* s1 = src[1];
780 int scale = dsp->frac_bits + 1 - NATIVE_DEPTH; 780 int scale = dsp->frac_bits + 1 - NATIVE_DEPTH;
781 781
782 if (dsp->dither_enabled) 782 if (dsp->dither_enabled)
@@ -815,7 +815,7 @@ static void write_samples(short* dst, long* src[], int count)
815 */ 815 */
816long dsp_process(char* dst, const char* src[], long size) 816long dsp_process(char* dst, const char* src[], long size)
817{ 817{
818 long* tmp[2]; 818 int32_t* tmp[2];
819 long written = 0; 819 long written = 0;
820 long factor; 820 long factor;
821 int samples; 821 int samples;
@@ -980,7 +980,7 @@ bool dsp_configure(int setting, void *value)
980 else 980 else
981 { 981 {
982 dsp->frac_bits = (long) value; 982 dsp->frac_bits = (long) value;
983 dsp->sample_bytes = sizeof(long); 983 dsp->sample_bytes = 4; /* samples are 32 bits */
984 dsp->clip_max = (1 << (long)value) - 1; 984 dsp->clip_max = (1 << (long)value) - 1;
985 dsp->clip_min = -(1 << (long)value); 985 dsp->clip_min = -(1 << (long)value);
986 } 986 }