From 621bcc22940aed0242ed1795491a400521d2394d Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Sat, 4 Feb 2006 23:15:15 +0000 Subject: The simulator should use the keypad period key, not the regular one git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8568 a1c6a512-1295-4272-9138-f99709370657 --- apps/dsp.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'apps/dsp.c') diff --git a/apps/dsp.c b/apps/dsp.c index 789cf72b20..f403674ba2 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -145,6 +145,7 @@ struct dsp_config bool dither_enabled; bool new_gain; bool crossfeed_enabled; + bool eq_enabled; }; struct resample_data @@ -618,6 +619,52 @@ static void apply_crossfeed(long* src[], int count) } #endif +#define EQ_CUTOFF_USER2REAL(x) (0xffffffff / dsp->frequency * (x)) +#define EQ_Q_USER2REAL(x) (((x) << 16) / 10) +#define EQ_GAIN_USER2REAL(x) (((x) << 16) / 10) + +/* Synchronize the EQ filters with the global settings */ +static void eq_update_data() +{ + int i; + int *setting; + int gain, cutoff, q, maxgain; + + /* Don't do anything if we're not playing */ + if (dsp->frequency == 0) + return; + + setting = &global_settings.eq_band0_cutoff; + maxgain = 0; + + /* Iterate over each band and update the appropriate filter */ + for(i = 0; i < 5; i++) { + cutoff = *setting++; + q = *setting++; + gain = *setting++; + + /* Keep track of maxgain for the pre-amp */ + if (gain > maxgain) + maxgain = gain; + + if (gain == 0) { + eq_data.enabled[i] = 0; + } else { + if (i == 0) + eq_ls_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), + EQ_GAIN_USER2REAL(gain), eq_data.filters[0].coefs); + else if (i == 4) + eq_hs_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), + EQ_GAIN_USER2REAL(gain), eq_data.filters[4].coefs); + else + eq_pk_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), + EQ_GAIN_USER2REAL(gain), eq_data.filters[i].coefs); + + eq_data.enabled[i] = 1; + } + } +} + /* Apply EQ filters to those bands that have got it switched on. */ static void eq_process(long **x, unsigned num) { @@ -737,6 +784,9 @@ long dsp_process(char* dst, char* src[], long size) size /= dsp->sample_bytes * factor; dsp_set_replaygain(false); + if (dsp->eq_enabled) + eq_update_data(); + while (size > 0) { samples = convert_to_internal(src, size, tmp); @@ -745,8 +795,7 @@ long dsp_process(char* dst, char* src[], long size) samples = resample(tmp, samples); if (dsp->crossfeed_enabled && dsp->stereo_mode != STEREO_MONO) apply_crossfeed(tmp, samples); - /* TODO: Might want to wrap this with a generic eq_enabled when the - settings are in place */ + if (dsp->eq_enabled) eq_process(tmp, samples); write_samples((short*) dst, tmp, samples); written += samples; @@ -943,6 +992,11 @@ bool dsp_configure(int setting, void *value) return 1; } +void dsp_set_eq(bool enable) +{ + dsp->eq_enabled = enable; +} + void dsp_set_crossfeed(bool enable) { if (enable) -- cgit v1.2.3