Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.8 KiB
C
Raw Normal View History

/*
* Copyright (c) 2018 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 MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_PITCH_SEARCH_H_
#define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_PITCH_SEARCH_H_
#include <memory>
#include <vector>
#include "api/array_view.h"
#include "modules/audio_processing/agc2/cpu_features.h"
Reland "RNN VAD: Replace Ooura with PFFFT for the pitch auto correlation." This reverts commit d38ce9f82402a995289b87e044125847d12eb658. Reason for revert: land this first, then fix downstream Original change's description: > Revert "RNN VAD: Replace Ooura with PFFFT for the pitch auto correlation." > > This reverts commit 8fcd6537f242ffd74154a62dad410e573e2efc4b. > > Reason for revert: broke internal projects. > > Original change's description: > > RNN VAD: Replace Ooura with PFFFT for the pitch auto correlation. > > > > Bug: webrtc:9577, webrtc:10480 > > Change-Id: I6d58866d48b8eaaa4102551b88d4f55133d1915c > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130482 > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27387} > > TBR=gustaf@webrtc.org,alessiob@webrtc.org > > Change-Id: Ia05057326ebc277f334b13db0bfec9d4442903c2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:9577, webrtc:10480 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130369 > Reviewed-by: Qingsi Wang <qingsi@webrtc.org> > Commit-Queue: Qingsi Wang <qingsi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27405} TBR=gustaf@webrtc.org,alessiob@webrtc.org,qingsi@webrtc.org Change-Id: I345f00d798fb67d0f02bf1e89319dac7f0287485 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:9577, webrtc:10480 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130516 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27407}
2019-04-02 06:58:45 +00:00
#include "modules/audio_processing/agc2/rnn_vad/auto_correlation.h"
#include "modules/audio_processing/agc2/rnn_vad/common.h"
#include "modules/audio_processing/agc2/rnn_vad/pitch_search_internal.h"
Reland "RNN VAD: pitch search optimizations (part 1)" This reverts commit 1b6b958a4aa574b7852fe62efe5d4f96ce085d8b. Reason for revert: Bug fix Original change's description: > Revert "RNN VAD: pitch search optimizations (part 1)" > > This reverts commit 9da3e177fd5c2236cc15fea0ee8933e1dd0d8f6d. > > Reason for revert: bug in ComputePitchPeriod48kHz() > > Original change's description: > > RNN VAD: pitch search optimizations (part 1) > > > > TL;DR this CL improves efficiency and includes several code > > readability improvements mainly triggered by the comments to > > patch set #10. > > > > Highlights: > > - Split `FindBestPitchPeriods()` into 12 and 24 kHz versions > > to hard-code the input size and simplify the 24 kHz version > > - Loop in `ComputePitchPeriod48kHz()` (new name for > > `RefinePitchPeriod48kHz()`) removed since the lags for which > > we need to compute the auto correlation are a few > > - `ComputePitchGainThreshold()` was only used in unit tests; it's been > > moved into the anon ns and the test removed > > > > This CL makes `ComputePitchPeriod48kHz()` is about 10% faster (measured > > with https://webrtc-review.googlesource.com/c/src/+/191320/4/modules/audio_processing/agc2/rnn_vad/pitch_search_internal_unittest.cc). > > The realtime factor has improved by about +14%. > > > > Benchmarked as follows: > > ``` > > out/release/modules_unittests \ > > --gtest_filter=*RnnVadTest.DISABLED_RnnVadPerformance* \ > > --gtest_also_run_disabled_tests --logs > > ``` > > > > Results: > > > > | baseline | this CL > > ------+----------------------+------------------------ > > run 1 | 24.0231 +/- 0.591016 | 23.568 +/- 0.990788 > > | 370.06x | 377.207x > > ------+----------------------+------------------------ > > run 2 | 24.0485 +/- 0.957498 | 23.3714 +/- 0.857523 > > | 369.67x | 380.379x > > ------+----------------------+------------------------ > > run 2 | 25.4091 +/- 2.6123 | 23.709 +/- 1.04477 > > | 349.875x | 374.963x > > > > Bug: webrtc:10480 > > Change-Id: I9a3e9164b2442114b928de506c92a547c273882f > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191320 > > Reviewed-by: Per Åhgren <peah@webrtc.org> > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#32568} > > TBR=alessiob@webrtc.org,peah@webrtc.org > > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10480 > Change-Id: I2a91f4f29566f872a7dfa220b31c6c625ed075db > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192660 > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#32581} TBR=alessiob@webrtc.org,peah@webrtc.org # Not skipping CQ checks because this is a reland. Bug: webrtc:10480 Change-Id: I66e3e8d73ebc04a437c01a0396cd5613c42a8cf5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192780 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32585}
2020-11-11 12:06:09 +01:00
#include "rtc_base/gtest_prod_util.h"
namespace webrtc {
namespace rnn_vad {
// Pitch estimator.
class PitchEstimator {
public:
explicit PitchEstimator(const AvailableCpuFeatures& cpu_features);
PitchEstimator(const PitchEstimator&) = delete;
PitchEstimator& operator=(const PitchEstimator&) = delete;
~PitchEstimator();
Reland "RNN VAD: pitch search optimizations (part 1)" This reverts commit 1b6b958a4aa574b7852fe62efe5d4f96ce085d8b. Reason for revert: Bug fix Original change's description: > Revert "RNN VAD: pitch search optimizations (part 1)" > > This reverts commit 9da3e177fd5c2236cc15fea0ee8933e1dd0d8f6d. > > Reason for revert: bug in ComputePitchPeriod48kHz() > > Original change's description: > > RNN VAD: pitch search optimizations (part 1) > > > > TL;DR this CL improves efficiency and includes several code > > readability improvements mainly triggered by the comments to > > patch set #10. > > > > Highlights: > > - Split `FindBestPitchPeriods()` into 12 and 24 kHz versions > > to hard-code the input size and simplify the 24 kHz version > > - Loop in `ComputePitchPeriod48kHz()` (new name for > > `RefinePitchPeriod48kHz()`) removed since the lags for which > > we need to compute the auto correlation are a few > > - `ComputePitchGainThreshold()` was only used in unit tests; it's been > > moved into the anon ns and the test removed > > > > This CL makes `ComputePitchPeriod48kHz()` is about 10% faster (measured > > with https://webrtc-review.googlesource.com/c/src/+/191320/4/modules/audio_processing/agc2/rnn_vad/pitch_search_internal_unittest.cc). > > The realtime factor has improved by about +14%. > > > > Benchmarked as follows: > > ``` > > out/release/modules_unittests \ > > --gtest_filter=*RnnVadTest.DISABLED_RnnVadPerformance* \ > > --gtest_also_run_disabled_tests --logs > > ``` > > > > Results: > > > > | baseline | this CL > > ------+----------------------+------------------------ > > run 1 | 24.0231 +/- 0.591016 | 23.568 +/- 0.990788 > > | 370.06x | 377.207x > > ------+----------------------+------------------------ > > run 2 | 24.0485 +/- 0.957498 | 23.3714 +/- 0.857523 > > | 369.67x | 380.379x > > ------+----------------------+------------------------ > > run 2 | 25.4091 +/- 2.6123 | 23.709 +/- 1.04477 > > | 349.875x | 374.963x > > > > Bug: webrtc:10480 > > Change-Id: I9a3e9164b2442114b928de506c92a547c273882f > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191320 > > Reviewed-by: Per Åhgren <peah@webrtc.org> > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#32568} > > TBR=alessiob@webrtc.org,peah@webrtc.org > > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10480 > Change-Id: I2a91f4f29566f872a7dfa220b31c6c625ed075db > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192660 > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#32581} TBR=alessiob@webrtc.org,peah@webrtc.org # Not skipping CQ checks because this is a reland. Bug: webrtc:10480 Change-Id: I66e3e8d73ebc04a437c01a0396cd5613c42a8cf5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192780 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32585}
2020-11-11 12:06:09 +01:00
// Returns the estimated pitch period at 48 kHz.
int Estimate(rtc::ArrayView<const float, kBufSize24kHz> pitch_buffer);
private:
Reland "RNN VAD: pitch search optimizations (part 1)" This reverts commit 1b6b958a4aa574b7852fe62efe5d4f96ce085d8b. Reason for revert: Bug fix Original change's description: > Revert "RNN VAD: pitch search optimizations (part 1)" > > This reverts commit 9da3e177fd5c2236cc15fea0ee8933e1dd0d8f6d. > > Reason for revert: bug in ComputePitchPeriod48kHz() > > Original change's description: > > RNN VAD: pitch search optimizations (part 1) > > > > TL;DR this CL improves efficiency and includes several code > > readability improvements mainly triggered by the comments to > > patch set #10. > > > > Highlights: > > - Split `FindBestPitchPeriods()` into 12 and 24 kHz versions > > to hard-code the input size and simplify the 24 kHz version > > - Loop in `ComputePitchPeriod48kHz()` (new name for > > `RefinePitchPeriod48kHz()`) removed since the lags for which > > we need to compute the auto correlation are a few > > - `ComputePitchGainThreshold()` was only used in unit tests; it's been > > moved into the anon ns and the test removed > > > > This CL makes `ComputePitchPeriod48kHz()` is about 10% faster (measured > > with https://webrtc-review.googlesource.com/c/src/+/191320/4/modules/audio_processing/agc2/rnn_vad/pitch_search_internal_unittest.cc). > > The realtime factor has improved by about +14%. > > > > Benchmarked as follows: > > ``` > > out/release/modules_unittests \ > > --gtest_filter=*RnnVadTest.DISABLED_RnnVadPerformance* \ > > --gtest_also_run_disabled_tests --logs > > ``` > > > > Results: > > > > | baseline | this CL > > ------+----------------------+------------------------ > > run 1 | 24.0231 +/- 0.591016 | 23.568 +/- 0.990788 > > | 370.06x | 377.207x > > ------+----------------------+------------------------ > > run 2 | 24.0485 +/- 0.957498 | 23.3714 +/- 0.857523 > > | 369.67x | 380.379x > > ------+----------------------+------------------------ > > run 2 | 25.4091 +/- 2.6123 | 23.709 +/- 1.04477 > > | 349.875x | 374.963x > > > > Bug: webrtc:10480 > > Change-Id: I9a3e9164b2442114b928de506c92a547c273882f > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191320 > > Reviewed-by: Per Åhgren <peah@webrtc.org> > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#32568} > > TBR=alessiob@webrtc.org,peah@webrtc.org > > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10480 > Change-Id: I2a91f4f29566f872a7dfa220b31c6c625ed075db > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192660 > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#32581} TBR=alessiob@webrtc.org,peah@webrtc.org # Not skipping CQ checks because this is a reland. Bug: webrtc:10480 Change-Id: I66e3e8d73ebc04a437c01a0396cd5613c42a8cf5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192780 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32585}
2020-11-11 12:06:09 +01:00
FRIEND_TEST_ALL_PREFIXES(RnnVadTest, PitchSearchWithinTolerance);
float GetLastPitchStrengthForTesting() const {
return last_pitch_48kHz_.strength;
}
const AvailableCpuFeatures cpu_features_;
Reland "RNN VAD: pitch search optimizations (part 1)" This reverts commit 1b6b958a4aa574b7852fe62efe5d4f96ce085d8b. Reason for revert: Bug fix Original change's description: > Revert "RNN VAD: pitch search optimizations (part 1)" > > This reverts commit 9da3e177fd5c2236cc15fea0ee8933e1dd0d8f6d. > > Reason for revert: bug in ComputePitchPeriod48kHz() > > Original change's description: > > RNN VAD: pitch search optimizations (part 1) > > > > TL;DR this CL improves efficiency and includes several code > > readability improvements mainly triggered by the comments to > > patch set #10. > > > > Highlights: > > - Split `FindBestPitchPeriods()` into 12 and 24 kHz versions > > to hard-code the input size and simplify the 24 kHz version > > - Loop in `ComputePitchPeriod48kHz()` (new name for > > `RefinePitchPeriod48kHz()`) removed since the lags for which > > we need to compute the auto correlation are a few > > - `ComputePitchGainThreshold()` was only used in unit tests; it's been > > moved into the anon ns and the test removed > > > > This CL makes `ComputePitchPeriod48kHz()` is about 10% faster (measured > > with https://webrtc-review.googlesource.com/c/src/+/191320/4/modules/audio_processing/agc2/rnn_vad/pitch_search_internal_unittest.cc). > > The realtime factor has improved by about +14%. > > > > Benchmarked as follows: > > ``` > > out/release/modules_unittests \ > > --gtest_filter=*RnnVadTest.DISABLED_RnnVadPerformance* \ > > --gtest_also_run_disabled_tests --logs > > ``` > > > > Results: > > > > | baseline | this CL > > ------+----------------------+------------------------ > > run 1 | 24.0231 +/- 0.591016 | 23.568 +/- 0.990788 > > | 370.06x | 377.207x > > ------+----------------------+------------------------ > > run 2 | 24.0485 +/- 0.957498 | 23.3714 +/- 0.857523 > > | 369.67x | 380.379x > > ------+----------------------+------------------------ > > run 2 | 25.4091 +/- 2.6123 | 23.709 +/- 1.04477 > > | 349.875x | 374.963x > > > > Bug: webrtc:10480 > > Change-Id: I9a3e9164b2442114b928de506c92a547c273882f > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191320 > > Reviewed-by: Per Åhgren <peah@webrtc.org> > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#32568} > > TBR=alessiob@webrtc.org,peah@webrtc.org > > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10480 > Change-Id: I2a91f4f29566f872a7dfa220b31c6c625ed075db > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192660 > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#32581} TBR=alessiob@webrtc.org,peah@webrtc.org # Not skipping CQ checks because this is a reland. Bug: webrtc:10480 Change-Id: I66e3e8d73ebc04a437c01a0396cd5613c42a8cf5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192780 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32585}
2020-11-11 12:06:09 +01:00
PitchInfo last_pitch_48kHz_{};
Reland "RNN VAD: Replace Ooura with PFFFT for the pitch auto correlation." This reverts commit d38ce9f82402a995289b87e044125847d12eb658. Reason for revert: land this first, then fix downstream Original change's description: > Revert "RNN VAD: Replace Ooura with PFFFT for the pitch auto correlation." > > This reverts commit 8fcd6537f242ffd74154a62dad410e573e2efc4b. > > Reason for revert: broke internal projects. > > Original change's description: > > RNN VAD: Replace Ooura with PFFFT for the pitch auto correlation. > > > > Bug: webrtc:9577, webrtc:10480 > > Change-Id: I6d58866d48b8eaaa4102551b88d4f55133d1915c > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130482 > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27387} > > TBR=gustaf@webrtc.org,alessiob@webrtc.org > > Change-Id: Ia05057326ebc277f334b13db0bfec9d4442903c2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:9577, webrtc:10480 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130369 > Reviewed-by: Qingsi Wang <qingsi@webrtc.org> > Commit-Queue: Qingsi Wang <qingsi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27405} TBR=gustaf@webrtc.org,alessiob@webrtc.org,qingsi@webrtc.org Change-Id: I345f00d798fb67d0f02bf1e89319dac7f0287485 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:9577, webrtc:10480 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130516 Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27407}
2019-04-02 06:58:45 +00:00
AutoCorrelationCalculator auto_corr_calculator_;
Reland "RNN VAD: pitch search optimizations (part 2)" This reverts commit e6a731fceae9503f6237d3ea287323aeac732ea6. Reason for revert: bug in parent CL fixed Original change's description: > Revert "RNN VAD: pitch search optimizations (part 2)" > > This reverts commit 2f7d1c62e21e2f3786c0803c973d71b414726d8d. > > Reason for revert: bug in ancestor CL https://webrtc-review.googlesource.com/c/src/+/191320 > > Original change's description: > > RNN VAD: pitch search optimizations (part 2) > > > > This CL brings a large improvement to the VAD by precomputing the > > energy for the sliding frame `y` in the pitch buffer instead of > > computing them twice in two different places. The realtime factor > > has improved by about +16x. > > > > There is room for additional improvement (TODOs added), but that will > > be done in a follow up CL since the change won't be bit-exact and > > careful testing is needed. > > > > Benchmarked as follows: > > ``` > > out/release/modules_unittests \ > > --gtest_filter=*RnnVadTest.DISABLED_RnnVadPerformance* \ > > --gtest_also_run_disabled_tests --logs > > ``` > > > > Results: > > > > | baseline | this CL > > ------+----------------------+------------------------ > > run 1 | 23.568 +/- 0.990788 | 22.8319 +/- 1.46554 > > | 377.207x | 389.367x > > ------+----------------------+------------------------ > > run 2 | 23.3714 +/- 0.857523 | 22.4286 +/- 0.726449 > > | 380.379x | 396.369x > > ------+----------------------+------------------------ > > run 2 | 23.709 +/- 1.04477 | 22.5688 +/- 0.831341 > > | 374.963x | 393.906x > > > > Bug: webrtc:10480 > > Change-Id: I599a4dda2bde16dc6c2f42cf89e96afbd4630311 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191484 > > Reviewed-by: Per Åhgren <peah@webrtc.org> > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#32571} > > TBR=alessiob@webrtc.org,peah@webrtc.org > > Change-Id: I53e478d8d58912c7a5fae4ad8a8d1342a9a48091 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10480 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192620 > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#32580} TBR=alessiob@webrtc.org,peah@webrtc.org # Not skipping CQ checks because this is a reland. Bug: webrtc:10480 Change-Id: I0d6c89c64587bb6c38e69b968df12a5eb499ac6f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192782 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32586}
2020-11-11 12:23:07 +01:00
std::vector<float> y_energy_24kHz_;
std::vector<float> pitch_buffer_12kHz_;
std::vector<float> auto_correlation_12kHz_;
};
} // namespace rnn_vad
} // namespace webrtc
#endif // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_PITCH_SEARCH_H_