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
|
|
|
#ifndef MODULES_AUDIO_CODING_NETEQ_EXPAND_H_
|
|
|
|
|
#define MODULES_AUDIO_CODING_NETEQ_EXPAND_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/audio_coding/neteq/audio_vector.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Forward declarations.
|
2018-10-23 12:03:01 +02:00
|
|
|
class AudioMultiVector;
|
2013-01-29 12:09:21 +00:00
|
|
|
class BackgroundNoise;
|
|
|
|
|
class RandomVector;
|
2015-08-18 14:58:09 +02:00
|
|
|
class StatisticsCalculator;
|
2013-01-29 12:09:21 +00:00
|
|
|
class SyncBuffer;
|
|
|
|
|
|
|
|
|
|
// This class handles extrapolation of audio data from the sync_buffer to
|
|
|
|
|
// produce packet-loss concealment.
|
|
|
|
|
// TODO(hlundin): Refactor this class to divide the long methods into shorter
|
|
|
|
|
// ones.
|
|
|
|
|
class Expand {
|
|
|
|
|
public:
|
|
|
|
|
Expand(BackgroundNoise* background_noise,
|
|
|
|
|
SyncBuffer* sync_buffer,
|
|
|
|
|
RandomVector* random_vector,
|
2015-08-18 14:58:09 +02:00
|
|
|
StatisticsCalculator* statistics,
|
2013-01-29 12:09:21 +00:00
|
|
|
int fs,
|
2015-04-09 15:44:22 +02:00
|
|
|
size_t num_channels);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-04-09 15:44:22 +02:00
|
|
|
virtual ~Expand();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
Expand(const Expand&) = delete;
|
|
|
|
|
Expand& operator=(const Expand&) = delete;
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Resets the object.
|
2014-04-11 18:47:55 +00:00
|
|
|
virtual void Reset();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// The main method to produce concealment data. The data is appended to the
|
2021-07-28 20:00:17 +02:00
|
|
|
// end of `output`.
|
2014-04-11 18:47:55 +00:00
|
|
|
virtual int Process(AudioMultiVector* output);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Prepare the object to do extra expansion during normal operation following
|
|
|
|
|
// a period of expands.
|
2014-04-11 18:47:55 +00:00
|
|
|
virtual void SetParametersForNormalAfterExpand();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Prepare the object to do extra expansion during merge operation following
|
|
|
|
|
// a period of expands.
|
2014-04-11 18:47:55 +00:00
|
|
|
virtual void SetParametersForMergeAfterExpand();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Returns the mute factor for `channel`.
|
2018-05-22 13:21:01 +02:00
|
|
|
int16_t MuteFactor(size_t channel) const {
|
2021-07-08 20:08:20 +02:00
|
|
|
RTC_DCHECK_LT(channel, num_channels_);
|
2013-01-29 12:09:21 +00:00
|
|
|
return channel_parameters_[channel].mute_factor;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-10 05:54:35 -07:00
|
|
|
// Returns true if expansion has been faded down to zero amplitude (for all
|
|
|
|
|
// channels); false otherwise.
|
|
|
|
|
bool Muted() const;
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Accessors and mutators.
|
2015-04-09 15:44:22 +02:00
|
|
|
virtual size_t overlap_length() const;
|
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 max_lag() const { return max_lag_; }
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2014-04-11 18:47:55 +00:00
|
|
|
protected:
|
|
|
|
|
static const int kMaxConsecutiveExpands = 200;
|
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
|
|
|
void GenerateRandomVector(int16_t seed_increment,
|
2014-04-11 18:47:55 +00:00
|
|
|
size_t length,
|
|
|
|
|
int16_t* random_vector);
|
|
|
|
|
|
|
|
|
|
// Initializes member variables at the beginning of an expand period.
|
|
|
|
|
void InitializeForAnExpandPeriod();
|
|
|
|
|
|
|
|
|
|
bool TooManyExpands();
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Analyzes the signal history in `sync_buffer_`, and set up all parameters
|
2014-04-11 18:47:55 +00:00
|
|
|
// necessary to produce concealment data.
|
|
|
|
|
void AnalyzeSignal(int16_t* random_vector);
|
|
|
|
|
|
2015-08-18 14:58:09 +02:00
|
|
|
RandomVector* const random_vector_;
|
|
|
|
|
SyncBuffer* const sync_buffer_;
|
2014-04-11 18:47:55 +00:00
|
|
|
bool first_expand_;
|
|
|
|
|
const int fs_hz_;
|
|
|
|
|
const size_t num_channels_;
|
|
|
|
|
int consecutive_expands_;
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
private:
|
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 kUnvoicedLpcOrder = 6;
|
|
|
|
|
static const size_t kNumCorrelationCandidates = 3;
|
|
|
|
|
static const size_t kDistortionLength = 20;
|
|
|
|
|
static const size_t kLpcAnalysisLength = 160;
|
|
|
|
|
static const size_t kMaxSampleRate = 48000;
|
2013-01-29 12:09:21 +00:00
|
|
|
static const int kNumLags = 3;
|
|
|
|
|
|
|
|
|
|
struct ChannelParameters {
|
2015-04-09 15:44:22 +02:00
|
|
|
ChannelParameters();
|
2013-01-29 12:09:21 +00:00
|
|
|
int16_t mute_factor;
|
|
|
|
|
int16_t ar_filter[kUnvoicedLpcOrder + 1];
|
|
|
|
|
int16_t ar_filter_state[kUnvoicedLpcOrder];
|
|
|
|
|
int16_t ar_gain;
|
|
|
|
|
int16_t ar_gain_scale;
|
|
|
|
|
int16_t voice_mix_factor; /* Q14 */
|
|
|
|
|
int16_t current_voice_mix_factor; /* Q14 */
|
2013-10-14 20:33:25 +00:00
|
|
|
AudioVector expand_vector0;
|
|
|
|
|
AudioVector expand_vector1;
|
2013-01-29 12:09:21 +00:00
|
|
|
bool onset;
|
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 mute_slope; /* Q20 */
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Calculate the auto-correlation of `input`, with length `input_length`
|
2013-01-29 12:09:21 +00:00
|
|
|
// samples. The correlation is calculated from a downsampled version of
|
2021-07-28 20:00:17 +02:00
|
|
|
// `input`, and is written to `output`.
|
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
|
|
|
void Correlation(const int16_t* input,
|
|
|
|
|
size_t input_length,
|
2016-05-02 01:50:30 -07:00
|
|
|
int16_t* output) const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
void UpdateLagIndex();
|
|
|
|
|
|
2015-08-18 14:58:09 +02:00
|
|
|
BackgroundNoise* const background_noise_;
|
|
|
|
|
StatisticsCalculator* const statistics_;
|
2014-02-17 11:37:16 +00:00
|
|
|
const size_t overlap_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 max_lag_;
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t expand_lags_[kNumLags];
|
|
|
|
|
int lag_index_direction_;
|
|
|
|
|
int current_lag_index_;
|
|
|
|
|
bool stop_muting_;
|
2015-08-18 14:58:09 +02:00
|
|
|
size_t expand_duration_samples_;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<ChannelParameters[]> channel_parameters_;
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
2014-01-14 10:18:45 +00:00
|
|
|
struct ExpandFactory {
|
|
|
|
|
ExpandFactory() {}
|
|
|
|
|
virtual ~ExpandFactory() {}
|
|
|
|
|
|
|
|
|
|
virtual Expand* Create(BackgroundNoise* background_noise,
|
|
|
|
|
SyncBuffer* sync_buffer,
|
|
|
|
|
RandomVector* random_vector,
|
2015-08-18 14:58:09 +02:00
|
|
|
StatisticsCalculator* statistics,
|
2014-01-14 10:18:45 +00:00
|
|
|
int fs,
|
|
|
|
|
size_t num_channels) const;
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_CODING_NETEQ_EXPAND_H_
|