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_DSP_HELPER_H_
|
|
|
|
|
#define MODULES_AUDIO_CODING_NETEQ_DSP_HELPER_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/audio_multi_vector.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/audio_coding/neteq/audio_vector.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// This class contains various signal processing functions, all implemented as
|
|
|
|
|
// static methods.
|
|
|
|
|
class DspHelper {
|
|
|
|
|
public:
|
|
|
|
|
// Filter coefficients used when downsampling from the indicated sample rates
|
|
|
|
|
// (8, 16, 32, 48 kHz) to 4 kHz. Coefficients are in Q12.
|
|
|
|
|
static const int16_t kDownsample8kHzTbl[3];
|
|
|
|
|
static const int16_t kDownsample16kHzTbl[5];
|
|
|
|
|
static const int16_t kDownsample32kHzTbl[7];
|
|
|
|
|
static const int16_t kDownsample48kHzTbl[7];
|
|
|
|
|
|
|
|
|
|
// Constants used to mute and unmute over 5 samples. The coefficients are
|
|
|
|
|
// in Q15.
|
|
|
|
|
static const int kMuteFactorStart8kHz = 27307;
|
|
|
|
|
static const int kMuteFactorIncrement8kHz = -5461;
|
|
|
|
|
static const int kUnmuteFactorStart8kHz = 5461;
|
|
|
|
|
static const int kUnmuteFactorIncrement8kHz = 5461;
|
|
|
|
|
static const int kMuteFactorStart16kHz = 29789;
|
|
|
|
|
static const int kMuteFactorIncrement16kHz = -2979;
|
|
|
|
|
static const int kUnmuteFactorStart16kHz = 2979;
|
|
|
|
|
static const int kUnmuteFactorIncrement16kHz = 2979;
|
|
|
|
|
static const int kMuteFactorStart32kHz = 31208;
|
|
|
|
|
static const int kMuteFactorIncrement32kHz = -1560;
|
|
|
|
|
static const int kUnmuteFactorStart32kHz = 1560;
|
|
|
|
|
static const int kUnmuteFactorIncrement32kHz = 1560;
|
|
|
|
|
static const int kMuteFactorStart48kHz = 31711;
|
|
|
|
|
static const int kMuteFactorIncrement48kHz = -1057;
|
|
|
|
|
static const int kUnmuteFactorStart48kHz = 1057;
|
|
|
|
|
static const int kUnmuteFactorIncrement48kHz = 1057;
|
|
|
|
|
|
|
|
|
|
// Multiplies the signal with a gradually changing factor.
|
|
|
|
|
// The first sample is multiplied with |factor| (in Q14). For each sample,
|
|
|
|
|
// |factor| is increased (additive) by the |increment| (in Q20), which can
|
|
|
|
|
// be negative. Returns the scale factor after the last increment.
|
|
|
|
|
static int RampSignal(const int16_t* input,
|
|
|
|
|
size_t length,
|
|
|
|
|
int factor,
|
|
|
|
|
int increment,
|
|
|
|
|
int16_t* output);
|
|
|
|
|
|
|
|
|
|
// Same as above, but with the samples of |signal| being modified in-place.
|
|
|
|
|
static int RampSignal(int16_t* signal,
|
|
|
|
|
size_t length,
|
|
|
|
|
int factor,
|
|
|
|
|
int increment);
|
|
|
|
|
|
|
|
|
|
// Same as above, but processes |length| samples from |signal|, starting at
|
|
|
|
|
// |start_index|.
|
2016-05-10 19:55:56 +02:00
|
|
|
static int RampSignal(AudioVector* signal,
|
|
|
|
|
size_t start_index,
|
|
|
|
|
size_t length,
|
|
|
|
|
int factor,
|
|
|
|
|
int increment);
|
|
|
|
|
|
|
|
|
|
// Same as above, but for an AudioMultiVector.
|
2013-09-30 20:38:44 +00:00
|
|
|
static int RampSignal(AudioMultiVector* signal,
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t start_index,
|
|
|
|
|
size_t length,
|
|
|
|
|
int factor,
|
|
|
|
|
int increment);
|
|
|
|
|
|
|
|
|
|
// Peak detection with parabolic fit. Looks for |num_peaks| maxima in |data|,
|
|
|
|
|
// having length |data_length| and sample rate multiplier |fs_mult|. The peak
|
|
|
|
|
// locations and values are written to the arrays |peak_index| and
|
|
|
|
|
// |peak_value|, respectively. Both arrays must hold at least |num_peaks|
|
|
|
|
|
// elements.
|
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 void PeakDetection(int16_t* data,
|
|
|
|
|
size_t data_length,
|
|
|
|
|
size_t num_peaks,
|
|
|
|
|
int fs_mult,
|
|
|
|
|
size_t* peak_index,
|
|
|
|
|
int16_t* peak_value);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Estimates the height and location of a maximum. The three values in the
|
|
|
|
|
// array |signal_points| are used as basis for a parabolic fit, which is then
|
|
|
|
|
// used to find the maximum in an interpolated signal. The |signal_points| are
|
|
|
|
|
// assumed to be from a 4 kHz signal, while the maximum, written to
|
|
|
|
|
// |peak_index| and |peak_value| is given in the full sample rate, as
|
|
|
|
|
// indicated by the sample rate multiplier |fs_mult|.
|
|
|
|
|
static void ParabolicFit(int16_t* signal_points,
|
|
|
|
|
int fs_mult,
|
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* peak_index,
|
|
|
|
|
int16_t* peak_value);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Calculates the sum-abs-diff for |signal| when compared to a displaced
|
|
|
|
|
// version of itself. Returns the displacement lag that results in the minimum
|
|
|
|
|
// distortion. The resulting distortion is written to |distortion_value|.
|
|
|
|
|
// The values of |min_lag| and |max_lag| are boundaries for the search.
|
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 size_t MinDistortion(const int16_t* signal,
|
|
|
|
|
size_t min_lag,
|
|
|
|
|
size_t max_lag,
|
|
|
|
|
size_t length,
|
|
|
|
|
int32_t* distortion_value);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Mixes |length| samples from |input1| and |input2| together and writes the
|
|
|
|
|
// result to |output|. The gain for |input1| starts at |mix_factor| (Q14) and
|
|
|
|
|
// is decreased by |factor_decrement| (Q14) for each sample. The gain for
|
|
|
|
|
// |input2| is the complement 16384 - mix_factor.
|
|
|
|
|
static void CrossFade(const int16_t* input1,
|
|
|
|
|
const int16_t* input2,
|
2013-09-20 16:25:28 +00:00
|
|
|
size_t length,
|
|
|
|
|
int16_t* mix_factor,
|
2013-01-29 12:09:21 +00:00
|
|
|
int16_t factor_decrement,
|
|
|
|
|
int16_t* output);
|
|
|
|
|
|
|
|
|
|
// Scales |input| with an increasing gain. Applies |factor| (Q14) to the first
|
|
|
|
|
// sample and increases the gain by |increment| (Q20) for each sample. The
|
|
|
|
|
// result is written to |output|. |length| samples are processed.
|
2013-09-20 16:25:28 +00:00
|
|
|
static void UnmuteSignal(const int16_t* input,
|
|
|
|
|
size_t length,
|
|
|
|
|
int16_t* factor,
|
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 increment,
|
|
|
|
|
int16_t* output);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Starts at unity gain and gradually fades out |signal|. For each sample,
|
|
|
|
|
// the gain is reduced by |mute_slope| (Q14). |length| samples are processed.
|
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
|
|
|
static void MuteSignal(int16_t* signal, int mute_slope, size_t length);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Downsamples |input| from |sample_rate_hz| to 4 kHz sample rate. The input
|
|
|
|
|
// has |input_length| samples, and the method will write |output_length|
|
|
|
|
|
// samples to |output|. Compensates for the phase delay of the downsampling
|
|
|
|
|
// filters if |compensate_delay| is true. Returns -1 if the input is too short
|
|
|
|
|
// to produce |output_length| samples, otherwise 0.
|
2013-09-20 16:25:28 +00:00
|
|
|
static int DownsampleTo4kHz(const 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
|
|
|
size_t output_length,
|
|
|
|
|
int input_rate_hz,
|
2013-01-29 12:09:21 +00:00
|
|
|
bool compensate_delay,
|
|
|
|
|
int16_t* output);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Table of constants used in method DspHelper::ParabolicFit().
|
|
|
|
|
static const int16_t kParabolaCoefficients[17][3];
|
|
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(DspHelper);
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_CODING_NETEQ_DSP_HELPER_H_
|