summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp/tone_controls.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-05-23 13:58:51 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-07-06 04:22:04 +0200
commitd37bf24d9011addbfbd40942a4e9bbf26de7df00 (patch)
treedafb7eaeb494081668a4841d490fce2bfbb2438d /lib/rbcodec/dsp/tone_controls.c
parent00faabef5e902008172e08d3bcd77683cbafef51 (diff)
downloadrockbox-d37bf24d9011addbfbd40942a4e9bbf26de7df00.tar.gz
rockbox-d37bf24d9011addbfbd40942a4e9bbf26de7df00.zip
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 <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'lib/rbcodec/dsp/tone_controls.c')
-rw-r--r--lib/rbcodec/dsp/tone_controls.c29
1 files changed, 21 insertions, 8 deletions
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 @@
21 ****************************************************************************/ 21 ****************************************************************************/
22#include "rbcodecconfig.h" 22#include "rbcodecconfig.h"
23#include "platform.h" 23#include "platform.h"
24#include "fixedpoint.h"
24#include "dsp_proc_entry.h" 25#include "dsp_proc_entry.h"
25#include "dsp_filter.h" 26#include "dsp_filter.h"
26#include "tone_controls.h" 27#include "tone_controls.h"
28#include "dsp_misc.h"
27 29
28/* These apply to all DSP streams to remain as consistant as possible with 30/* These apply to all DSP streams to remain as consistant as possible with
29 * the behavior of hardware tone controls */ 31 * the behavior of hardware tone controls */
@@ -36,32 +38,39 @@ static const unsigned int tone_treble_cutoff = 3500;
36static int tone_bass = 0; 38static int tone_bass = 0;
37static int tone_treble = 0; 39static int tone_treble = 0;
38 40
41/* Current prescaler setting */
42static int tone_prescale = 0;
43
39/* Data for each DSP */ 44/* Data for each DSP */
40static struct dsp_filter tone_filters[DSP_COUNT] IBSS_ATTR; 45static struct dsp_filter tone_filters[DSP_COUNT] IBSS_ATTR;
41 46
47static void update_filter(int id, unsigned int fout)
48{
49 filter_bishelf_coefs(fp_div(tone_bass_cutoff, fout, 32),
50 fp_div(tone_treble_cutoff, fout, 32),
51 tone_bass, tone_treble, -tone_prescale,
52 &tone_filters[id]);
53}
54
42/* Update the filters' coefficients based upon the bass/treble settings */ 55/* Update the filters' coefficients based upon the bass/treble settings */
43void tone_set_prescale(int prescale) 56void tone_set_prescale(int prescale)
44{ 57{
45 int bass = tone_bass; 58 int bass = tone_bass;
46 int treble = tone_treble; 59 int treble = tone_treble;
47 60
48 struct dsp_filter tone_filter; /* Temp to hold new version */ 61 tone_prescale = prescale;
49 filter_bishelf_coefs(0xffffffff / NATIVE_FREQUENCY * tone_bass_cutoff,
50 0xffffffff / NATIVE_FREQUENCY * tone_treble_cutoff,
51 bass, treble, -prescale, &tone_filter);
52 62
53 struct dsp_config *dsp; 63 struct dsp_config *dsp;
54 for (int i = 0; (dsp = dsp_get_config(i)); i++) 64 for (int i = 0; (dsp = dsp_get_config(i)); i++)
55 { 65 {
56 struct dsp_filter *filter = &tone_filters[i]; 66 update_filter(i, dsp_get_output_frequency(dsp));
57 filter_copy(filter, &tone_filter);
58 67
59 bool enable = bass != 0 || treble != 0; 68 bool enable = bass != 0 || treble != 0;
60 dsp_proc_enable(dsp, DSP_PROC_TONE_CONTROLS, enable); 69 dsp_proc_enable(dsp, DSP_PROC_TONE_CONTROLS, enable);
61 70
62 if (!dsp_proc_active(dsp, DSP_PROC_TONE_CONTROLS)) 71 if (enable && !dsp_proc_active(dsp, DSP_PROC_TONE_CONTROLS))
63 { 72 {
64 filter_flush(filter); /* Going online */ 73 filter_flush(&tone_filters[i]); /* Going online */
65 dsp_proc_activate(dsp, DSP_PROC_TONE_CONTROLS, true); 74 dsp_proc_activate(dsp, DSP_PROC_TONE_CONTROLS, true);
66 } 75 }
67 } 76 }
@@ -109,6 +118,10 @@ static intptr_t tone_configure(struct dsp_proc_entry *this,
109 case DSP_FLUSH: 118 case DSP_FLUSH:
110 filter_flush((struct dsp_filter *)this->data); 119 filter_flush((struct dsp_filter *)this->data);
111 break; 120 break;
121
122 case DSP_SET_OUT_FREQUENCY:
123 update_filter(dsp_get_id(dsp), value);
124 break;
112 } 125 }
113 126
114 return 0; 127 return 0;