Forums > MaxMSP

Auto Gain Control

December 1, 2006 | 1:23 am

Hi there,

I’m looking for a real simple solution here, something like the crappy auto-gain control you find on a minidisc player.

I just want max/msp to regulate my mic gain automatically. If there is a quiet input, the patch would boost the levels considerably so you could really hear it, and if a lot was going on and things get loud it would adjust the levels to avoid clipping. Anyone know a good way to do this?

Thanks,

Kevin


December 1, 2006 | 2:35 am

http://web.media.mit.edu/~tristan/maxmsp.html

look at her loudness~ object. That should help

Jhaysonn

On 11/30/06, kevin wrote:
>
>
> Hi there,
>
> I’m looking for a real simple solution here, something like the crappy
> auto-gain control you find on a minidisc player.
>
> I just want max/msp to regulate my mic gain automatically. If there is a
> quiet input, the patch would boost the levels considerably so you could
> really hear it, and if a lot was going on and things get loud it would
> adjust the levels to avoid clipping. Anyone know a good way to do this?
>
> Thanks,
>
> Kevin
>


December 1, 2006 | 3:46 am

Thanks Jahysonn… I am looking for something that is UB preferably but this will help. Any other suggestions are still more than welcome.


December 1, 2006 | 4:06 am


December 1, 2011 | 10:04 am

any other options?
loudness~ extrenal mentioned seems to crash max5.1 (win7)



December 1, 2011 | 10:32 pm
C code for ones who unfamiliar with MatLab:

#define TIME         0.9999     // integrator time constant
#define ATTENUATION  0.05       // attenuation after integ.
#define OUTGAIN      1.66       // output gain boost
void normalize(int sample_len, float x[], float y[])
{
  double energy, integr, prev_in, gain;
  int t;

  prev_in = x[i];                  // setup for first time
  for(t = 0; t < sample_len; t++)
  {
    energy = abs( x[t] );          // rectifier
    integr = TIME*prev_in + (1-TIME)*energy;    // integration
    prev_in = integr;              //  y(t-1)
    gain = 1.0 / integr;           // inversion
    gain = gain * ATTENUATION;     // attenuate too big gain
    if(gain > 1.0) gain = 1.0;     // limit below 1.0
    y[t] = gain * x[t];            // vca
    y[t] = OUTGAIN * y[t];         // boost
  }
}
// EOF

March 13, 2014 | 5:25 am

Hi There!

Any joy with this project? have you ever managed to make up a patch for this purpose?
I am trying to run a very similar patch but cannot find a suitable solution.
loudness~ works fine with my max, altho the help guide isn’t very useful.
Any ideas?


April 5, 2014 | 7:40 pm

I’m looking to do the same. Ditto what Quoob says about loudness~. Can’t figure it out. But if I get something working, i think i’ll post it here.


April 6, 2014 | 3:16 am

this thread is strange. There are so many options for compression in max.
look into omx.compresor
or just use abs~+slide~ to get something like the average loudness in order to scale the signal up.
cheers


April 6, 2014 | 3:17 am

also I’m a 100% sure you will find tons of threads about compression btw.


April 6, 2014 | 3:57 am

The problem is it is not about compression we inquiring here but an automatic gain (and equalization – in the more advanced cases) control. something on this line http://alango.com/technologies-avq.php.
Although, as someone has already mentioned in this post, which relates to one of the components of an Automatic volume control http://cycling74.com/forums/topic/noise-cancellation/ it isn’t an easy thing to achieve…

What you are looking for is called Acoustic Echo Cancellation and is a closely guarded dark art practiced by DSP companies and makers of conference phones.

Performance is highly dependent on room reflections, distortion in both speaker and microphone and varying line delay times. It also needs to be adaptive as people – objects – conditions change and move about the room.

This is not for the faint of heart. We spent 18 months developing a usable algorithm that ultimately ran on a SHARC. Many company sell code for this which can be modified. I have never seen a complete Max/MSP implementation, altho I started using MSP for basic experiments before we moved to Matlab and Simulink.

This is why most internet phone systems work best with a headset – to keep the incoming audio from getting to the outgoing audio.

KMc

Cause if you go about compression, the dynamic range will be somehow squashed and restricted, where here what I am looking for it is something that will simply adjust the gain of the main output of the DSP (and at the same time filter out offending frequencies for speech intelligibility – but the equalization part it is slightly too complicated for me just yet).

I came up with a very basic basic patch, which looks at the level of the noise coming from the Mic in the room via a live.gain~ and if the noise it is too loud it will increase the main output.

Although, the limitations are HUGE!

P.s. I’d like to attach my patch to my posts but I cannot figure out how to…please help? :(

  • This reply was modified 4 months by  quoob.

April 6, 2014 | 8:10 am

hi, what you are saying is compression, just with a really large timescale. Or I don’t get it.
Anyway, I didn’t want to sound like your problems are trivial.
post your patch, select everything in your patch, go edit-> copy compressed, and paste it in here


April 6, 2014 | 8:12 am

ok, read more closely now :)
what you mentioned in your last post seems more complicated&sounds a lot like cross-correlation.


Viewing 14 posts - 1 through 14 (of 14 total)