[mythtv] AGC for audio

John Fulton john at geode.homelinux.org
Fri May 16 09:44:17 UTC 2008

Mark Spieth wrote:
>> Hi devs,
>> With a recent upgrade to 0.21 I found that audio channels from my DVB
>> tuners and the DVD were low - in my setup this was obvious with
>> mythmusic starting mp3 playback after exiting a video recording and the
>> speaker cones nearly flying across the room.  I've also noticed that
>> other users complain about varying levels between channels or tuners.
>> I've coded up a simple Auto Gain Control (AGC) based on this post
>> http://www.dsprelated.com/showmessage/21943/1.php .  It's modified to
>> take into account that the gain can go too high during periods of 
>> silence.
>> I placed the call to ManageAGC() in AddAudioData() before any calls to
>> AddSamples() in NuppleVideoPlayer.cpp . It seems to be working well.  In
>> normal operation it has two floating point multiplications and 2
>> add/subtracts per an audio sample.
>> I've coded it against the release-0-21-fixes branch and placed a svn
>> diff patch here if anyone would like to try it out:
>> http://people.connect.net.au/bf/john/agc_svn_diff
> nice and simple. Ive always refrained from agc as it usually adds 
> artifacts.
> however, it could go in audiooutputbase (the correct place for this). 
> with a config item for enabling in DB and mythfrontend setup.
> also gain needs to be scaled with samplerate so that the timeconstant 
> remains "constant" with varying samplerates.
> how well does it work with speech as I can see this amplifying 
> background noise and then making sudden bursts of speech too loud.
> also why did you choose 0.05 as the set point.
> cheers
> mark
I made the gain as small as possible (1e-9) to avoid amplifying noise 
around speech.  It can not be set any smaller unless the floating point 
variables are double.  Having the gain so low means that it will respond 
slowly to overall changes in volume.

As to how well it works for speech: I tested it against the evening news 
(ABC Australia) and the following current affairs program with no 
problems.  For large changes in volume level I tested against a couple 
of David Attenborough wildlife specials - this has quite animals 
together with David's (relatively loud to the animals) voice over.
As for action stuff I've tested it with a DVD of Fantastic 4 and DVB 
broadcast of Pirates of the Caribbean.  I didn't notice any artefacts.

I can see that an analogue tuner combined with large instantaneous noise 
- light switch turning on or lighting - may cause short (30 seconds) of 
low audio volume.

As to the set point.  This was set more with trial and error, The value 
0.05 * NUM_MAX just made the code which cuts in against over-driving the 
output trigger less often.  Values up to 0.2 seem acceptable.


More information about the mythtv-dev mailing list