summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp/surround.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-10-12 05:51:46 -0400
committerMichael Sevakis <jethead71@rockbox.org>2017-10-12 05:59:18 -0400
commita8e4b3a1906f05f6ab7fc1ee94e0be513cb2c86a (patch)
tree09fe0e2c798b65aa6db58f7aa2b4c98942c8bba2 /lib/rbcodec/dsp/surround.c
parent5eee28e37d78e0679fc5aa8488e5408429153e4c (diff)
downloadrockbox-a8e4b3a1906f05f6ab7fc1ee94e0be513cb2c86a.tar.gz
rockbox-a8e4b3a1906f05f6ab7fc1ee94e0be513cb2c86a.zip
PBE+Surround: Localize some variables and fixup some flush ops
Change-Id: I9fba5b8cbf69d261a7ca1c66e080c08d2fc6d9db
Diffstat (limited to 'lib/rbcodec/dsp/surround.c')
-rw-r--r--lib/rbcodec/dsp/surround.c106
1 files changed, 47 insertions, 59 deletions
diff --git a/lib/rbcodec/dsp/surround.c b/lib/rbcodec/dsp/surround.c
index f3349b34e5..1a24d615fc 100644
--- a/lib/rbcodec/dsp/surround.c
+++ b/lib/rbcodec/dsp/surround.c
@@ -44,10 +44,6 @@ static int surround_strength = 0;
44#define BB_DLY (MAX_DLY/4 + 1) 44#define BB_DLY (MAX_DLY/4 + 1)
45#define HH_DLY (MAX_DLY/2 + 1) 45#define HH_DLY (MAX_DLY/2 + 1)
46#define CL_DLY B2_DLY 46#define CL_DLY B2_DLY
47/*only need to buffer right channel */
48static int32_t *b0, *b2, *bb, *hh, *cl;
49static int32_t temp_buffer[2];
50static int32_t mid, side;
51 47
52/*voice from 300hz - 3400hz ?*/ 48/*voice from 300hz - 3400hz ?*/
53static int32_t tcoef1,tcoef2,bcoef,hcoef; 49static int32_t tcoef1,tcoef2,bcoef,hcoef;
@@ -80,15 +76,6 @@ static void surround_buffer_free(void)
80 handle = -1; 76 handle = -1;
81} 77}
82 78
83static void surround_buffer_get_data(void)
84{
85 b0 = core_get_data(handle);
86 b2 = b0 + B0_DLY;
87 bb = b2 + B2_DLY;
88 hh = bb + BB_DLY;
89 cl = hh + HH_DLY;
90}
91
92static void dsp_surround_flush(void) 79static void dsp_surround_flush(void)
93{ 80{
94 memset(core_get_data(handle), 0, SURROUND_BUFSIZE); 81 memset(core_get_data(handle), 0, SURROUND_BUFSIZE);
@@ -109,16 +96,7 @@ void dsp_surround_set_balance(int var)
109 96
110void dsp_surround_side_only(bool var) 97void dsp_surround_side_only(bool var)
111{ 98{
112 if (var == surround_side_only)
113 return; /* No setting change */
114
115 surround_side_only = var; 99 surround_side_only = var;
116
117 struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
118 if (!dsp_proc_enabled(dsp, DSP_PROC_SURROUND))
119 return;
120
121 dsp_surround_flush();
122} 100}
123 101
124void dsp_surround_mix(int var) 102void dsp_surround_mix(int var)
@@ -143,7 +121,9 @@ void dsp_surround_set_cutoff(int frq_l, int frq_h)
143 121
144static void surround_set_stepsize(int surround_strength) 122static void surround_set_stepsize(int surround_strength)
145{ 123{
146 dsp_surround_flush(); 124 if (handle > 0)
125 dsp_surround_flush();
126
147 switch(surround_strength) 127 switch(surround_strength)
148 { 128 {
149 case 1: 129 case 1:
@@ -175,7 +155,7 @@ void dsp_surround_enable(int var)
175 bool was_enabled = dsp_proc_enabled(dsp, DSP_PROC_SURROUND); 155 bool was_enabled = dsp_proc_enabled(dsp, DSP_PROC_SURROUND);
176 bool now_enabled = var > 0; 156 bool now_enabled = var > 0;
177 157
178 if (was_enabled == now_enabled && !now_enabled) 158 if (was_enabled == now_enabled)
179 return; /* No change in enabled status */ 159 return; /* No change in enabled status */
180 160
181 if (now_enabled) 161 if (now_enabled)
@@ -201,88 +181,96 @@ static void surround_process(struct dsp_proc_entry *this,
201 int i; 181 int i;
202 int32_t x; 182 int32_t x;
203 183
204 surround_buffer_get_data(); 184 /*only need to buffer right channel */
185 static int32_t *b0, *b2, *bb, *hh, *cl;
186
187 b0 = core_get_data(handle);
188 b2 = b0 + B0_DLY;
189 bb = b2 + B2_DLY;
190 hh = bb + BB_DLY;
191 cl = hh + HH_DLY;
205 192
206 for (i = 0; i < count; i++) 193 for (i = 0; i < count; i++)
207 { 194 {
208 mid = buf->p32[0][i] /2 + buf->p32[1][i] /2; 195 int32_t mid = buf->p32[0][i] / 2 + buf->p32[1][i] / 2;
209 side = buf->p32[0][i] - buf->p32[1][i]; 196 int32_t side = buf->p32[0][i] - buf->p32[1][i];
197 int32_t temp0, temp1;
210 198
211 if (!surround_side_only) 199 if (!surround_side_only)
212 { 200 {
213 /*clone the left channal*/ 201 /*clone the left channal*/
214 temp_buffer[0]= buf->p32[0][i]; 202 temp0 = buf->p32[0][i];
215 /*keep the middle band of right channel*/ 203 /*keep the middle band of right channel*/
216 temp_buffer[1]= FRACMUL(buf->p32[1][i], tcoef1) - 204 temp1 = FRACMUL(buf->p32[1][i], tcoef1) -
217 FRACMUL(buf->p32[1][i], tcoef2); 205 FRACMUL(buf->p32[1][i], tcoef2);
218 } 206 }
219 else /* apply haas to side only*/ 207 else /* apply haas to side only*/
220 { 208 {
221 temp_buffer[0] = side / 2; 209 temp0 = side / 2;
222 temp_buffer[1] = FRACMUL(-side,tcoef1)/2 - 210 temp1 = FRACMUL(-side, tcoef1) / 2 -
223 FRACMUL(-side, tcoef2)/2; 211 FRACMUL(-side, tcoef2) / 2;
224 } 212 }
225 213
226 /* inverted crossfeed delay (left channel) to make sound wider*/ 214 /* inverted crossfeed delay (left channel) to make sound wider*/
227 x = temp_buffer[1]/100 * 35; 215 x = temp1/100 * 35;
228 temp_buffer[0] += dequeue(cl, &cl_r, dly); 216 temp0 += dequeue(cl, &cl_r, dly);
229 enqueue(-x, cl, &cl_w, dly); 217 enqueue(-x, cl, &cl_w, dly);
230 218
231 /* apply 1/8 delay to frequency below fx2 */ 219 /* apply 1/8 delay to frequency below fx2 */
232 x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], tcoef1); 220 x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], tcoef1);
233 temp_buffer[1] += dequeue(b0, &b0_r, dly_shift3); 221 temp1 += dequeue(b0, &b0_r, dly_shift3);
234 enqueue(x, b0, &b0_w, dly_shift3 ); 222 enqueue(x, b0, &b0_w, dly_shift3 );
235 223
236 /* cut frequency below half fx2*/ 224 /* cut frequency below half fx2*/
237 temp_buffer[1] = FRACMUL(temp_buffer[1], bcoef); 225 temp1 = FRACMUL(temp1, bcoef);
238 226
239 /* apply 1/4 delay to frequency below half fx2 */ 227 /* apply 1/4 delay to frequency below half fx2 */
240 /* use different delay to fake the sound direction*/ 228 /* use different delay to fake the sound direction*/
241 x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], bcoef); 229 x = buf->p32[1][i] - FRACMUL(buf->p32[1][i], bcoef);
242 temp_buffer[1] += dequeue(bb, &bb_r, dly_shift2); 230 temp1 += dequeue(bb, &bb_r, dly_shift2);
243 enqueue(x, bb, &bb_w, dly_shift2 ); 231 enqueue(x, bb, &bb_w, dly_shift2 );
244 232
245 /* apply full delay to higher band */ 233 /* apply full delay to higher band */
246 x = FRACMUL(buf->p32[1][i], tcoef2); 234 x = FRACMUL(buf->p32[1][i], tcoef2);
247 temp_buffer[1] += dequeue(b2, &b2_r, dly); 235 temp1 += dequeue(b2, &b2_r, dly);
248 enqueue(x, b2, &b2_w, dly ); 236 enqueue(x, b2, &b2_w, dly );
249 237
250 /* do the same direction trick again */ 238 /* do the same direction trick again */
251 temp_buffer[1] -= FRACMUL(temp_buffer[1], hcoef); 239 temp1 -= FRACMUL(temp1, hcoef);
252 240
253 x = FRACMUL(buf->p32[1][i], hcoef); 241 x = FRACMUL(buf->p32[1][i], hcoef);
254 temp_buffer[1] += dequeue(hh, &hh_r, dly_shift1); 242 temp1 += dequeue(hh, &hh_r, dly_shift1);
255 enqueue(x, hh, &hh_w, dly_shift1 ); 243 enqueue(x, hh, &hh_w, dly_shift1 );
256 /*balance*/ 244 /*balance*/
257 if (surround_balance > 0 && !surround_side_only) 245 if (surround_balance > 0 && !surround_side_only)
258 { 246 {
259 temp_buffer[0] -= temp_buffer[0]/200 * surround_balance; 247 temp0 -= temp0/200 * surround_balance;
260 temp_buffer[1] += temp_buffer[1]/200 * surround_balance; 248 temp1 += temp1/200 * surround_balance;
261 } 249 }
262 else if (surround_balance > 0) 250 else if (surround_balance > 0)
263 { 251 {
264 temp_buffer[0] += temp_buffer[0]/200 * surround_balance; 252 temp0 += temp0/200 * surround_balance;
265 temp_buffer[1] -= temp_buffer[1]/200 * surround_balance; 253 temp1 -= temp1/200 * surround_balance;
266 } 254 }
267 255
268 if (surround_side_only) 256 if (surround_side_only)
269 { 257 {
270 temp_buffer[0] += mid; 258 temp0 += mid;
271 temp_buffer[1] += mid; 259 temp1 += mid;
272 } 260 }
273 261
274 if (surround_mix == 100) 262 if (surround_mix == 100)
275 { 263 {
276 buf->p32[0][i] = temp_buffer[0]; 264 buf->p32[0][i] = temp0;
277 buf->p32[1][i] = temp_buffer[1]; 265 buf->p32[1][i] = temp1;
278 } 266 }
279 else 267 else
280 { 268 {
281 /*dry wet mix*/ 269 /*dry wet mix*/
282 buf->p32[0][i] = buf->p32[0][i]/100 * (100-surround_mix) + 270 buf->p32[0][i] = buf->p32[0][i]/100 * (100-surround_mix) +
283 temp_buffer[0]/100 * surround_mix; 271 temp0/100 * surround_mix;
284 buf->p32[1][i] = buf->p32[1][i]/100 * (100-surround_mix) + 272 buf->p32[1][i] = buf->p32[1][i]/100 * (100-surround_mix) +
285 temp_buffer[1]/100 * surround_mix; 273 temp1/100 * surround_mix;
286 } 274 }
287 } 275 }
288 (void)this; 276 (void)this;
@@ -326,16 +314,16 @@ static intptr_t surround_configure(struct dsp_proc_entry *this,
326 switch (setting) 314 switch (setting)
327 { 315 {
328 case DSP_PROC_INIT: 316 case DSP_PROC_INIT:
329 if (value == 0) 317 /* Coming online; was disabled */
330 { 318 retval = surround_buffer_alloc();
331 retval = surround_buffer_alloc(); 319 if (retval < 0)
332 if (retval < 0) 320 break;
333 break;
334 321
335 this->process = surround_process; 322 this->process = surround_process;
336 } 323
337 /* else additional forced messages */ 324 dsp_surround_flush();
338 325
326 /* Wouldn't have been getting frequency updates */
339 surround_update_filter(dsp_get_output_frequency(dsp)); 327 surround_update_filter(dsp_get_output_frequency(dsp));
340 break; 328 break;
341 329