2015-06-15 13:02:24 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_
|
|
|
|
|
|
|
|
|
|
#include <complex>
|
2016-02-22 15:57:38 -08:00
|
|
|
#include <vector>
|
2015-06-15 13:02:24 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
namespace intelligibility {
|
|
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
// Internal helper for computing the power of a stream of arrays.
|
|
|
|
|
// The result is an array of power per position: the i-th power is the power of
|
|
|
|
|
// the stream of data on the i-th positions in the input arrays.
|
2016-02-22 15:57:38 -08:00
|
|
|
template <typename T>
|
2016-02-17 20:04:19 -08:00
|
|
|
class PowerEstimator {
|
2015-06-15 13:02:24 -07:00
|
|
|
public:
|
2016-02-17 20:04:19 -08:00
|
|
|
// Construct an instance for the given input array length (|freqs|), with the
|
|
|
|
|
// appropriate parameters. |decay| is the forgetting factor.
|
|
|
|
|
PowerEstimator(size_t freqs, float decay);
|
2015-06-15 13:02:24 -07:00
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
// Add a new data point to the series.
|
2016-02-22 15:57:38 -08:00
|
|
|
void Step(const T* data);
|
2015-06-15 13:02:24 -07:00
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
// The current power array.
|
2016-02-22 15:57:38 -08:00
|
|
|
const std::vector<float>& power() { return power_; };
|
2016-02-17 20:04:19 -08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// The current power array.
|
2016-02-22 15:57:38 -08:00
|
|
|
std::vector<float> power_;
|
2015-06-15 13:02:24 -07:00
|
|
|
|
|
|
|
|
const float decay_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
// Helper class for smoothing gain changes. On each application step, the
|
2015-06-15 13:02:24 -07:00
|
|
|
// currently used gains are changed towards a set of settable target gains,
|
2016-02-22 15:57:38 -08:00
|
|
|
// constrained by a limit on the relative changes.
|
2015-06-15 13:02:24 -07:00
|
|
|
class GainApplier {
|
|
|
|
|
public:
|
2016-02-22 15:57:38 -08:00
|
|
|
GainApplier(size_t freqs, float relative_change_limit);
|
2015-06-15 13:02:24 -07:00
|
|
|
|
2016-09-06 11:25:40 -07:00
|
|
|
~GainApplier();
|
|
|
|
|
|
2015-06-15 13:02:24 -07:00
|
|
|
// Copy |in_block| to |out_block|, multiplied by the current set of gains,
|
|
|
|
|
// and step the current set of gains towards the target set.
|
|
|
|
|
void Apply(const std::complex<float>* in_block,
|
|
|
|
|
std::complex<float>* out_block);
|
|
|
|
|
|
|
|
|
|
// Return the current target gain set. Modify this array to set the targets.
|
2016-02-26 17:17:38 -08:00
|
|
|
float* target() { return target_.data(); }
|
2015-06-15 13:02:24 -07: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
|
|
|
const size_t num_freqs_;
|
2016-02-22 15:57:38 -08:00
|
|
|
const float relative_change_limit_;
|
2016-02-26 17:17:38 -08:00
|
|
|
std::vector<float> target_;
|
|
|
|
|
std::vector<float> current_;
|
2015-06-15 13:02:24 -07:00
|
|
|
};
|
|
|
|
|
|
2016-09-20 14:51:56 -07:00
|
|
|
// Helper class to delay a signal by an integer number of samples.
|
|
|
|
|
class DelayBuffer {
|
|
|
|
|
public:
|
|
|
|
|
DelayBuffer(size_t delay, size_t num_channels);
|
|
|
|
|
|
|
|
|
|
~DelayBuffer();
|
|
|
|
|
|
|
|
|
|
void Delay(float* const* data, size_t length);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::vector<std::vector<float>> buffer_;
|
|
|
|
|
size_t read_index_;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-15 13:02:24 -07:00
|
|
|
} // namespace intelligibility
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_
|