Notice: A non well formed numeric value encountered in /sites/ on line 96 Notice: A non well formed numeric value encountered in /sites/ on line 96 Notice: A non well formed numeric value encountered in /sites/ on line 96 Deprecated: Function create_function() is deprecated in /sites/ on line 104 Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /sites/ on line 845 Deprecated: Function create_function() is deprecated in /sites/ on line 111 FS#4748 : Automatic Recording Gain Control



FS#4748 - Automatic Recording Gain Control

Attached to Project: Rockbox
Opened by Jvo Studer (vinylivo) - Tuesday, 28 February 2006, 14:09 GMT
Last edited by Peter D'Hoye (petur) - Monday, 03 April 2006, 10:01 GMT
Task Type Patches
Category Recording
Status Closed
Assigned To No-one
Operating System Iriver H100 series
Severity Low
Priority Normal
Reported Version
Due in Version Version 3.1
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This patch adds automatic gain control (AGC) for recording.
At the moment it works with Mmmm's recording enhancements pack but I included a patch with the agc and the recenhancementpack included.
- 6 selectable AGC presets: Off, Safety (clip prevention), Live (slow), DJ-Set (slow), Medium and Voice (fast).
- Controls also out of balance and tries to center the levels.
The nominal target levels for the presets are: Live -9dB, DJ-Set -5dB, Medium -6dB, Voice -7dB.
- Peak level histogram view in 4 modes: high resolution linear or logarithmic histogram, low height linear or logarithmic histogram plus balance meter, disk usage and batter level display.
- Shows correct recording status in statusbar.
- Issues a warning splash when disk space or battery level gets low.
- Stops recording when disk is full (leaving a small 128MB remaining space that the jukebox can continue to work).
- Stops recording when battery level is critical for hdd writing to prevent corrupted (or with 0 bytes because FAT entry couldn't be written anymore) files.

This is a preliminary release, AGC-Mode is not yet saved in user settings and localization (language) is not yet done.

All presets reduce the level by detection of clipping more than a second. The internal timing is 0.5s for now, perhaps I'll increase it to 0.2s later. 'fast' here means an attack time of 2 seconds and a release time of 4 seconds, so this is not a realtime compressor but really a relatively slow gain control system. And the gain control works by increasing/decreasing the input gain in 0.5dB steps. The user can change the gain manually anytime and therefore override the AGC. If AGC-Mode is not set to Off or Safety it will take over control again and head up for the preset target volume.

Technical details:
Algorithm timing: 0.5 sec
Thresholds (upper/lower) [dB]: Live -7/-11, DJ-Set -4/-6, Medium -5/-7, Voice -5/-8
Timing (attack/release/balance) [s]: Live 40/150/60, DJ-Set 24/64/40, Medium 12/32/20, Voice 1.5/4/3
This task depends upon

Closed by  Peter D'Hoye (petur)
Thursday, 17 August 2006, 11:25 GMT
Reason for closing:  Accepted
Additional comments about closing:  the rest of the REP should be committed separately or resubmitted to the tracker
Comment by Jvo Studer (vinylivo) - Tuesday, 28 February 2006, 14:13 GMT
Forgot to mention that the first patch (rec_agc_histogram) is for people who already installed Mmmm's recording enhancement pack.
The second includes the enhancement pack and AGC.
Comment by Paul van der Heu (paulheu) - Sunday, 05 March 2006, 17:21 GMT
The 'graphics' for HD space and battery life do not take different fontsizes into account..
Comment by Jvo Studer (vinylivo) - Monday, 06 March 2006, 04:06 GMT
So here's the updated patch for AGC.
New features:
- settings are saved.
- localization (english & german)
- limiter versions of presets. allows to set a maximum gain which isn't succeeded. press left when AGC presets highlighted to select limiter presets. timing is the same as 'normal' presets. press down when AGC presets highlighted and a limiter preset is selected to change maximum gain.
- improved precision of peak meter (much lower error in important -12dB to 0dB range, error < 0.2dB).

This patch includes Mmmm's remote support and high size peak meter.
Comment by sebastien (sebienbon) - Sunday, 12 March 2006, 18:17 GMT
I have no idea how to apply that to my rockbox.....I m very interested since i m a musician and record a lot with my Iriver h320 in live sittuations...Anybody could tip me? thanks a lot and thanks for people developing this great thing!
Comment by Jvo Studer (vinylivo) - Wednesday, 15 March 2006, 18:19 GMT
A quick update against daily build 060313:

- now with user font in recording screen if it fits. remote and main can have different fonts and peak-meter sizes depending on space.
- removed the 'limiter' presets and made 'max. AGC gain' enabled always.
- slight rearrangment of battery, disk and balance-meter. also enabled these infos for the higher sized histogram views if there is enough space on the screen.
- seperate saved preset & max. agc gain settings for mic and line-in.
- includes remote support (from Mmmm's patch)
- includes improved power managment (as I was unable to remove it right now, just too busy).
- use patch -p1 to apply to source.

@sebastien: This is for developers only at the moment (you need the development tools installed and compile the source yourself). I'll compile a recent binary for H120 and H320 when I find some time.
Comment by Nicolas Pennequin (nicolas_p) - Thursday, 16 March 2006, 16:59 GMT
I isolated the recording enhancements part of the patch, and i also made a version which will apply cleanly against paprica's scroll margins patch (which can be found here : ), as they conflict but they are both very nice ;)

Use -p0 to apply
Comment by pilot000 (pilot000) - Sunday, 19 March 2006, 10:44 GMT
there is a missing part in nicolas_p patch (english.lang)

desc: in recording screen
eng: "Battery is low!"
Comment by Paul van der Heu (paulheu) - Saturday, 25 March 2006, 14:51 GMT
With the remote support and peakmeter patch added to CVS I guess we need a new patch for 'just' the AGC part..
Comment by Peter D'Hoye (petur) - Wednesday, 29 March 2006, 19:25 GMT
Could you *please* split usefull patches (like this) into one functionality per patch?
I would love to test and commit the AGC and other stuff, but I can't do it all in one...
Comment by Jvo Studer (vinylivo) - Monday, 03 April 2006, 09:42 GMT
OK here it comes. This is only the AGC, the histogram follows in a seperate patch. Since remote support and peakmeter patch got added to CVS there are only a few files left to modify, namely german & englisch language, settings, sound_menu, status (for showing the 'REC? symbol in statusbar) and recording.
Comment by Peter D'Hoye (petur) - Monday, 03 April 2006, 10:00 GMT
Great... but it seems you just missed the 'feature freeze' deadline, so I won't be able to commit it for another 4 weeks. After the 3.0 release, it 'll be one of the first things to go in :)
Comment by Jvo Studer (vinylivo) - Tuesday, 04 April 2006, 10:58 GMT
Yeah that's sad I know, but it was impossible to do it before.

I splitted agc and batt/disk warnings too, so here are the seperate patches. I still try to update the patch every two weeks or so that they remain updated for easier patching lateron.
Comment by Peter D'Hoye (petur) - Sunday, 09 April 2006, 11:38 GMT
Tried your AGC patch and it sure has potential - I only used the safety setting and it worked nicely. The settings will need a fair bit of documentation, maybe change it to a fully parametric control (in true rockbox style) next to the wizard-like presets.

As the lang file changed, it didn't apply cleanly anymore, so I fixed it for you (AGC patch only)
Comment by Jvo Studer (vinylivo) - Sunday, 09 April 2006, 18:10 GMT
Thanks Peter, I thought about more control for presets too, perhaps some user presets which can be configured like the EQs. There are quite some control parameters that's why I thought it would be easier just to give presets. But we can make something that lets the user choose target level, control hysteresis, attack and release timing as the most important ones. Perhaps via context menu?
I'll dive into this...

This is the official patch for the new language format. I moved all graphic changes (like status bar REC symbol etc) to the seperate histogram patch.

And I added a patch which includes AGC and Histogram display because it's not so easy to apply both patches to the source (conflicts because several functions and other stuff are used by both). So use the 'rec_agc_hist_pack' for this.

Patches were done against daily-060408 and use -p1 for patching
Comment by Paul van der Heu (paulheu) - Sunday, 09 April 2006, 20:37 GMT
The color (part of the) patch turns the textcolor to black .. not very nice if you have a black background :^)
Comment by Peter D'Hoye (petur) - Sunday, 09 April 2006, 20:55 GMT
Paul, you must surely be talking about the agc+histogram patch, as the agc-only patch does no such thing here...
Comment by Paul van der Heu (paulheu) - Sunday, 09 April 2006, 21:33 GMT
hmm I guess yes :)
Comment by Paul van der Heu (paulheu) - Sunday, 09 April 2006, 21:56 GMT
Fixed it..
Comment by Paul van der Heu (paulheu) - Sunday, 09 April 2006, 22:13 GMT
Replace lcd_set_foreground(LCD_DEFAULT_FG) with lcd_set_foreground(global_settings.fg_color) works for me
Comment by Paul van der Heu (paulheu) - Friday, 21 April 2006, 00:19 GMT
it appears the patch does not setup LCD width correctly(on my H3x0 at least, the left side (as far as I can see the outline only) of the balance meter is missing and the outline of the histogram is not shown either..
Comment by Paul van der Heu (paulheu) - Sunday, 30 April 2006, 20:05 GMT
Another thing I noticed is that the box around the histogram and the 'needle' in the balancementer is always drawn in black. This makes it hard to see when using a black background..;^)
Comment by Peter D'Hoye (petur) - Friday, 12 May 2006, 23:59 GMT
updated agc patch for current cvs
   agc (36.2 KiB)
