How to use Automatic Gain Control?

This article is a brief introduction about Automatic Gain Control technology in relation with Ozeki VoIP SIP SDK. After reading through this page you will be fully familiar with all the essential terms concerning Automatic Voice Gain and what you will need for creating your own solution using Ozeki VoIP SIP SDK.

What is Automatic Gain Control? How does it work?

Auto Gain Control (AGC) is an adaptive system found in many electronic devices. The average output signal level is fed back to adjust the gain to an appropriate level for a range of input signal levels. For example, without AGC the sound emitted from an AM radio receiver would vary to an extreme extent from a weak to a strong signal; the AGC effectively reduces the volume if the signal is strong and raises it when it is weaker.

Devices to record both sides of a telephone conversation must record both the relatively large signal from the local user and the much smaller signal from the remote user at comparable loudness. Some telephone recording devices incorporate automatic gain control to produce acceptable-quality recordings.

How to implement Automatic Gain Control using C#?

The auto gain control functionality is implemented in the AudioQualityEnhancer class, which is a mediahandler. It uses the AutoGainControl bool property to enable or disable the gain control feature.
To learn more about media handlers, please visit the Managing Media Handler article.

The AudioQualityEnhancer is an audio modifier media handler that needs to be connected to the microphone in order to get all the voice data coming from it. After getting the voice information the AudioQualityEnhancer makes all the noise reduction, echo cancellation and/or gain control that is set to be done and transfers the data to an AudioDataMixerHandler that will produce the actual audio stream that is sent to the other party.

In order to make this whole process work properly, you need to connect the above mentioned media handlers together in the right order.

The automatic gain control is modeled in the AudioQualityEnhancer class by a bool property called AutoGainControl. If this property is set to true, the gain control will affect the communication. If you do not want to use this feature, you just set this property to false.
The automatic gain control function can be customized by two other properties in the AudioQualityEnhancer class. These are the GainSpeed and the MaxGain properties that define the speed of voice gain and the maximal volume value.

Automatic Gain Control example in C#

using System;
using Ozeki.Media;

namespace Automatic_Gain_Control
{
    class Program
    {
        static Microphone microphone;
        static Speaker speaker;
        static MediaConnector connector;
        static AudioQualityEnhancer audioProcessor;

        static void Main(string[] args)
        {
            microphone = Microphone.GetDefaultDevice();
            speaker = Speaker.GetDefaultDevice();
            connector = new MediaConnector();
            audioProcessor = new AudioQualityEnhancer();

            audioProcessor.AutoGainControl = true;
            audioProcessor.GainSpeed = 12;
            audioProcessor.MaxGain = 30;

            connector.Connect(microphone, audioProcessor);
            connector.Connect(audioProcessor, speaker);

            microphone.Start();
            speaker.Start();

            Console.ReadLine();
        }
    }
}

Related Pages

More information