diff options
Diffstat (limited to 'lib/rbcodec/dsp/tone_controls.c')
-rw-r--r-- | lib/rbcodec/dsp/tone_controls.c | 29 |
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; | |||
36 | static int tone_bass = 0; | 38 | static int tone_bass = 0; |
37 | static int tone_treble = 0; | 39 | static int tone_treble = 0; |
38 | 40 | ||
41 | /* Current prescaler setting */ | ||
42 | static int tone_prescale = 0; | ||
43 | |||
39 | /* Data for each DSP */ | 44 | /* Data for each DSP */ |
40 | static struct dsp_filter tone_filters[DSP_COUNT] IBSS_ATTR; | 45 | static struct dsp_filter tone_filters[DSP_COUNT] IBSS_ATTR; |
41 | 46 | ||
47 | static 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 */ |
43 | void tone_set_prescale(int prescale) | 56 | void 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; |