atrac3: Generalize gain compensation code