diff options
-rw-r--r-- | apps/dsp.c | 98 | ||||
-rw-r--r-- | apps/eq.c | 3 | ||||
-rw-r--r-- | apps/eq.h | 8 |
3 files changed, 56 insertions, 53 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 | |||
192 | struct resample_data | 192 | struct 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 | ||
198 | struct dither_data | 198 | struct dither_data |
@@ -203,9 +203,9 @@ struct dither_data | |||
203 | 203 | ||
204 | struct crossfeed_data | 204 | struct 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 | ||
236 | static long sample_buf[SAMPLE_BUF_SIZE] IBSS_ATTR; | 236 | static int32_t sample_buf[SAMPLE_BUF_SIZE] IBSS_ATTR; |
237 | static long resample_buf[RESAMPLE_BUF_SIZE] IBSS_ATTR; | 237 | static int32_t resample_buf[RESAMPLE_BUF_SIZE] IBSS_ATTR; |
238 | 238 | ||
239 | int sound_get_pitch(void) | 239 | int 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 | */ |
257 | static int convert_to_internal(const char* src[], int count, long* dst[]) | 257 | static 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. */ |
351 | static long downsample(long **dst, long **src, int count, | 351 | static 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 | ||
391 | static long upsample(long **dst, long **src, int count, struct resample_data *r) | 391 | static 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 | */ |
430 | static inline int resample(long* src[], int count) | 430 | static 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 | ||
463 | static inline long clip_sample(long sample, long min, long max) | 463 | static 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 | ||
481 | static long dither_sample(long sample, long bias, long mask, | 481 | static 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 | ||
526 | static void apply_crossfeed(long* src[], int count) | 526 | static 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 |
601 | static void apply_crossfeed(long* src[], int count) | 601 | static 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. */ |
714 | static void eq_process(long **x, unsigned num) | 714 | static 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 | */ |
739 | static void apply_gain(long* _src[], int _count) | 739 | static 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 | ||
776 | static void write_samples(short* dst, long* src[], int count) | 776 | static 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 | */ |
816 | long dsp_process(char* dst, const char* src[], long size) | 816 | long 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 | } |
@@ -17,6 +17,7 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include <inttypes.h> | ||
20 | #include "config.h" | 21 | #include "config.h" |
21 | #include "eq.h" | 22 | #include "eq.h" |
22 | 23 | ||
@@ -214,7 +215,7 @@ void eq_hs_coefs(unsigned long cutoff, unsigned long Q, long db, long *c) | |||
214 | } | 215 | } |
215 | 216 | ||
216 | #if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR) | 217 | #if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR) |
217 | void eq_filter(long **x, struct eqfilter *f, unsigned num, | 218 | void eq_filter(int32_t **x, struct eqfilter *f, unsigned num, |
218 | unsigned channels, unsigned shift) | 219 | unsigned channels, unsigned shift) |
219 | { | 220 | { |
220 | unsigned c, i; | 221 | unsigned c, i; |
@@ -20,6 +20,8 @@ | |||
20 | #ifndef _EQ_H | 20 | #ifndef _EQ_H |
21 | #define _EQ_H | 21 | #define _EQ_H |
22 | 22 | ||
23 | #include <inttypes.h> | ||
24 | |||
23 | /* These depend on the fixed point formats used by the different filter types | 25 | /* These depend on the fixed point formats used by the different filter types |
24 | and need to be changed when they change. | 26 | and need to be changed when they change. |
25 | */ | 27 | */ |
@@ -27,14 +29,14 @@ | |||
27 | #define EQ_SHELF_SHIFT 8 | 29 | #define EQ_SHELF_SHIFT 8 |
28 | 30 | ||
29 | struct eqfilter { | 31 | struct eqfilter { |
30 | long coefs[5]; /* Order is b0, b1, b2, a1, a2 */ | 32 | int32_t coefs[5]; /* Order is b0, b1, b2, a1, a2 */ |
31 | long history[2][4]; | 33 | int32_t history[2][4]; |
32 | }; | 34 | }; |
33 | 35 | ||
34 | void eq_pk_coefs(unsigned long cutoff, unsigned long Q, long db, long *c); | 36 | void eq_pk_coefs(unsigned long cutoff, unsigned long Q, long db, long *c); |
35 | void eq_ls_coefs(unsigned long cutoff, unsigned long Q, long db, long *c); | 37 | void eq_ls_coefs(unsigned long cutoff, unsigned long Q, long db, long *c); |
36 | void eq_hs_coefs(unsigned long cutoff, unsigned long Q, long db, long *c); | 38 | void eq_hs_coefs(unsigned long cutoff, unsigned long Q, long db, long *c); |
37 | void eq_filter(long **x, struct eqfilter *f, unsigned num, | 39 | void eq_filter(int32_t **x, struct eqfilter *f, unsigned num, |
38 | unsigned channels, unsigned shift); | 40 | unsigned channels, unsigned shift); |
39 | 41 | ||
40 | #endif | 42 | #endif |