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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.h"
|
|
|
|
|
|
2015-07-10 14:11:52 -07:00
|
|
|
#include <math.h>
|
2015-07-23 12:15:24 -07:00
|
|
|
#include <stdlib.h>
|
2015-07-10 14:11:52 -07:00
|
|
|
#include <string.h>
|
2015-06-15 13:02:24 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2015-07-10 14:11:52 -07:00
|
|
|
namespace webrtc {
|
2015-06-15 13:02:24 -07:00
|
|
|
|
2015-07-10 14:11:52 -07:00
|
|
|
namespace intelligibility {
|
2015-06-15 13:02:24 -07:00
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// Return |current| changed towards |target|, with the change being at most
|
|
|
|
|
// |limit|.
|
2015-07-10 14:11:52 -07:00
|
|
|
float UpdateFactor(float target, float current, float limit) {
|
2015-06-15 13:02:24 -07:00
|
|
|
float delta = fabsf(target - current);
|
2016-02-17 20:04:19 -08:00
|
|
|
float sign = copysign(1.f, target - current);
|
2015-06-15 13:02:24 -07:00
|
|
|
return current + sign * fminf(delta, limit);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
} // namespace
|
2015-06-15 13:02:24 -07:00
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
PowerEstimator::PowerEstimator(size_t num_freqs,
|
|
|
|
|
float decay)
|
|
|
|
|
: magnitude_(new float[num_freqs]()),
|
|
|
|
|
power_(new float[num_freqs]()),
|
2015-08-14 10:35:55 -07:00
|
|
|
num_freqs_(num_freqs),
|
2016-02-17 20:04:19 -08:00
|
|
|
decay_(decay) {
|
|
|
|
|
memset(magnitude_.get(), 0, sizeof(*magnitude_.get()) * num_freqs_);
|
|
|
|
|
memset(power_.get(), 0, sizeof(*power_.get()) * num_freqs_);
|
2015-06-15 13:02:24 -07:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
// Compute the magnitude from the beginning, with exponential decaying of the
|
2015-06-15 13:02:24 -07:00
|
|
|
// series data.
|
2016-02-17 20:04:19 -08:00
|
|
|
void PowerEstimator::Step(const std::complex<float>* data) {
|
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
|
|
|
for (size_t i = 0; i < num_freqs_; ++i) {
|
2016-02-17 20:04:19 -08:00
|
|
|
magnitude_[i] = decay_ * magnitude_[i] +
|
|
|
|
|
(1.f - decay_) * std::abs(data[i]);
|
2015-06-15 13:02:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
const float* PowerEstimator::Power() {
|
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
|
|
|
for (size_t i = 0; i < num_freqs_; ++i) {
|
2016-02-17 20:04:19 -08:00
|
|
|
power_[i] = magnitude_[i] * magnitude_[i];
|
2015-06-15 13:02:24 -07:00
|
|
|
}
|
2016-02-17 20:04:19 -08:00
|
|
|
return &power_[0];
|
2015-06-15 13:02:24 -07: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
|
|
|
GainApplier::GainApplier(size_t freqs, float change_limit)
|
2015-08-14 10:35:55 -07:00
|
|
|
: num_freqs_(freqs),
|
2015-06-15 13:02:24 -07:00
|
|
|
change_limit_(change_limit),
|
|
|
|
|
target_(new float[freqs]()),
|
|
|
|
|
current_(new float[freqs]()) {
|
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
|
|
|
for (size_t i = 0; i < freqs; ++i) {
|
2016-02-17 20:04:19 -08:00
|
|
|
target_[i] = 1.f;
|
|
|
|
|
current_[i] = 1.f;
|
2015-06-15 13:02:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 20:04:19 -08:00
|
|
|
void GainApplier::Apply(const std::complex<float>* in_block,
|
|
|
|
|
std::complex<float>* out_block) {
|
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
|
|
|
for (size_t i = 0; i < num_freqs_; ++i) {
|
2015-06-15 13:02:24 -07:00
|
|
|
float factor = sqrtf(fabsf(current_[i]));
|
|
|
|
|
if (!std::isnormal(factor)) {
|
2016-02-17 20:04:19 -08:00
|
|
|
factor = 1.f;
|
2015-06-15 13:02:24 -07:00
|
|
|
}
|
|
|
|
|
out_block[i] = factor * in_block[i];
|
|
|
|
|
current_[i] = UpdateFactor(target_[i], current_[i], change_limit_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace intelligibility
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|