Fix constness of AudioBuffer accessors.
Don't return non-const pointers from const accessors and deal with the spillover. Provide overloaded versions as needed. Inspired by kwiberg: https://webrtc-codereview.appspot.com/12379005/ R=bjornv@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/15379004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6030 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -69,7 +69,7 @@ int WebRtcVad_set_mode(VadInst* handle, int mode);
|
|||||||
// returns : 1 - (Active Voice),
|
// returns : 1 - (Active Voice),
|
||||||
// 0 - (Non-active Voice),
|
// 0 - (Non-active Voice),
|
||||||
// -1 - (Error)
|
// -1 - (Error)
|
||||||
int WebRtcVad_Process(VadInst* handle, int fs, int16_t* audio_frame,
|
int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
|
||||||
int frame_length);
|
int frame_length);
|
||||||
|
|
||||||
// Checks for valid combinations of |rate| and |frame_length|. We support 10,
|
// Checks for valid combinations of |rate| and |frame_length|. We support 10,
|
||||||
|
@@ -603,7 +603,7 @@ int WebRtcVad_set_mode_core(VadInstT* self, int mode) {
|
|||||||
// Calculate VAD decision by first extracting feature values and then calculate
|
// Calculate VAD decision by first extracting feature values and then calculate
|
||||||
// probability for both speech and background noise.
|
// probability for both speech and background noise.
|
||||||
|
|
||||||
int WebRtcVad_CalcVad48khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length) {
|
int frame_length) {
|
||||||
int vad;
|
int vad;
|
||||||
int i;
|
int i;
|
||||||
@@ -628,7 +628,7 @@ int WebRtcVad_CalcVad48khz(VadInstT* inst, int16_t* speech_frame,
|
|||||||
return vad;
|
return vad;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtcVad_CalcVad32khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length)
|
int frame_length)
|
||||||
{
|
{
|
||||||
int len, vad;
|
int len, vad;
|
||||||
@@ -650,7 +650,7 @@ int WebRtcVad_CalcVad32khz(VadInstT* inst, int16_t* speech_frame,
|
|||||||
return vad;
|
return vad;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtcVad_CalcVad16khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length)
|
int frame_length)
|
||||||
{
|
{
|
||||||
int len, vad;
|
int len, vad;
|
||||||
@@ -666,7 +666,7 @@ int WebRtcVad_CalcVad16khz(VadInstT* inst, int16_t* speech_frame,
|
|||||||
return vad;
|
return vad;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtcVad_CalcVad8khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length)
|
int frame_length)
|
||||||
{
|
{
|
||||||
int16_t feature_vector[kNumChannels], total_power;
|
int16_t feature_vector[kNumChannels], total_power;
|
||||||
|
@@ -103,13 +103,13 @@ int WebRtcVad_set_mode_core(VadInstT* self, int mode);
|
|||||||
* 0 - No active speech
|
* 0 - No active speech
|
||||||
* 1-6 - Active speech
|
* 1-6 - Active speech
|
||||||
*/
|
*/
|
||||||
int WebRtcVad_CalcVad48khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length);
|
int frame_length);
|
||||||
int WebRtcVad_CalcVad32khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length);
|
int frame_length);
|
||||||
int WebRtcVad_CalcVad16khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length);
|
int frame_length);
|
||||||
int WebRtcVad_CalcVad8khz(VadInstT* inst, int16_t* speech_frame,
|
int WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,
|
||||||
int frame_length);
|
int frame_length);
|
||||||
|
|
||||||
#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_CORE_H_
|
#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_CORE_H_
|
||||||
|
@@ -24,7 +24,7 @@ static const int16_t kSmoothingUp = 32439; // 0.99 in Q15.
|
|||||||
|
|
||||||
// TODO(bjornv): Move this function to vad_filterbank.c.
|
// TODO(bjornv): Move this function to vad_filterbank.c.
|
||||||
// Downsampling filter based on splitting filter and allpass functions.
|
// Downsampling filter based on splitting filter and allpass functions.
|
||||||
void WebRtcVad_Downsampling(int16_t* signal_in,
|
void WebRtcVad_Downsampling(const int16_t* signal_in,
|
||||||
int16_t* signal_out,
|
int16_t* signal_out,
|
||||||
int32_t* filter_state,
|
int32_t* filter_state,
|
||||||
int in_length) {
|
int in_length) {
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
//
|
//
|
||||||
// Output:
|
// Output:
|
||||||
// - signal_out : Downsampled signal (of length |in_length| / 2).
|
// - signal_out : Downsampled signal (of length |in_length| / 2).
|
||||||
void WebRtcVad_Downsampling(int16_t* signal_in,
|
void WebRtcVad_Downsampling(const int16_t* signal_in,
|
||||||
int16_t* signal_out,
|
int16_t* signal_out,
|
||||||
int32_t* filter_state,
|
int32_t* filter_state,
|
||||||
int in_length);
|
int in_length);
|
||||||
|
@@ -68,7 +68,7 @@ int WebRtcVad_set_mode(VadInst* handle, int mode) {
|
|||||||
return WebRtcVad_set_mode_core(self, mode);
|
return WebRtcVad_set_mode_core(self, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtcVad_Process(VadInst* handle, int fs, int16_t* audio_frame,
|
int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
|
||||||
int frame_length) {
|
int frame_length) {
|
||||||
int vad = -1;
|
int vad = -1;
|
||||||
VadInstT* self = (VadInstT*) handle;
|
VadInstT* self = (VadInstT*) handle;
|
||||||
|
@@ -228,7 +228,7 @@ void AudioBuffer::InitForNewData() {
|
|||||||
is_muted_ = false;
|
is_muted_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* AudioBuffer::data(int channel) const {
|
const int16_t* AudioBuffer::data(int channel) const {
|
||||||
assert(channel >= 0 && channel < num_proc_channels_);
|
assert(channel >= 0 && channel < num_proc_channels_);
|
||||||
if (data_ != NULL) {
|
if (data_ != NULL) {
|
||||||
return data_;
|
return data_;
|
||||||
@@ -237,7 +237,12 @@ int16_t* AudioBuffer::data(int channel) const {
|
|||||||
return channels_->channel(channel);
|
return channels_->channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* AudioBuffer::low_pass_split_data(int channel) const {
|
int16_t* AudioBuffer::data(int channel) {
|
||||||
|
const AudioBuffer* t = this;
|
||||||
|
return const_cast<int16_t*>(t->data(channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
const int16_t* AudioBuffer::low_pass_split_data(int channel) const {
|
||||||
assert(channel >= 0 && channel < num_proc_channels_);
|
assert(channel >= 0 && channel < num_proc_channels_);
|
||||||
if (split_channels_.get() == NULL) {
|
if (split_channels_.get() == NULL) {
|
||||||
return data(channel);
|
return data(channel);
|
||||||
@@ -246,7 +251,12 @@ int16_t* AudioBuffer::low_pass_split_data(int channel) const {
|
|||||||
return split_channels_->low_channel(channel);
|
return split_channels_->low_channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* AudioBuffer::high_pass_split_data(int channel) const {
|
int16_t* AudioBuffer::low_pass_split_data(int channel) {
|
||||||
|
const AudioBuffer* t = this;
|
||||||
|
return const_cast<int16_t*>(t->low_pass_split_data(channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
const int16_t* AudioBuffer::high_pass_split_data(int channel) const {
|
||||||
assert(channel >= 0 && channel < num_proc_channels_);
|
assert(channel >= 0 && channel < num_proc_channels_);
|
||||||
if (split_channels_.get() == NULL) {
|
if (split_channels_.get() == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -255,19 +265,24 @@ int16_t* AudioBuffer::high_pass_split_data(int channel) const {
|
|||||||
return split_channels_->high_channel(channel);
|
return split_channels_->high_channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* AudioBuffer::mixed_data(int channel) const {
|
int16_t* AudioBuffer::high_pass_split_data(int channel) {
|
||||||
|
const AudioBuffer* t = this;
|
||||||
|
return const_cast<int16_t*>(t->high_pass_split_data(channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
const int16_t* AudioBuffer::mixed_data(int channel) const {
|
||||||
assert(channel >= 0 && channel < num_mixed_channels_);
|
assert(channel >= 0 && channel < num_mixed_channels_);
|
||||||
|
|
||||||
return mixed_channels_->channel(channel);
|
return mixed_channels_->channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* AudioBuffer::mixed_low_pass_data(int channel) const {
|
const int16_t* AudioBuffer::mixed_low_pass_data(int channel) const {
|
||||||
assert(channel >= 0 && channel < num_mixed_low_pass_channels_);
|
assert(channel >= 0 && channel < num_mixed_low_pass_channels_);
|
||||||
|
|
||||||
return mixed_low_pass_channels_->channel(channel);
|
return mixed_low_pass_channels_->channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* AudioBuffer::low_pass_reference(int channel) const {
|
const int16_t* AudioBuffer::low_pass_reference(int channel) const {
|
||||||
assert(channel >= 0 && channel < num_proc_channels_);
|
assert(channel >= 0 && channel < num_proc_channels_);
|
||||||
if (!reference_copied_) {
|
if (!reference_copied_) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -280,7 +295,7 @@ const float* AudioBuffer::keyboard_data() const {
|
|||||||
return keyboard_data_;
|
return keyboard_data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
SplitFilterStates* AudioBuffer::filter_states(int channel) const {
|
SplitFilterStates* AudioBuffer::filter_states(int channel) {
|
||||||
assert(channel >= 0 && channel < num_proc_channels_);
|
assert(channel >= 0 && channel < num_proc_channels_);
|
||||||
return &filter_states_[channel];
|
return &filter_states_[channel];
|
||||||
}
|
}
|
||||||
|
@@ -55,15 +55,18 @@ class AudioBuffer {
|
|||||||
int samples_per_split_channel() const;
|
int samples_per_split_channel() const;
|
||||||
int samples_per_keyboard_channel() const;
|
int samples_per_keyboard_channel() const;
|
||||||
|
|
||||||
int16_t* data(int channel) const;
|
int16_t* data(int channel);
|
||||||
int16_t* low_pass_split_data(int channel) const;
|
const int16_t* data(int channel) const;
|
||||||
int16_t* high_pass_split_data(int channel) const;
|
int16_t* low_pass_split_data(int channel);
|
||||||
int16_t* mixed_data(int channel) const;
|
const int16_t* low_pass_split_data(int channel) const;
|
||||||
int16_t* mixed_low_pass_data(int channel) const;
|
int16_t* high_pass_split_data(int channel);
|
||||||
int16_t* low_pass_reference(int channel) const;
|
const int16_t* high_pass_split_data(int channel) const;
|
||||||
|
const int16_t* mixed_data(int channel) const;
|
||||||
|
const int16_t* mixed_low_pass_data(int channel) const;
|
||||||
|
const int16_t* low_pass_reference(int channel) const;
|
||||||
const float* keyboard_data() const;
|
const float* keyboard_data() const;
|
||||||
|
|
||||||
SplitFilterStates* filter_states(int channel) const;
|
SplitFilterStates* filter_states(int channel);
|
||||||
|
|
||||||
void set_activity(AudioFrame::VADActivity activity);
|
void set_activity(AudioFrame::VADActivity activity);
|
||||||
AudioFrame::VADActivity activity() const;
|
AudioFrame::VADActivity activity() const;
|
||||||
|
@@ -128,7 +128,7 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
|||||||
for (int i = 0; i < audio->num_channels(); i++) {
|
for (int i = 0; i < audio->num_channels(); i++) {
|
||||||
// TODO(ajm): improve how this works, possibly inside AECM.
|
// TODO(ajm): improve how this works, possibly inside AECM.
|
||||||
// This is kind of hacked up.
|
// This is kind of hacked up.
|
||||||
int16_t* noisy = audio->low_pass_reference(i);
|
const int16_t* noisy = audio->low_pass_reference(i);
|
||||||
int16_t* clean = audio->low_pass_split_data(i);
|
int16_t* clean = audio->low_pass_split_data(i);
|
||||||
if (noisy == NULL) {
|
if (noisy == NULL) {
|
||||||
noisy = clean;
|
noisy = clean;
|
||||||
|
@@ -59,7 +59,7 @@ int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) {
|
|||||||
|
|
||||||
assert(audio->samples_per_split_channel() <= 160);
|
assert(audio->samples_per_split_channel() <= 160);
|
||||||
|
|
||||||
int16_t* mixed_data = audio->low_pass_split_data(0);
|
const int16_t* mixed_data = audio->low_pass_split_data(0);
|
||||||
if (audio->num_channels() > 1) {
|
if (audio->num_channels() > 1) {
|
||||||
audio->CopyAndMixLowPass(1);
|
audio->CopyAndMixLowPass(1);
|
||||||
mixed_data = audio->mixed_low_pass_data(0);
|
mixed_data = audio->mixed_low_pass_data(0);
|
||||||
|
@@ -20,7 +20,15 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const double kMaxSquaredLevel = 32768.0 * 32768.0;
|
const float kMaxSquaredLevel = 32768.0 * 32768.0;
|
||||||
|
|
||||||
|
float SumSquare(const int16_t* data, int length) {
|
||||||
|
float sum_square = 0.f;
|
||||||
|
for (int i = 0; i < length; ++i) {
|
||||||
|
sum_square += data[i] * data[i];
|
||||||
|
}
|
||||||
|
return sum_square;
|
||||||
|
}
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
@@ -36,7 +44,7 @@ class Level {
|
|||||||
sample_count_ = 0;
|
sample_count_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process(int16_t* data, int length) {
|
void Process(const int16_t* data, int length) {
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
assert(length > 0);
|
assert(length > 0);
|
||||||
sum_square_ += SumSquare(data, length);
|
sum_square_ += SumSquare(data, length);
|
||||||
@@ -55,7 +63,7 @@ class Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normalize by the max level.
|
// Normalize by the max level.
|
||||||
double rms = sum_square_ / (sample_count_ * kMaxSquaredLevel);
|
float rms = sum_square_ / (sample_count_ * kMaxSquaredLevel);
|
||||||
// 20log_10(x^0.5) = 10log_10(x)
|
// 20log_10(x^0.5) = 10log_10(x)
|
||||||
rms = 10 * log10(rms);
|
rms = 10 * log10(rms);
|
||||||
if (rms > 0)
|
if (rms > 0)
|
||||||
@@ -69,18 +77,10 @@ class Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static double SumSquare(int16_t* data, int length) {
|
float sum_square_;
|
||||||
double sum_square = 0.0;
|
|
||||||
for (int i = 0; i < length; ++i) {
|
|
||||||
double data_d = static_cast<double>(data[i]);
|
|
||||||
sum_square += data_d * data_d;
|
|
||||||
}
|
|
||||||
return sum_square;
|
|
||||||
}
|
|
||||||
|
|
||||||
double sum_square_;
|
|
||||||
int sample_count_;
|
int sample_count_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm,
|
LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm,
|
||||||
@@ -102,7 +102,7 @@ int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) {
|
|||||||
return apm_->kNoError;
|
return apm_->kNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* mixed_data = audio->data(0);
|
const int16_t* mixed_data = audio->data(0);
|
||||||
if (audio->num_channels() > 1) {
|
if (audio->num_channels() > 1) {
|
||||||
audio->CopyAndMix(1);
|
audio->CopyAndMix(1);
|
||||||
mixed_data = audio->mixed_data(0);
|
mixed_data = audio->mixed_data(0);
|
||||||
|
@@ -61,7 +61,7 @@ int VoiceDetectionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
|||||||
}
|
}
|
||||||
assert(audio->samples_per_split_channel() <= 160);
|
assert(audio->samples_per_split_channel() <= 160);
|
||||||
|
|
||||||
int16_t* mixed_data = audio->low_pass_split_data(0);
|
const int16_t* mixed_data = audio->low_pass_split_data(0);
|
||||||
if (audio->num_channels() > 1) {
|
if (audio->num_channels() > 1) {
|
||||||
audio->CopyAndMixLowPass(1);
|
audio->CopyAndMixLowPass(1);
|
||||||
mixed_data = audio->mixed_low_pass_data(0);
|
mixed_data = audio->mixed_low_pass_data(0);
|
||||||
|
Reference in New Issue
Block a user