Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Radio
- {
- public class AutomaticGainControl : IFilter
- {
- private const double MeanLevel = 0.02;
- private const double MaxFactor = 5000.0;
- private const double MinFactor = 1.0;
- private const double TimeConst = 0.001;
- private readonly Integrator _integrator = new Integrator(TimeConst);
- public double Process(double sample)
- {
- var dc = _integrator.Process(Math.Abs(sample));
- var factor = MeanLevel / dc;
- if (factor > MaxFactor)
- {
- factor = MaxFactor;
- }
- if (factor < MinFactor)
- {
- factor = MinFactor;
- }
- return sample * factor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement