Files
platform-external-webrtc/webrtc/modules/audio_coding/neteq/background_noise.h
henrik.lundin@webrtc.org ea25784107 Change how background noise mode in NetEq is set
This change prepares for switching default background noise (bgn) mode
from on to off. The actual switch will be done later.

In this change, the bgn mode is included as a setting in NetEq's config
struct. We're also removing the connection between playout modes and
bgn modes in ACM. In practice this means that bgn mode will change from
off to on for streaming mode, but since the playout modes are not used
it does not matter.

BUG=3519
R=tina.legrand@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/21749004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-08-07 12:27:37 +00:00

138 lines
4.4 KiB
C++

/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_BACKGROUND_NOISE_H_
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_BACKGROUND_NOISE_H_
#include <string.h> // size_t
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h"
#include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#include "webrtc/typedefs.h"
namespace webrtc {
// Forward declarations.
class PostDecodeVad;
// This class handles estimation of background noise parameters.
class BackgroundNoise {
public:
// TODO(hlundin): For 48 kHz support, increase kMaxLpcOrder to 10.
// Will work anyway, but probably sound a little worse.
static const int kMaxLpcOrder = 8; // 32000 / 8000 + 4.
explicit BackgroundNoise(size_t num_channels);
virtual ~BackgroundNoise();
void Reset();
// Updates the parameter estimates based on the signal currently in the
// |sync_buffer|, and on the latest decision in |vad| if it is running.
void Update(const AudioMultiVector& sync_buffer,
const PostDecodeVad& vad);
// Returns |energy_| for |channel|.
int32_t Energy(size_t channel) const;
// Sets the value of |mute_factor_| for |channel| to |value|.
void SetMuteFactor(size_t channel, int16_t value);
// Returns |mute_factor_| for |channel|.
int16_t MuteFactor(size_t channel) const;
// Returns a pointer to |filter_| for |channel|.
const int16_t* Filter(size_t channel) const;
// Returns a pointer to |filter_state_| for |channel|.
const int16_t* FilterState(size_t channel) const;
// Copies |length| elements from |input| to the filter state. Will not copy
// more than |kMaxLpcOrder| elements.
void SetFilterState(size_t channel, const int16_t* input, size_t length);
// Returns |scale_| for |channel|.
int16_t Scale(size_t channel) const;
// Returns |scale_shift_| for |channel|.
int16_t ScaleShift(size_t channel) const;
// Accessors.
bool initialized() const { return initialized_; }
NetEq::BackgroundNoiseMode mode() const { return mode_; }
// Sets the mode of the background noise playout for cases when there is long
// duration of packet loss.
void set_mode(NetEq::BackgroundNoiseMode mode) { mode_ = mode; }
private:
static const int kThresholdIncrement = 229; // 0.0035 in Q16.
static const int kVecLen = 256;
static const int kLogVecLen = 8; // log2(kVecLen).
static const int kResidualLength = 64;
static const int kLogResidualLength = 6; // log2(kResidualLength)
struct ChannelParameters {
// Constructor.
ChannelParameters() {
Reset();
}
void Reset() {
energy = 2500;
max_energy = 0;
energy_update_threshold = 500000;
low_energy_update_threshold = 0;
memset(filter_state, 0, sizeof(filter_state));
memset(filter, 0, sizeof(filter));
filter[0] = 4096;
mute_factor = 0,
scale = 20000;
scale_shift = 24;
}
int32_t energy;
int32_t max_energy;
int32_t energy_update_threshold;
int32_t low_energy_update_threshold;
int16_t filter_state[kMaxLpcOrder];
int16_t filter[kMaxLpcOrder + 1];
int16_t mute_factor;
int16_t scale;
int16_t scale_shift;
};
int32_t CalculateAutoCorrelation(const int16_t* signal,
int length,
int32_t* auto_correlation) const;
// Increments the energy threshold by a factor 1 + |kThresholdIncrement|.
void IncrementEnergyThreshold(size_t channel, int32_t sample_energy);
// Updates the filter parameters.
void SaveParameters(size_t channel,
const int16_t* lpc_coefficients,
const int16_t* filter_state,
int32_t sample_energy,
int32_t residual_energy);
size_t num_channels_;
scoped_ptr<ChannelParameters[]> channel_parameters_;
bool initialized_;
NetEq::BackgroundNoiseMode mode_;
DISALLOW_COPY_AND_ASSIGN(BackgroundNoise);
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_BACKGROUND_NOISE_H_