Automatic Gain Control — github port from sourceforge