2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/merge.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <string.h> // memmove, memcpy, memset, size_t
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
#include <algorithm> // min, max
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/signal_processing/include/signal_processing_library.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/audio_multi_vector.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/cross_correlation.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/dsp_helper.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/expand.h"
|
|
|
|
|
#include "modules/audio_coding/neteq/sync_buffer.h"
|
2017-11-22 10:42:26 +01:00
|
|
|
#include "rtc_base/numerics/safe_conversions.h"
|
|
|
|
|
#include "rtc_base/numerics/safe_minmax.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-04-09 15:44:22 +02:00
|
|
|
Merge::Merge(int fs_hz,
|
|
|
|
|
size_t num_channels,
|
|
|
|
|
Expand* expand,
|
|
|
|
|
SyncBuffer* sync_buffer)
|
|
|
|
|
: fs_hz_(fs_hz),
|
|
|
|
|
num_channels_(num_channels),
|
|
|
|
|
fs_mult_(fs_hz_ / 8000),
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
timestamps_per_call_(static_cast<size_t>(fs_hz_ / 100)),
|
2015-04-09 15:44:22 +02:00
|
|
|
expand_(expand),
|
|
|
|
|
sync_buffer_(sync_buffer),
|
|
|
|
|
expanded_(num_channels_) {
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_GT(num_channels_, 0);
|
2015-04-09 15:44:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-02 04:46:11 -07:00
|
|
|
Merge::~Merge() = default;
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
size_t Merge::Process(int16_t* input,
|
|
|
|
|
size_t input_length,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
AudioMultiVector* output) {
|
2013-01-29 12:09:21 +00:00
|
|
|
// TODO(hlundin): Change to an enumerator and skip assert.
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK(fs_hz_ == 8000 || fs_hz_ == 16000 || fs_hz_ == 32000 ||
|
|
|
|
|
fs_hz_ == 48000);
|
|
|
|
|
RTC_DCHECK_LE(fs_hz_, kMaxSampleRate); // Should not be possible.
|
2020-12-03 10:06:25 +01:00
|
|
|
if (input_length == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-01-29 12:09:21 +00:00
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t old_length;
|
|
|
|
|
size_t expand_period;
|
2013-01-29 12:09:21 +00:00
|
|
|
// Get expansion data to overlap and mix with.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t expanded_length = GetExpandedSignal(&old_length, &expand_period);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Transfer input signal to an AudioMultiVector.
|
2013-09-30 20:38:44 +00:00
|
|
|
AudioMultiVector input_vector(num_channels_);
|
2018-09-05 18:14:52 +02:00
|
|
|
input_vector.PushBackInterleaved(
|
|
|
|
|
rtc::ArrayView<const int16_t>(input, input_length));
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t input_length_per_channel = input_vector.Size();
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_EQ(input_length_per_channel, input_length / num_channels_);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t best_correlation_index = 0;
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t output_length = 0;
|
|
|
|
|
|
2016-05-10 19:55:56 +02:00
|
|
|
std::unique_ptr<int16_t[]> input_channel(
|
|
|
|
|
new int16_t[input_length_per_channel]);
|
|
|
|
|
std::unique_ptr<int16_t[]> expanded_channel(new int16_t[expanded_length]);
|
2013-01-29 12:09:21 +00:00
|
|
|
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
2018-06-19 15:03:05 +02:00
|
|
|
input_vector[channel].CopyTo(input_length_per_channel, 0,
|
|
|
|
|
input_channel.get());
|
2016-05-10 19:55:56 +02:00
|
|
|
expanded_[channel].CopyTo(expanded_length, 0, expanded_channel.get());
|
|
|
|
|
|
2018-05-22 10:40:23 +02:00
|
|
|
const int16_t new_mute_factor = std::min<int16_t>(
|
|
|
|
|
16384, SignalScaling(input_channel.get(), input_length_per_channel,
|
|
|
|
|
expanded_channel.get()));
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
if (channel == 0) {
|
|
|
|
|
// Downsample, correlate, and find strongest correlation period for the
|
2020-06-29 12:17:42 +02:00
|
|
|
// reference (i.e., first) channel only.
|
2013-01-29 12:09:21 +00:00
|
|
|
// Downsample to 4kHz sample rate.
|
2016-05-10 19:55:56 +02:00
|
|
|
Downsample(input_channel.get(), input_length_per_channel,
|
|
|
|
|
expanded_channel.get(), expanded_length);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Calculate the lag of the strongest correlation period.
|
2013-09-20 16:25:28 +00:00
|
|
|
best_correlation_index = CorrelateAndPeakSearch(
|
2016-05-02 01:50:30 -07:00
|
|
|
old_length, input_length_per_channel, expand_period);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-02 04:46:11 -07:00
|
|
|
temp_data_.resize(input_length_per_channel + best_correlation_index);
|
|
|
|
|
int16_t* decoded_output = temp_data_.data() + best_correlation_index;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Mute the new decoded data if needed (and unmute it linearly).
|
|
|
|
|
// This is the overlapping part of expanded_signal.
|
2018-06-19 15:03:05 +02:00
|
|
|
size_t interpolation_length =
|
|
|
|
|
std::min(kMaxCorrelationLength * fs_mult_,
|
|
|
|
|
expanded_length - best_correlation_index);
|
|
|
|
|
interpolation_length =
|
|
|
|
|
std::min(interpolation_length, input_length_per_channel);
|
2018-05-22 10:40:23 +02:00
|
|
|
|
|
|
|
|
RTC_DCHECK_LE(new_mute_factor, 16384);
|
|
|
|
|
int16_t mute_factor =
|
|
|
|
|
std::max(expand_->MuteFactor(channel), new_mute_factor);
|
|
|
|
|
RTC_DCHECK_GE(mute_factor, 0);
|
|
|
|
|
|
|
|
|
|
if (mute_factor < 16384) {
|
2013-01-29 12:09:21 +00:00
|
|
|
// Set a suitable muting slope (Q20). 0.004 for NB, 0.002 for WB,
|
2018-05-22 10:40:23 +02:00
|
|
|
// and so on, or as fast as it takes to come back to full gain within the
|
|
|
|
|
// frame length.
|
|
|
|
|
const int back_to_fullscale_inc = static_cast<int>(
|
|
|
|
|
((16384 - mute_factor) << 6) / input_length_per_channel);
|
|
|
|
|
const int increment = std::max(4194 / fs_mult_, back_to_fullscale_inc);
|
|
|
|
|
mute_factor = static_cast<int16_t>(DspHelper::RampSignal(
|
|
|
|
|
input_channel.get(), interpolation_length, mute_factor, increment));
|
2013-01-29 12:09:21 +00:00
|
|
|
DspHelper::UnmuteSignal(&input_channel[interpolation_length],
|
|
|
|
|
input_length_per_channel - interpolation_length,
|
2018-05-22 10:40:23 +02:00
|
|
|
&mute_factor, increment,
|
2013-01-29 12:09:21 +00:00
|
|
|
&decoded_output[interpolation_length]);
|
|
|
|
|
} else {
|
|
|
|
|
// No muting needed.
|
|
|
|
|
memmove(
|
|
|
|
|
&decoded_output[interpolation_length],
|
|
|
|
|
&input_channel[interpolation_length],
|
|
|
|
|
sizeof(int16_t) * (input_length_per_channel - interpolation_length));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do overlap and mix linearly.
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
int16_t increment =
|
|
|
|
|
static_cast<int16_t>(16384 / (interpolation_length + 1)); // In Q14.
|
2018-05-22 10:40:23 +02:00
|
|
|
int16_t local_mute_factor = 16384 - increment;
|
2016-05-10 19:55:56 +02:00
|
|
|
memmove(temp_data_.data(), expanded_channel.get(),
|
2013-01-29 12:09:21 +00:00
|
|
|
sizeof(int16_t) * best_correlation_index);
|
|
|
|
|
DspHelper::CrossFade(&expanded_channel[best_correlation_index],
|
2016-05-10 19:55:56 +02:00
|
|
|
input_channel.get(), interpolation_length,
|
2018-05-22 10:40:23 +02:00
|
|
|
&local_mute_factor, increment, decoded_output);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
output_length = best_correlation_index + input_length_per_channel;
|
|
|
|
|
if (channel == 0) {
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK(output->Empty()); // Output should be empty at this point.
|
2013-01-29 12:09:21 +00:00
|
|
|
output->AssertSize(output_length);
|
|
|
|
|
} else {
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_EQ(output->Size(), output_length);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
2016-05-10 19:55:56 +02:00
|
|
|
(*output)[channel].OverwriteAt(temp_data_.data(), output_length, 0);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Copy back the first part of the data to `sync_buffer_` and remove it from
|
|
|
|
|
// `output`.
|
2013-01-29 12:09:21 +00:00
|
|
|
sync_buffer_->ReplaceAtIndex(*output, old_length, sync_buffer_->next_index());
|
|
|
|
|
output->PopFront(old_length);
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Return new added length. `old_length` samples were borrowed from
|
|
|
|
|
// `sync_buffer_`.
|
2017-05-05 05:04:16 -07:00
|
|
|
RTC_DCHECK_GE(output_length, old_length);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
return output_length - old_length;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t Merge::GetExpandedSignal(size_t* old_length, size_t* expand_period) {
|
2013-01-29 12:09:21 +00:00
|
|
|
// Check how much data that is left since earlier.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
*old_length = sync_buffer_->FutureLength();
|
2013-01-29 12:09:21 +00:00
|
|
|
// Should never be less than overlap_length.
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_GE(*old_length, expand_->overlap_length());
|
2013-01-29 12:09:21 +00:00
|
|
|
// Generate data to merge the overlap with using expand.
|
|
|
|
|
expand_->SetParametersForMergeAfterExpand();
|
|
|
|
|
|
|
|
|
|
if (*old_length >= 210 * kMaxSampleRate / 8000) {
|
|
|
|
|
// TODO(hlundin): Write test case for this.
|
|
|
|
|
// The number of samples available in the sync buffer is more than what fits
|
|
|
|
|
// in expanded_signal. Keep the first 210 * kMaxSampleRate / 8000 samples,
|
|
|
|
|
// 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.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t length_diff = *old_length - 210 * kMaxSampleRate / 8000;
|
2013-01-29 12:09:21 +00:00
|
|
|
sync_buffer_->InsertZerosAtIndex(length_diff, sync_buffer_->next_index());
|
|
|
|
|
*old_length = 210 * kMaxSampleRate / 8000;
|
|
|
|
|
// This is the truncated length.
|
|
|
|
|
}
|
|
|
|
|
// This assert should always be true thanks to the if statement above.
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_GE(210 * kMaxSampleRate / 8000, *old_length);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2013-09-30 20:38:44 +00:00
|
|
|
AudioMultiVector expanded_temp(num_channels_);
|
2013-01-29 12:09:21 +00:00
|
|
|
expand_->Process(&expanded_temp);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
*expand_period = expanded_temp.Size(); // Samples per channel.
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
expanded_.Clear();
|
|
|
|
|
// Copy what is left since earlier into the expanded vector.
|
|
|
|
|
expanded_.PushBackFromIndex(*sync_buffer_, sync_buffer_->next_index());
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_EQ(expanded_.Size(), *old_length);
|
|
|
|
|
RTC_DCHECK_GT(expanded_temp.Size(), 0);
|
2013-01-29 12:09:21 +00:00
|
|
|
// Do "ugly" copy and paste from the expanded in order to generate more data
|
|
|
|
|
// to correlate (but not interpolate) with.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t required_length = static_cast<size_t>((120 + 80 + 2) * fs_mult_);
|
|
|
|
|
if (expanded_.Size() < required_length) {
|
|
|
|
|
while (expanded_.Size() < required_length) {
|
2013-01-29 12:09:21 +00:00
|
|
|
// Append one more pitch period each time.
|
|
|
|
|
expanded_.PushBack(expanded_temp);
|
|
|
|
|
}
|
2021-07-28 20:00:17 +02:00
|
|
|
// Trim the length to exactly `required_length`.
|
2013-01-29 12:09:21 +00:00
|
|
|
expanded_.PopBack(expanded_.Size() - required_length);
|
|
|
|
|
}
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_GE(expanded_.Size(), required_length);
|
2013-01-29 12:09:21 +00:00
|
|
|
return required_length;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
int16_t Merge::SignalScaling(const int16_t* input,
|
|
|
|
|
size_t input_length,
|
2016-05-02 01:50:30 -07:00
|
|
|
const int16_t* expanded_signal) const {
|
2013-01-29 12:09:21 +00:00
|
|
|
// Adjust muting factor if new vector is more or less of the BGN energy.
|
2025-02-20 09:42:51 +00:00
|
|
|
const auto mod_input_length =
|
|
|
|
|
SafeMin<size_t>(64 * rtc::dchecked_cast<size_t>(fs_mult_), input_length);
|
2016-05-02 01:50:30 -07:00
|
|
|
const int16_t expanded_max =
|
|
|
|
|
WebRtcSpl_MaxAbsValueW16(expanded_signal, mod_input_length);
|
2018-06-19 15:03:05 +02:00
|
|
|
int32_t factor =
|
|
|
|
|
(expanded_max * expanded_max) / (std::numeric_limits<int32_t>::max() /
|
|
|
|
|
static_cast<int32_t>(mod_input_length));
|
2016-05-02 04:46:11 -07:00
|
|
|
const int expanded_shift = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor);
|
2018-06-19 15:03:05 +02:00
|
|
|
int32_t energy_expanded = WebRtcSpl_DotProductWithScale(
|
|
|
|
|
expanded_signal, expanded_signal, mod_input_length, expanded_shift);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Calculate energy of input signal.
|
2016-05-02 04:46:11 -07:00
|
|
|
const int16_t input_max = WebRtcSpl_MaxAbsValueW16(input, mod_input_length);
|
|
|
|
|
factor = (input_max * input_max) / (std::numeric_limits<int32_t>::max() /
|
2018-06-19 15:03:05 +02:00
|
|
|
static_cast<int32_t>(mod_input_length));
|
2016-05-02 04:46:11 -07:00
|
|
|
const int input_shift = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor);
|
2018-06-19 15:03:05 +02:00
|
|
|
int32_t energy_input = WebRtcSpl_DotProductWithScale(
|
|
|
|
|
input, input, mod_input_length, input_shift);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Align to the same Q-domain.
|
|
|
|
|
if (input_shift > expanded_shift) {
|
|
|
|
|
energy_expanded = energy_expanded >> (input_shift - expanded_shift);
|
|
|
|
|
} else {
|
|
|
|
|
energy_input = energy_input >> (expanded_shift - input_shift);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate muting factor to use for new frame.
|
|
|
|
|
int16_t mute_factor;
|
|
|
|
|
if (energy_input > energy_expanded) {
|
2021-07-28 20:00:17 +02:00
|
|
|
// Normalize `energy_input` to 14 bits.
|
2013-01-29 12:09:21 +00:00
|
|
|
int16_t temp_shift = WebRtcSpl_NormW32(energy_input) - 17;
|
|
|
|
|
energy_input = WEBRTC_SPL_SHIFT_W32(energy_input, temp_shift);
|
2021-07-28 20:00:17 +02:00
|
|
|
// Put `energy_expanded` in a domain 14 higher, so that
|
2013-01-29 12:09:21 +00:00
|
|
|
// energy_expanded / energy_input is in Q14.
|
|
|
|
|
energy_expanded = WEBRTC_SPL_SHIFT_W32(energy_expanded, temp_shift + 14);
|
|
|
|
|
// Calculate sqrt(energy_expanded / energy_input) in Q14.
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
mute_factor = static_cast<int16_t>(
|
|
|
|
|
WebRtcSpl_SqrtFloor((energy_expanded / energy_input) << 14));
|
2013-01-29 12:09:21 +00:00
|
|
|
} else {
|
2021-07-28 20:00:17 +02:00
|
|
|
// Set to 1 (in Q14) when `expanded` has higher energy than `input`.
|
2013-01-29 12:09:21 +00:00
|
|
|
mute_factor = 16384;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mute_factor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(hlundin): There are some parameter values in this method that seem
|
|
|
|
|
// strange. Compare with Expand::Correlation.
|
2018-06-19 15:03:05 +02:00
|
|
|
void Merge::Downsample(const int16_t* input,
|
|
|
|
|
size_t input_length,
|
|
|
|
|
const int16_t* expanded_signal,
|
|
|
|
|
size_t expanded_length) {
|
2013-01-29 12:09:21 +00:00
|
|
|
const int16_t* filter_coefficients;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t num_coefficients;
|
2013-01-29 12:09:21 +00:00
|
|
|
int decimation_factor = fs_hz_ / 4000;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
static const size_t kCompensateDelay = 0;
|
|
|
|
|
size_t length_limit = static_cast<size_t>(fs_hz_ / 100); // 10 ms in samples.
|
2013-01-29 12:09:21 +00:00
|
|
|
if (fs_hz_ == 8000) {
|
|
|
|
|
filter_coefficients = DspHelper::kDownsample8kHzTbl;
|
|
|
|
|
num_coefficients = 3;
|
|
|
|
|
} else if (fs_hz_ == 16000) {
|
|
|
|
|
filter_coefficients = DspHelper::kDownsample16kHzTbl;
|
|
|
|
|
num_coefficients = 5;
|
|
|
|
|
} else if (fs_hz_ == 32000) {
|
|
|
|
|
filter_coefficients = DspHelper::kDownsample32kHzTbl;
|
|
|
|
|
num_coefficients = 7;
|
|
|
|
|
} else { // fs_hz_ == 48000
|
|
|
|
|
filter_coefficients = DspHelper::kDownsample48kHzTbl;
|
|
|
|
|
num_coefficients = 7;
|
|
|
|
|
}
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t signal_offset = num_coefficients - 1;
|
2018-06-19 15:03:05 +02:00
|
|
|
WebRtcSpl_DownsampleFast(
|
|
|
|
|
&expanded_signal[signal_offset], expanded_length - signal_offset,
|
|
|
|
|
expanded_downsampled_, kExpandDownsampLength, filter_coefficients,
|
|
|
|
|
num_coefficients, decimation_factor, kCompensateDelay);
|
2013-01-29 12:09:21 +00:00
|
|
|
if (input_length <= length_limit) {
|
|
|
|
|
// Not quite long enough, so we have to cheat a bit.
|
2019-11-25 10:21:00 +01:00
|
|
|
// If the input is shorter than the offset, we consider the input to be 0
|
|
|
|
|
// length. This will cause us to skip the downsampling since it makes no
|
|
|
|
|
// sense anyway, and input_downsampled_ will be filled with zeros. This is
|
|
|
|
|
// clearly a pathological case, and the signal quality will suffer, but
|
|
|
|
|
// there is not much we can do.
|
|
|
|
|
const size_t temp_len =
|
|
|
|
|
input_length > signal_offset ? input_length - signal_offset : 0;
|
2021-07-28 20:00:17 +02:00
|
|
|
// TODO(hlundin): Should `downsamp_temp_len` be corrected for round-off
|
2013-01-29 12:09:21 +00:00
|
|
|
// errors? I.e., (temp_len + decimation_factor - 1) / decimation_factor?
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t downsamp_temp_len = temp_len / decimation_factor;
|
2019-11-25 10:21:00 +01:00
|
|
|
if (downsamp_temp_len > 0) {
|
|
|
|
|
WebRtcSpl_DownsampleFast(&input[signal_offset], temp_len,
|
|
|
|
|
input_downsampled_, downsamp_temp_len,
|
|
|
|
|
filter_coefficients, num_coefficients,
|
|
|
|
|
decimation_factor, kCompensateDelay);
|
|
|
|
|
}
|
2013-01-29 12:09:21 +00:00
|
|
|
memset(&input_downsampled_[downsamp_temp_len], 0,
|
|
|
|
|
sizeof(int16_t) * (kInputDownsampLength - downsamp_temp_len));
|
|
|
|
|
} else {
|
2018-06-19 15:03:05 +02:00
|
|
|
WebRtcSpl_DownsampleFast(
|
|
|
|
|
&input[signal_offset], input_length - signal_offset, input_downsampled_,
|
|
|
|
|
kInputDownsampLength, filter_coefficients, num_coefficients,
|
|
|
|
|
decimation_factor, kCompensateDelay);
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
size_t Merge::CorrelateAndPeakSearch(size_t start_position,
|
|
|
|
|
size_t input_length,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t expand_period) const {
|
2013-01-29 12:09:21 +00:00
|
|
|
// Calculate correlation without any normalization.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t max_corr_length = kMaxCorrelationLength;
|
|
|
|
|
size_t stop_position_downsamp =
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
int32_t correlation[kMaxCorrelationLength];
|
2016-05-02 01:50:30 -07:00
|
|
|
CrossCorrelationWithAutoShift(input_downsampled_, expanded_downsampled_,
|
|
|
|
|
kInputDownsampLength, stop_position_downsamp, 1,
|
|
|
|
|
correlation);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Normalize correlation to 14 bits and copy to a 16-bit array.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t pad_length = expand_->overlap_length() - 1;
|
|
|
|
|
const size_t correlation_buffer_size = 2 * pad_length + kMaxCorrelationLength;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<int16_t[]> correlation16(
|
2015-02-26 14:34:55 +00:00
|
|
|
new int16_t[correlation_buffer_size]);
|
2014-04-11 18:47:55 +00:00
|
|
|
memset(correlation16.get(), 0, correlation_buffer_size * sizeof(int16_t));
|
|
|
|
|
int16_t* correlation_ptr = &correlation16[pad_length];
|
2018-06-19 15:03:05 +02:00
|
|
|
int32_t max_correlation =
|
|
|
|
|
WebRtcSpl_MaxAbsValueW32(correlation, stop_position_downsamp);
|
Reland "Upconvert various types to int.", neteq portion.
This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the
files in webrtc/modules/audio_coding/neteq/ are relanded.
The original commit message is below:
Upconvert various types to int.
Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t.
Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C."
This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t). Other locations will be converted to size_t in a separate change.
BUG=none
TBR=kwiberg
Review URL: https://codereview.webrtc.org/1181073002
Cr-Commit-Position: refs/heads/master@{#9427}
2015-06-11 19:57:18 -07:00
|
|
|
int norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation));
|
2013-01-29 12:09:21 +00:00
|
|
|
WebRtcSpl_VectorBitShiftW32ToW16(correlation_ptr, stop_position_downsamp,
|
|
|
|
|
correlation, norm_shift);
|
|
|
|
|
|
|
|
|
|
// Calculate allowed starting point for peak finding.
|
|
|
|
|
// The peak location bestIndex must fulfill two criteria:
|
|
|
|
|
// (1) w16_bestIndex + input_length <
|
|
|
|
|
// timestamps_per_call_ + expand_->overlap_length();
|
|
|
|
|
// (2) w16_bestIndex + input_length < start_position.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t start_index = timestamps_per_call_ + expand_->overlap_length();
|
2013-01-29 12:09:21 +00:00
|
|
|
start_index = std::max(start_position, start_index);
|
2015-06-10 21:15:38 -07:00
|
|
|
start_index = (input_length > start_index) ? 0 : (start_index - input_length);
|
2013-01-29 12:09:21 +00:00
|
|
|
// Downscale starting index to 4kHz domain. (fs_mult_ * 2 = fs_hz_ / 4000.)
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t start_index_downsamp = start_index / (fs_mult_ * 2);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Calculate a modified `stop_position_downsamp` to account for the increased
|
|
|
|
|
// start index `start_index_downsamp` and the effective array length.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t modified_stop_pos =
|
2013-01-29 12:09:21 +00:00
|
|
|
std::min(stop_position_downsamp,
|
2014-04-11 18:47:55 +00:00
|
|
|
kMaxCorrelationLength + pad_length - start_index_downsamp);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t best_correlation_index;
|
2013-01-29 12:09:21 +00:00
|
|
|
int16_t best_correlation;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
static const size_t kNumCorrelationCandidates = 1;
|
2013-01-29 12:09:21 +00:00
|
|
|
DspHelper::PeakDetection(&correlation_ptr[start_index_downsamp],
|
|
|
|
|
modified_stop_pos, kNumCorrelationCandidates,
|
|
|
|
|
fs_mult_, &best_correlation_index,
|
|
|
|
|
&best_correlation);
|
|
|
|
|
// Compensate for modified start index.
|
|
|
|
|
best_correlation_index += start_index;
|
|
|
|
|
|
|
|
|
|
// Ensure that underrun does not occur for 10ms case => we have to get at
|
|
|
|
|
// least 10ms + overlap . (This should never happen thanks to the above
|
|
|
|
|
// modification of peak-finding starting point.)
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
while (((best_correlation_index + input_length) <
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
(timestamps_per_call_ + expand_->overlap_length())) ||
|
|
|
|
|
((best_correlation_index + input_length) < start_position)) {
|
2021-11-15 16:57:07 +01:00
|
|
|
RTC_DCHECK_NOTREACHED(); // Should never happen.
|
2013-01-29 12:09:21 +00:00
|
|
|
best_correlation_index += expand_period; // Jump one lag ahead.
|
|
|
|
|
}
|
|
|
|
|
return best_correlation_index;
|
|
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t Merge::RequiredFutureSamples() {
|
|
|
|
|
return fs_hz_ / 100 * num_channels_; // 10 ms.
|
2014-04-11 18:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
} // namespace webrtc
|