| Index: webrtc/modules/audio_coding/neteq/merge.cc
|
| diff --git a/webrtc/modules/audio_coding/neteq/merge.cc b/webrtc/modules/audio_coding/neteq/merge.cc
|
| index 2c515c14eb3ae21be86ba519c14fefeda0df07e3..b6fb2d8a26768ae13693a48428fe37ef6f3b6a4e 100644
|
| --- a/webrtc/modules/audio_coding/neteq/merge.cc
|
| +++ b/webrtc/modules/audio_coding/neteq/merge.cc
|
| @@ -31,25 +31,25 @@ Merge::Merge(int fs_hz,
|
| : fs_hz_(fs_hz),
|
| num_channels_(num_channels),
|
| fs_mult_(fs_hz_ / 8000),
|
| - timestamps_per_call_(fs_hz_ / 100),
|
| + timestamps_per_call_(static_cast<size_t>(fs_hz_ / 100)),
|
| expand_(expand),
|
| sync_buffer_(sync_buffer),
|
| expanded_(num_channels_) {
|
| assert(num_channels_ > 0);
|
| }
|
|
|
| -int Merge::Process(int16_t* input, size_t input_length,
|
| - int16_t* external_mute_factor_array,
|
| - AudioMultiVector* output) {
|
| +size_t Merge::Process(int16_t* input, size_t input_length,
|
| + int16_t* external_mute_factor_array,
|
| + AudioMultiVector* output) {
|
| // TODO(hlundin): Change to an enumerator and skip assert.
|
| assert(fs_hz_ == 8000 || fs_hz_ == 16000 || fs_hz_ == 32000 ||
|
| fs_hz_ == 48000);
|
| assert(fs_hz_ <= kMaxSampleRate); // Should not be possible.
|
|
|
| - int old_length;
|
| - int expand_period;
|
| + size_t old_length;
|
| + size_t expand_period;
|
| // Get expansion data to overlap and mix with.
|
| - int expanded_length = GetExpandedSignal(&old_length, &expand_period);
|
| + size_t expanded_length = GetExpandedSignal(&old_length, &expand_period);
|
|
|
| // Transfer input signal to an AudioMultiVector.
|
| AudioMultiVector input_vector(num_channels_);
|
| @@ -57,7 +57,7 @@ int Merge::Process(int16_t* input, size_t input_length,
|
| size_t input_length_per_channel = input_vector.Size();
|
| assert(input_length_per_channel == input_length / num_channels_);
|
|
|
| - int16_t best_correlation_index = 0;
|
| + size_t best_correlation_index = 0;
|
| size_t output_length = 0;
|
|
|
| for (size_t channel = 0; channel < num_channels_; ++channel) {
|
| @@ -65,8 +65,8 @@ int Merge::Process(int16_t* input, size_t input_length,
|
| int16_t* expanded_channel = &expanded_[channel][0];
|
| int16_t expanded_max, input_max;
|
| int16_t new_mute_factor = SignalScaling(
|
| - input_channel, static_cast<int>(input_length_per_channel),
|
| - expanded_channel, &expanded_max, &input_max);
|
| + input_channel, input_length_per_channel, expanded_channel,
|
| + &expanded_max, &input_max);
|
|
|
| // Adjust muting factor (product of "main" muting factor and expand muting
|
| // factor).
|
| @@ -84,13 +84,13 @@ int Merge::Process(int16_t* input, size_t input_length,
|
| // Downsample, correlate, and find strongest correlation period for the
|
| // master (i.e., first) channel only.
|
| // Downsample to 4kHz sample rate.
|
| - Downsample(input_channel, static_cast<int>(input_length_per_channel),
|
| - expanded_channel, expanded_length);
|
| + Downsample(input_channel, input_length_per_channel, expanded_channel,
|
| + expanded_length);
|
|
|
| // Calculate the lag of the strongest correlation period.
|
| best_correlation_index = CorrelateAndPeakSearch(
|
| expanded_max, input_max, old_length,
|
| - static_cast<int>(input_length_per_channel), expand_period);
|
| + input_length_per_channel, expand_period);
|
| }
|
|
|
| static const int kTempDataSize = 3600;
|
| @@ -99,11 +99,11 @@ int Merge::Process(int16_t* input, size_t input_length,
|
|
|
| // Mute the new decoded data if needed (and unmute it linearly).
|
| // This is the overlapping part of expanded_signal.
|
| - int interpolation_length = std::min(
|
| + size_t interpolation_length = std::min(
|
| kMaxCorrelationLength * fs_mult_,
|
| expanded_length - best_correlation_index);
|
| interpolation_length = std::min(interpolation_length,
|
| - static_cast<int>(input_length_per_channel));
|
| + input_length_per_channel);
|
| if (*external_mute_factor < 16384) {
|
| // Set a suitable muting slope (Q20). 0.004 for NB, 0.002 for WB,
|
| // and so on.
|
| @@ -153,14 +153,14 @@ int Merge::Process(int16_t* input, size_t input_length,
|
|
|
| // Return new added length. |old_length| samples were borrowed from
|
| // |sync_buffer_|.
|
| - return static_cast<int>(output_length) - old_length;
|
| + return output_length - old_length;
|
| }
|
|
|
| -int Merge::GetExpandedSignal(int* old_length, int* expand_period) {
|
| +size_t Merge::GetExpandedSignal(size_t* old_length, size_t* expand_period) {
|
| // Check how much data that is left since earlier.
|
| - *old_length = static_cast<int>(sync_buffer_->FutureLength());
|
| + *old_length = sync_buffer_->FutureLength();
|
| // Should never be less than overlap_length.
|
| - assert(*old_length >= static_cast<int>(expand_->overlap_length()));
|
| + assert(*old_length >= expand_->overlap_length());
|
| // Generate data to merge the overlap with using expand.
|
| expand_->SetParametersForMergeAfterExpand();
|
|
|
| @@ -171,7 +171,7 @@ int Merge::GetExpandedSignal(int* old_length, int* expand_period) {
|
| // but shift them towards the end of the buffer. This is ok, since all of
|
| // the buffer will be expand data anyway, so as long as the beginning is
|
| // left untouched, we're fine.
|
| - int16_t length_diff = *old_length - 210 * kMaxSampleRate / 8000;
|
| + size_t length_diff = *old_length - 210 * kMaxSampleRate / 8000;
|
| sync_buffer_->InsertZerosAtIndex(length_diff, sync_buffer_->next_index());
|
| *old_length = 210 * kMaxSampleRate / 8000;
|
| // This is the truncated length.
|
| @@ -181,34 +181,34 @@ int Merge::GetExpandedSignal(int* old_length, int* expand_period) {
|
|
|
| AudioMultiVector expanded_temp(num_channels_);
|
| expand_->Process(&expanded_temp);
|
| - *expand_period = static_cast<int>(expanded_temp.Size()); // Samples per
|
| - // channel.
|
| + *expand_period = expanded_temp.Size(); // Samples per channel.
|
|
|
| expanded_.Clear();
|
| // Copy what is left since earlier into the expanded vector.
|
| expanded_.PushBackFromIndex(*sync_buffer_, sync_buffer_->next_index());
|
| - assert(expanded_.Size() == static_cast<size_t>(*old_length));
|
| + assert(expanded_.Size() == *old_length);
|
| assert(expanded_temp.Size() > 0);
|
| // Do "ugly" copy and paste from the expanded in order to generate more data
|
| // to correlate (but not interpolate) with.
|
| - const int required_length = (120 + 80 + 2) * fs_mult_;
|
| - if (expanded_.Size() < static_cast<size_t>(required_length)) {
|
| - while (expanded_.Size() < static_cast<size_t>(required_length)) {
|
| + const size_t required_length = static_cast<size_t>((120 + 80 + 2) * fs_mult_);
|
| + if (expanded_.Size() < required_length) {
|
| + while (expanded_.Size() < required_length) {
|
| // Append one more pitch period each time.
|
| expanded_.PushBack(expanded_temp);
|
| }
|
| // Trim the length to exactly |required_length|.
|
| expanded_.PopBack(expanded_.Size() - required_length);
|
| }
|
| - assert(expanded_.Size() >= static_cast<size_t>(required_length));
|
| + assert(expanded_.Size() >= required_length);
|
| return required_length;
|
| }
|
|
|
| -int16_t Merge::SignalScaling(const int16_t* input, int input_length,
|
| +int16_t Merge::SignalScaling(const int16_t* input, size_t input_length,
|
| const int16_t* expanded_signal,
|
| int16_t* expanded_max, int16_t* input_max) const {
|
| // Adjust muting factor if new vector is more or less of the BGN energy.
|
| - const int mod_input_length = std::min(64 * fs_mult_, input_length);
|
| + const size_t mod_input_length =
|
| + std::min(static_cast<size_t>(64 * fs_mult_), input_length);
|
| *expanded_max = WebRtcSpl_MaxAbsValueW16(expanded_signal, mod_input_length);
|
| *input_max = WebRtcSpl_MaxAbsValueW16(input, mod_input_length);
|
|
|
| @@ -260,13 +260,13 @@ int16_t Merge::SignalScaling(const int16_t* input, int input_length,
|
|
|
| // TODO(hlundin): There are some parameter values in this method that seem
|
| // strange. Compare with Expand::Correlation.
|
| -void Merge::Downsample(const int16_t* input, int input_length,
|
| - const int16_t* expanded_signal, int expanded_length) {
|
| +void Merge::Downsample(const int16_t* input, size_t input_length,
|
| + const int16_t* expanded_signal, size_t expanded_length) {
|
| const int16_t* filter_coefficients;
|
| - int num_coefficients;
|
| + size_t num_coefficients;
|
| int decimation_factor = fs_hz_ / 4000;
|
| - static const int kCompensateDelay = 0;
|
| - int length_limit = fs_hz_ / 100; // 10 ms in samples.
|
| + static const size_t kCompensateDelay = 0;
|
| + size_t length_limit = static_cast<size_t>(fs_hz_ / 100); // 10 ms in samples.
|
| if (fs_hz_ == 8000) {
|
| filter_coefficients = DspHelper::kDownsample8kHzTbl;
|
| num_coefficients = 3;
|
| @@ -280,7 +280,7 @@ void Merge::Downsample(const int16_t* input, int input_length,
|
| filter_coefficients = DspHelper::kDownsample48kHzTbl;
|
| num_coefficients = 7;
|
| }
|
| - int signal_offset = num_coefficients - 1;
|
| + size_t signal_offset = num_coefficients - 1;
|
| WebRtcSpl_DownsampleFast(&expanded_signal[signal_offset],
|
| expanded_length - signal_offset,
|
| expanded_downsampled_, kExpandDownsampLength,
|
| @@ -288,10 +288,10 @@ void Merge::Downsample(const int16_t* input, int input_length,
|
| decimation_factor, kCompensateDelay);
|
| if (input_length <= length_limit) {
|
| // Not quite long enough, so we have to cheat a bit.
|
| - int16_t temp_len = input_length - signal_offset;
|
| + size_t temp_len = input_length - signal_offset;
|
| // TODO(hlundin): Should |downsamp_temp_len| be corrected for round-off
|
| // errors? I.e., (temp_len + decimation_factor - 1) / decimation_factor?
|
| - int16_t downsamp_temp_len = temp_len / decimation_factor;
|
| + size_t downsamp_temp_len = temp_len / decimation_factor;
|
| WebRtcSpl_DownsampleFast(&input[signal_offset], temp_len,
|
| input_downsampled_, downsamp_temp_len,
|
| filter_coefficients, num_coefficients,
|
| @@ -307,12 +307,12 @@ void Merge::Downsample(const int16_t* input, int input_length,
|
| }
|
| }
|
|
|
| -int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
|
| - int start_position, int input_length,
|
| - int expand_period) const {
|
| +size_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
|
| + size_t start_position, size_t input_length,
|
| + size_t expand_period) const {
|
| // Calculate correlation without any normalization.
|
| - const int max_corr_length = kMaxCorrelationLength;
|
| - int stop_position_downsamp =
|
| + const size_t max_corr_length = kMaxCorrelationLength;
|
| + size_t stop_position_downsamp =
|
| std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1);
|
| int correlation_shift = 0;
|
| if (expanded_max * input_max > 26843546) {
|
| @@ -325,8 +325,8 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
|
| stop_position_downsamp, correlation_shift, 1);
|
|
|
| // Normalize correlation to 14 bits and copy to a 16-bit array.
|
| - const int pad_length = static_cast<int>(expand_->overlap_length() - 1);
|
| - const int correlation_buffer_size = 2 * pad_length + kMaxCorrelationLength;
|
| + const size_t pad_length = expand_->overlap_length() - 1;
|
| + const size_t correlation_buffer_size = 2 * pad_length + kMaxCorrelationLength;
|
| rtc::scoped_ptr<int16_t[]> correlation16(
|
| new int16_t[correlation_buffer_size]);
|
| memset(correlation16.get(), 0, correlation_buffer_size * sizeof(int16_t));
|
| @@ -342,21 +342,20 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
|
| // (1) w16_bestIndex + input_length <
|
| // timestamps_per_call_ + expand_->overlap_length();
|
| // (2) w16_bestIndex + input_length < start_position.
|
| - int start_index = timestamps_per_call_ +
|
| - static_cast<int>(expand_->overlap_length());
|
| + size_t start_index = timestamps_per_call_ + expand_->overlap_length();
|
| start_index = std::max(start_position, start_index);
|
| start_index = (input_length > start_index) ? 0 : (start_index - input_length);
|
| // Downscale starting index to 4kHz domain. (fs_mult_ * 2 = fs_hz_ / 4000.)
|
| - int start_index_downsamp = start_index / (fs_mult_ * 2);
|
| + size_t start_index_downsamp = start_index / (fs_mult_ * 2);
|
|
|
| // Calculate a modified |stop_position_downsamp| to account for the increased
|
| // start index |start_index_downsamp| and the effective array length.
|
| - int modified_stop_pos =
|
| + size_t modified_stop_pos =
|
| std::min(stop_position_downsamp,
|
| kMaxCorrelationLength + pad_length - start_index_downsamp);
|
| - int best_correlation_index;
|
| + size_t best_correlation_index;
|
| int16_t best_correlation;
|
| - static const int kNumCorrelationCandidates = 1;
|
| + static const size_t kNumCorrelationCandidates = 1;
|
| DspHelper::PeakDetection(&correlation_ptr[start_index_downsamp],
|
| modified_stop_pos, kNumCorrelationCandidates,
|
| fs_mult_, &best_correlation_index,
|
| @@ -368,16 +367,16 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
|
| // least 10ms + overlap . (This should never happen thanks to the above
|
| // modification of peak-finding starting point.)
|
| while (((best_correlation_index + input_length) <
|
| - static_cast<int>(timestamps_per_call_ + expand_->overlap_length())) ||
|
| - ((best_correlation_index + input_length) < start_position)) {
|
| + (timestamps_per_call_ + expand_->overlap_length())) ||
|
| + ((best_correlation_index + input_length) < start_position)) {
|
| assert(false); // Should never happen.
|
| best_correlation_index += expand_period; // Jump one lag ahead.
|
| }
|
| return best_correlation_index;
|
| }
|
|
|
| -int Merge::RequiredFutureSamples() {
|
| - return static_cast<int>(fs_hz_ / 100 * num_channels_); // 10 ms.
|
| +size_t Merge::RequiredFutureSamples() {
|
| + return fs_hz_ / 100 * num_channels_; // 10 ms.
|
| }
|
|
|
|
|
|
|