Comment by Davide (Davide-NYC) - Sunday, 14 May 2006, 03:33 GMT
Hello Petur, Paul, and Jvo.
I think that there's a small bug in this lastest AGC patch.
When AGC is set to be in a "non-off" state it seems to only be available if your source is set to "mic".
Wouldn't AGC be useful during line-in recording as well?
I understand that it makes no sense to have AGC on when recording from digital, but automatic line-in attenuation would be a good feature too, no?
If you didn't want it during line-in you could always set the AGC to "off".
Comment by Peter D'Hoye (petur) - Monday, 15 May 2006, 22:06 GMT
Davide, I think the problem was that the newly added frequency line didn't compensate for line-in having L/R gain ( <-> mic only one line). I have fixed this and had quite some work getting the patch compatible with latest CVS.

Please test ;)
   agc (33.6 KiB)
Comment by Peter D'Hoye (petur) - Wednesday, 17 May 2006, 22:17 GMT
Updated to latest CVS and fixed build issue for sim builds
   agc (33.7 KiB)
Comment by Peter D'Hoye (petur) - Friday, 26 May 2006, 22:15 GMT
Updated to latest CVS
   agc (33.6 KiB)
Comment by Peter D'Hoye (petur) - Monday, 03 July 2006, 20:08 GMT
Updated to latest CVS
Comment by Peter D'Hoye (petur) - Tuesday, 01 August 2006, 06:22 GMT
Updated to latest CVS
(but in a hurry, so please check)
Comment by Davide (Davide-NYC) - Wednesday, 02 August 2006, 03:18 GMT
Regretfully, it breaks when attempting to use it on Line-In.
Seems to work for Mic in. This was the case in an earlier build.
Sorry Petur, it's broken. :-(
Comment by Peter D'Hoye (petur) - Wednesday, 02 August 2006, 06:03 GMT
How does it break?

