blob: fa6a2621af0c7780b52d0e6f4b29b75f4540f15c [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <math.h>
#include "base/logging.h"
#include "services/media/audio/gain.h"
namespace mojo {
namespace media {
namespace audio {
constexpr unsigned int Gain::FRACTIONAL_BITS;
constexpr Gain::AScale Gain::UNITY;
Gain::Gain()
: amplitude_scale_(UNITY) {
}
void Gain::Set(float db_gain) {
// Compute the amplitude scale factor as a double and sanity check before
// converting to the fixed point representation.
double amp_scale = pow(10.0, db_gain / 20.0);
DCHECK(amp_scale < (1u << ((sizeof(AScale) * 8) - FRACTIONAL_BITS)));
amp_scale *= static_cast<double>(UNITY);
amplitude_scale_.store(static_cast<AScale>(amp_scale));
}
} // namespace audio
} // namespace media
} // namespace mojo