diff options
Diffstat (limited to 'apps/dsp.c')
-rw-r--r-- | apps/dsp.c | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/apps/dsp.c b/apps/dsp.c index 789cf72b20..e4d28bd083 100644 --- a/apps/dsp.c +++ b/apps/dsp.c | |||
@@ -145,6 +145,7 @@ struct dsp_config | |||
145 | bool dither_enabled; | 145 | bool dither_enabled; |
146 | bool new_gain; | 146 | bool new_gain; |
147 | bool crossfeed_enabled; | 147 | bool crossfeed_enabled; |
148 | bool eq_enabled; | ||
148 | }; | 149 | }; |
149 | 150 | ||
150 | struct resample_data | 151 | struct resample_data |
@@ -618,6 +619,61 @@ static void apply_crossfeed(long* src[], int count) | |||
618 | } | 619 | } |
619 | #endif | 620 | #endif |
620 | 621 | ||
622 | #define EQ_CUTOFF_USER2REAL(x) (0xffffffff / NATIVE_FREQUENCY * (x)) | ||
623 | #define EQ_Q_USER2REAL(x) (((x) << 16) / 10) | ||
624 | #define EQ_GAIN_USER2REAL(x) (((x) << 16) / 10) | ||
625 | |||
626 | /* Synchronize the EQ filters with the global settings */ | ||
627 | void dsp_eq_update_data(bool enabled) | ||
628 | { | ||
629 | int i; | ||
630 | int *setting; | ||
631 | int gain, cutoff, q, maxgain; | ||
632 | |||
633 | dsp->eq_enabled = enabled; | ||
634 | setting = &global_settings.eq_band0_cutoff; | ||
635 | maxgain = 0; | ||
636 | |||
637 | #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) | ||
638 | /* set emac unit for dsp processing, and save old macsr, we're running in | ||
639 | codec thread context at this point, so can't clobber it */ | ||
640 | unsigned long old_macsr = coldfire_get_macsr(); | ||
641 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); | ||
642 | #endif | ||
643 | |||
644 | /* Iterate over each band and update the appropriate filter */ | ||
645 | for(i = 0; i < 5; i++) { | ||
646 | cutoff = *setting++; | ||
647 | q = *setting++; | ||
648 | gain = *setting++; | ||
649 | |||
650 | /* Keep track of maxgain for the pre-amp */ | ||
651 | if (gain > maxgain) | ||
652 | maxgain = gain; | ||
653 | |||
654 | if (gain == 0) { | ||
655 | eq_data.enabled[i] = 0; | ||
656 | } else { | ||
657 | if (i == 0) | ||
658 | eq_ls_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), | ||
659 | EQ_GAIN_USER2REAL(gain), eq_data.filters[0].coefs); | ||
660 | else if (i == 4) | ||
661 | eq_hs_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), | ||
662 | EQ_GAIN_USER2REAL(gain), eq_data.filters[4].coefs); | ||
663 | else | ||
664 | eq_pk_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), | ||
665 | EQ_GAIN_USER2REAL(gain), eq_data.filters[i].coefs); | ||
666 | |||
667 | eq_data.enabled[i] = 1; | ||
668 | } | ||
669 | } | ||
670 | |||
671 | #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) | ||
672 | /* set old macsr again */ | ||
673 | coldfire_set_macsr(old_macsr); | ||
674 | #endif | ||
675 | } | ||
676 | |||
621 | /* Apply EQ filters to those bands that have got it switched on. */ | 677 | /* Apply EQ filters to those bands that have got it switched on. */ |
622 | static void eq_process(long **x, unsigned num) | 678 | static void eq_process(long **x, unsigned num) |
623 | { | 679 | { |
@@ -745,9 +801,8 @@ long dsp_process(char* dst, char* src[], long size) | |||
745 | samples = resample(tmp, samples); | 801 | samples = resample(tmp, samples); |
746 | if (dsp->crossfeed_enabled && dsp->stereo_mode != STEREO_MONO) | 802 | if (dsp->crossfeed_enabled && dsp->stereo_mode != STEREO_MONO) |
747 | apply_crossfeed(tmp, samples); | 803 | apply_crossfeed(tmp, samples); |
748 | /* TODO: Might want to wrap this with a generic eq_enabled when the | 804 | if (dsp->eq_enabled) |
749 | settings are in place */ | 805 | eq_process(tmp, samples); |
750 | eq_process(tmp, samples); | ||
751 | write_samples((short*) dst, tmp, samples); | 806 | write_samples((short*) dst, tmp, samples); |
752 | written += samples; | 807 | written += samples; |
753 | dst += samples * sizeof(short) * 2; | 808 | dst += samples * sizeof(short) * 2; |