summaryrefslogtreecommitdiff
path: root/apps/dsp.c
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2006-02-07 14:07:46 +0000
committerDan Everton <dan@iocaine.org>2006-02-07 14:07:46 +0000
commit88abdd97b25eb458466a84f614a518b7173265a8 (patch)
tree4a70e3d0d829125e458c80fb21ccf82c77733e36 /apps/dsp.c
parent27f69db40494ca63887fce941dfe02dbd5f24d5b (diff)
downloadrockbox-88abdd97b25eb458466a84f614a518b7173265a8.tar.gz
rockbox-88abdd97b25eb458466a84f614a518b7173265a8.zip
Add Equalizer configuration to Sound Settings menu.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8606 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/dsp.c')
-rw-r--r--apps/dsp.c61
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
150struct resample_data 151struct 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 */
627void 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. */
622static void eq_process(long **x, unsigned num) 678static 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;