diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/recorder/recording.c | 121 |
1 files changed, 63 insertions, 58 deletions
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index c51569ad31..0a21d96566 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c | |||
@@ -119,6 +119,8 @@ static short balance_mem[BAL_MEM_SIZE]; | |||
119 | 119 | ||
120 | /* Automatic Gain Control */ | 120 | /* Automatic Gain Control */ |
121 | #define AGC_MODE_SIZE 5 | 121 | #define AGC_MODE_SIZE 5 |
122 | #define AGC_SAFETY_MODE 0 | ||
123 | |||
122 | static char* agc_preset_str[] = | 124 | static char* agc_preset_str[] = |
123 | { "Off", "S", "L", "D", "M", "V" }; | 125 | { "Off", "S", "L", "D", "M", "V" }; |
124 | /* "Off", | 126 | /* "Off", |
@@ -282,71 +284,73 @@ void auto_gain_control(int *peak_l, int *peak_r, int *balance) | |||
282 | return; | 284 | return; |
283 | } | 285 | } |
284 | 286 | ||
285 | /* Automatic balance control */ | 287 | if (agc_mode != AGC_SAFETY_MODE) { |
286 | if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG)) | 288 | /* Automatic balance control - only if not in safety mode */ |
287 | { | 289 | if ((agc_left > AGC_IMG) && (agc_right > AGC_IMG)) |
288 | if (*balance < -556) | ||
289 | { | ||
290 | if (*balance > -900) | ||
291 | agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */ | ||
292 | else if (*balance > -4125) | ||
293 | agc_baltime--; /* 0.75 - 3.00dB */ | ||
294 | else if (*balance > -7579) | ||
295 | agc_baltime -= 2; /* 3.00 - 4.90dB */ | ||
296 | else | ||
297 | agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */ | ||
298 | if (agc_baltime > 0) | ||
299 | agc_baltime -= (peak_time % 2); | ||
300 | } | ||
301 | else if (*balance > 556) | ||
302 | { | 290 | { |
303 | if (*balance < 900) | 291 | if (*balance < -556) |
304 | agc_baltime += !(peak_time % 4); | 292 | { |
305 | else if (*balance < 4125) | 293 | if (*balance > -900) |
306 | agc_baltime++; | 294 | agc_baltime -= !(peak_time % 4); /* 0.47 - 0.75dB */ |
307 | else if (*balance < 7579) | 295 | else if (*balance > -4125) |
308 | agc_baltime += 2; | 296 | agc_baltime--; /* 0.75 - 3.00dB */ |
309 | else | 297 | else if (*balance > -7579) |
310 | agc_baltime += !(peak_time % 8); | 298 | agc_baltime -= 2; /* 3.00 - 4.90dB */ |
311 | if (agc_baltime < 0) | 299 | else |
312 | agc_baltime += (peak_time % 2); | 300 | agc_baltime -= !(peak_time % 8); /* 4.90 - inf dB */ |
313 | } | 301 | if (agc_baltime > 0) |
302 | agc_baltime -= (peak_time % 2); | ||
303 | } | ||
304 | else if (*balance > 556) | ||
305 | { | ||
306 | if (*balance < 900) | ||
307 | agc_baltime += !(peak_time % 4); | ||
308 | else if (*balance < 4125) | ||
309 | agc_baltime++; | ||
310 | else if (*balance < 7579) | ||
311 | agc_baltime += 2; | ||
312 | else | ||
313 | agc_baltime += !(peak_time % 8); | ||
314 | if (agc_baltime < 0) | ||
315 | agc_baltime += (peak_time % 2); | ||
316 | } | ||
314 | 317 | ||
315 | if ((*balance * agc_baltime) < 0) | 318 | if ((*balance * agc_baltime) < 0) |
316 | { | 319 | { |
317 | if (*balance < 0) | 320 | if (*balance < 0) |
318 | agc_baltime -= peak_time % 2; | 321 | agc_baltime -= peak_time % 2; |
319 | else | 322 | else |
320 | agc_baltime += peak_time % 2; | 323 | agc_baltime += peak_time % 2; |
321 | } | 324 | } |
322 | 325 | ||
323 | increment = ((agc_risetime / 2) > agc_droptime); | 326 | increment = ((agc_risetime / 2) > agc_droptime); |
324 | 327 | ||
325 | if (agc_baltime < -agc_tbal[agc_mode]) | 328 | if (agc_baltime < -agc_tbal[agc_mode]) |
326 | { | 329 | { |
327 | if (!increment || !agc_gain_is_max(!increment, increment)) { | 330 | if (!increment || !agc_gain_is_max(!increment, increment)) { |
328 | change_recording_gain(increment, !increment, increment); | 331 | change_recording_gain(increment, !increment, increment); |
329 | set_gain(); | 332 | set_gain(); |
333 | } | ||
334 | agc_baltime = 0; | ||
335 | } | ||
336 | else if (agc_baltime > +agc_tbal[agc_mode]) | ||
337 | { | ||
338 | if (!increment || !agc_gain_is_max(increment, !increment)) { | ||
339 | change_recording_gain(increment, increment, !increment); | ||
340 | set_gain(); | ||
341 | } | ||
342 | agc_baltime = 0; | ||
330 | } | 343 | } |
331 | agc_baltime = 0; | ||
332 | } | 344 | } |
333 | else if (agc_baltime > +agc_tbal[agc_mode]) | 345 | else if (!(hist_time % 4)) |
334 | { | 346 | { |
335 | if (!increment || !agc_gain_is_max(increment, !increment)) { | 347 | if (agc_baltime < 0) |
336 | change_recording_gain(increment, increment, !increment); | 348 | agc_baltime++; |
337 | set_gain(); | 349 | else |
338 | } | 350 | agc_baltime--; |
339 | agc_baltime = 0; | ||
340 | } | 351 | } |
341 | } | 352 | } |
342 | else if (!(hist_time % 4)) | 353 | |
343 | { | ||
344 | if (agc_baltime < 0) | ||
345 | agc_baltime++; | ||
346 | else | ||
347 | agc_baltime--; | ||
348 | } | ||
349 | |||
350 | /* Automatic gain control */ | 354 | /* Automatic gain control */ |
351 | if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode])) | 355 | if ((agc_left > agc_th_hi[agc_mode]) || (agc_right > agc_th_hi[agc_mode])) |
352 | { | 356 | { |
@@ -389,7 +393,8 @@ void auto_gain_control(int *peak_l, int *peak_r, int *balance) | |||
389 | agc_risetime++; | 393 | agc_risetime++; |
390 | 394 | ||
391 | if (agc_risetime >= agc_trise[agc_mode]) { | 395 | if (agc_risetime >= agc_trise[agc_mode]) { |
392 | if (!agc_gain_is_max(true, true)) { | 396 | if ((agc_mode != AGC_SAFETY_MODE) && |
397 | (!agc_gain_is_max(true, true))) { | ||
393 | change_recording_gain(true, true, true); | 398 | change_recording_gain(true, true, true); |
394 | set_gain(); | 399 | set_gain(); |
395 | } | 400 | } |