It's a diff from a version I run here, and I admit I only tested Line-In. But that worked.
Will check tonight...
Comment by Davide (Davide-NYC) - Wednesday, 02 August 2006, 13:53 GMT
Using Mic input I monitor and record BOTH channels! This is actually great, a dual mono track is better than left channel only (as it was), but I don't know whether this new behavior is caused specifically by AGC or not. AGC seems to work fine with the new dual mono mic recording.

Using Line input I can monitor and record both channels, but there is no AGC display and when I set the gain high and clip the input none of the levels change even when AGC is set to Safety in the menu.

I am currently 'make'ing a clean build from yesterday's source (20060801) and will report back on the 'dual mono' mic input recording status.
Comment by Davide (Davide-NYC) - Wednesday, 02 August 2006, 13:59 GMT
CONFIRMED: Dual Mono Recording for Mic Input committed to CVS. Whoever commited this change THANK YOU!
AGC bug still pending, de-activated during Line-Input recording regardless of menu setting. No AGC status disply in WRS when Source=Line-In (someone please corroberate)
PS: thanks for all of the Devs on this project. LLRB (long live Rockbox)
Comment by Peter D'Hoye (petur) - Wednesday, 02 August 2006, 17:36 GMT
Ouch.. must have overlooked that... will fix
Comment by Peter D'Hoye (petur) - Wednesday, 02 August 2006, 21:34 GMT
This one should be better. Don't know about the remote and certainly not what the code will do now for non AGC targets.

The recording screen code is in need of some serious clean-up. I'm trying to have a look at it. *seeks time*
Comment by Peter D'Hoye (petur) - Thursday, 03 August 2006, 21:31 GMT
Some small updates:
- moved HAVE_AGC to the config_xxx.h files for smoother multi-target implementation
- small fix in recording screen
Comment by Martin Scarratt (mmmm-) - Sunday, 06 August 2006, 15:31 GMT
Petur... Here's a patch based on the one above 3/08

I've added display support for digital in for players that support it (although AGC obviously does nothing for digital so on second thoughts maybe we shouldn't display at all in that mode...hmmmm).

Also I've fixed the remote display (and any other screens that are too small to fit all this info on).
(application/octet-stream)    AGC.patch (31.3 KiB)
Comment by Martin Scarratt (mmmm-) - Sunday, 06 August 2006, 21:48 GMT
Here's a better one. Now the AGC settings don't appear for digital in (as they don't do anything anyway) and the cursor handling is better...

Small screens that can't fit in the AGC info/settings now have the bottom line change into the settings line when the cursor is moved down.
Comment by Peter D'Hoye (petur) - Tuesday, 08 August 2006, 17:26 GMT
my version of the agc patch in sync with cvs. Does not contain recent changes by Mmmm yet. Posted here on request ;)
Comment by Peter D'Hoye (petur) - Tuesday, 08 August 2006, 23:20 GMT
Better version:
- Synced with CVS (again)
- Should incorporate Mmmm's changes
- Removed 2 constants
- Prepared for other targets

Do test...
Comment by Davide (Davide-NYC) - Wednesday, 09 August 2006, 00:50 GMT
DLed clean CVS and patched with agc_20060809.patch.
Built SIM: no errors, build NORMAL: no errors.
Installed on H140, tested mic in and line-in.
Digital in shows no AGC.
Tested with the 300LCD-Joystick remote. (buttons are mis-mapped but are all there)
IMO: Looks good! Woohoo!
Comment by Peter D'Hoye (petur) - Tuesday, 15 August 2006, 23:08 GMT
sync to cvs
Comment by Peter D'Hoye (petur) - Wednesday, 16 August 2006, 23:27 GMT
AGC part has been committed ;)