From d37bf24d9011addbfbd40942a4e9bbf26de7df00 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 23 May 2013 13:58:51 -0400 Subject: Enable setting of global output samplerate on certain targets. Replaces the NATIVE_FREQUENCY constant with a configurable frequency. The user may select 48000Hz if the hardware supports it. The default is still 44100Hz and the minimum is 44100Hz. The setting is located in the playback settings, under "Frequency". "Frequency" was duplicated in english.lang for now to avoid having to fix every .lang file for the moment and throwing everything out of sync because of the new play_frequency feature in features.txt. The next cleanup should combine it with the one included for recording and generalize the ID label. If the hardware doesn't support 48000Hz, no setting will be available. On particular hardware where very high rates are practical and desireable, the upper bound can be extended by patching. The PCM mixer can be configured to play at the full hardware frequency range. The DSP core can configure to the hardware minimum up to the maximum playback setting (some buffers must be reserved according to the maximum rate). If only 44100Hz is supported or possible on a given target for playback, using the DSP and mixer at other samperates is possible if the hardware offers them. Change-Id: I6023cf0c0baa8bc6292b6919b4dd3618a6a25622 Reviewed-on: http://gerrit.rockbox.org/479 Reviewed-by: Michael Sevakis Tested-by: Michael Sevakis --- lib/rbcodec/dsp/tone_controls.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'lib/rbcodec/dsp/tone_controls.c') diff --git a/lib/rbcodec/dsp/tone_controls.c b/lib/rbcodec/dsp/tone_controls.c index e636b04b9a..4266af4d97 100644 --- a/lib/rbcodec/dsp/tone_controls.c +++ b/lib/rbcodec/dsp/tone_controls.c @@ -21,9 +21,11 @@ ****************************************************************************/ #include "rbcodecconfig.h" #include "platform.h" +#include "fixedpoint.h" #include "dsp_proc_entry.h" #include "dsp_filter.h" #include "tone_controls.h" +#include "dsp_misc.h" /* These apply to all DSP streams to remain as consistant as possible with * the behavior of hardware tone controls */ @@ -36,32 +38,39 @@ static const unsigned int tone_treble_cutoff = 3500; static int tone_bass = 0; static int tone_treble = 0; +/* Current prescaler setting */ +static int tone_prescale = 0; + /* Data for each DSP */ static struct dsp_filter tone_filters[DSP_COUNT] IBSS_ATTR; +static void update_filter(int id, unsigned int fout) +{ + filter_bishelf_coefs(fp_div(tone_bass_cutoff, fout, 32), + fp_div(tone_treble_cutoff, fout, 32), + tone_bass, tone_treble, -tone_prescale, + &tone_filters[id]); +} + /* Update the filters' coefficients based upon the bass/treble settings */ void tone_set_prescale(int prescale) { int bass = tone_bass; int treble = tone_treble; - struct dsp_filter tone_filter; /* Temp to hold new version */ - filter_bishelf_coefs(0xffffffff / NATIVE_FREQUENCY * tone_bass_cutoff, - 0xffffffff / NATIVE_FREQUENCY * tone_treble_cutoff, - bass, treble, -prescale, &tone_filter); + tone_prescale = prescale; struct dsp_config *dsp; for (int i = 0; (dsp = dsp_get_config(i)); i++) { - struct dsp_filter *filter = &tone_filters[i]; - filter_copy(filter, &tone_filter); + update_filter(i, dsp_get_output_frequency(dsp)); bool enable = bass != 0 || treble != 0; dsp_proc_enable(dsp, DSP_PROC_TONE_CONTROLS, enable); - if (!dsp_proc_active(dsp, DSP_PROC_TONE_CONTROLS)) + if (enable && !dsp_proc_active(dsp, DSP_PROC_TONE_CONTROLS)) { - filter_flush(filter); /* Going online */ + filter_flush(&tone_filters[i]); /* Going online */ dsp_proc_activate(dsp, DSP_PROC_TONE_CONTROLS, true); } } @@ -109,6 +118,10 @@ static intptr_t tone_configure(struct dsp_proc_entry *this, case DSP_FLUSH: filter_flush((struct dsp_filter *)this->data); break; + + case DSP_SET_OUT_FREQUENCY: + update_filter(dsp_get_id(dsp), value); + break; } return 0; -- cgit v1.2.3