summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp/dsp_misc.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-12-19 17:34:57 -0500
committerMichael Sevakis <jethead71@rockbox.org>2013-05-04 13:43:33 -0400
commit78a45b47dede5ddf35dfc53e965b486a79177b18 (patch)
treeedb3ad7c101e600a7cc3be4b40380430cbeb3e55 /lib/rbcodec/dsp/dsp_misc.c
parentcdb71c707bb434f44368b72f2db3becc37b7a46c (diff)
downloadrockbox-78a45b47dede5ddf35dfc53e965b486a79177b18.tar.gz
rockbox-78a45b47dede5ddf35dfc53e965b486a79177b18.zip
Cleanup and simplify latest DSP code incarnation.
Some things can just be a bit simpler in handling the list of stages and some things, especially format change handling, can be simplified for each stage implementation. Format changes are sent through the configure() callback. Hide some internal details and variables from processing stages and let the core deal with it. Do some miscellaneous cleanup and keep things a bit better factored. Change-Id: I19dd8ce1d0b792ba914d426013088a49a52ecb7e
Diffstat (limited to 'lib/rbcodec/dsp/dsp_misc.c')
-rw-r--r--lib/rbcodec/dsp/dsp_misc.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/rbcodec/dsp/dsp_misc.c b/lib/rbcodec/dsp/dsp_misc.c
index 672212b267..a19ef52883 100644
--- a/lib/rbcodec/dsp/dsp_misc.c
+++ b/lib/rbcodec/dsp/dsp_misc.c
@@ -26,7 +26,6 @@
26#include "fixedpoint.h" 26#include "fixedpoint.h"
27#include "replaygain.h" 27#include "replaygain.h"
28#include "dsp_proc_entry.h" 28#include "dsp_proc_entry.h"
29#include "dsp_sample_io.h"
30#include "dsp_misc.h" 29#include "dsp_misc.h"
31#include "pga.h" 30#include "pga.h"
32#include "channel_mode.h" 31#include "channel_mode.h"
@@ -113,20 +112,21 @@ static int32_t pitch_ratio = PITCH_SPEED_100;
113 112
114static void dsp_pitch_update(struct dsp_config *dsp) 113static void dsp_pitch_update(struct dsp_config *dsp)
115{ 114{
116 /* Account for playback speed adjustment when setting dsp->frequency 115 dsp_configure(dsp, DSP_SET_PITCH,
117 if we're called from the main audio thread. Voice playback thread 116 fp_div(pitch_ratio, PITCH_SPEED_100, 16));
118 does not support this feature. */
119 struct sample_io_data *data = (void *)dsp;
120 data->format.frequency =
121 (int64_t)pitch_ratio * data->format.codec_frequency / PITCH_SPEED_100;
122} 117}
123 118
124static void dsp_set_pitch(int32_t percent) 119static void dsp_set_pitch(int32_t percent)
125{ 120{
126 pitch_ratio = percent > 0 ? percent : PITCH_SPEED_100; 121 if (percent <= 0)
127 struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO); 122 percent = PITCH_SPEED_100;
128 struct sample_io_data *data = (void *)dsp; 123
129 dsp_configure(dsp, DSP_SWITCH_FREQUENCY, data->format.codec_frequency); 124 if (percent == pitch_ratio)
125 return;
126
127 pitch_ratio = percent;
128
129 dsp_pitch_update(dsp_get_config(CODEC_IDX_AUDIO));
130} 130}
131#endif /* HAVE_PITCHCONTROL */ 131#endif /* HAVE_PITCHCONTROL */
132 132
@@ -173,6 +173,13 @@ int dsp_callback(int msg, intptr_t param)
173 return retval; 173 return retval;
174} 174}
175 175
176static void INIT_ATTR misc_dsp_init(struct dsp_config *dsp,
177 enum dsp_ids dsp_id)
178{
179 /* Enable us for the audio DSP at startup */
180 if (dsp_id == CODEC_IDX_AUDIO)
181 dsp_proc_enable(dsp, DSP_PROC_MISC_HANDLER, true);
182}
176 183
177/* This is a null-processing stage that monitors as an enabled stage but never 184/* This is a null-processing stage that monitors as an enabled stage but never
178 * becomes active in processing samples. It only hooks messages. */ 185 * becomes active in processing samples. It only hooks messages. */
@@ -186,9 +193,7 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this,
186 switch (setting) 193 switch (setting)
187 { 194 {
188 case DSP_INIT: 195 case DSP_INIT:
189 /* Enable us for the audio DSP at startup */ 196 misc_dsp_init(dsp, (enum dsp_ids)value);
190 if (value == CODEC_IDX_AUDIO)
191 dsp_proc_enable(dsp, DSP_PROC_MISC_HANDLER, true);
192 break; 197 break;
193 198
194 case DSP_PROC_CLOSE: 199 case DSP_PROC_CLOSE:
@@ -212,7 +217,7 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this,
212#endif 217#endif
213 } 218 }
214 219
215 return 1; 220 return 0;
216 (void)this; 221 (void)this;
217} 222}
218 223