tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rnn_unittest.cc (2695B)


      1 /*
      2 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "modules/audio_processing/agc2/rnn_vad/rnn.h"
     12 
     13 #include <array>
     14 
     15 #include "api/array_view.h"
     16 #include "modules/audio_processing/agc2/cpu_features.h"
     17 #include "modules/audio_processing/agc2/rnn_vad/common.h"
     18 #include "test/gtest.h"
     19 
     20 namespace webrtc {
     21 namespace rnn_vad {
     22 namespace {
     23 
     24 constexpr std::array<float, kFeatureVectorSize> kFeatures = {
     25    -1.00131f,   -0.627069f, -7.81097f,  7.86285f,    -2.87145f,  3.32365f,
     26    -0.653161f,  0.529839f,  -0.425307f, 0.25583f,    0.235094f,  0.230527f,
     27    -0.144687f,  0.182785f,  0.57102f,   0.125039f,   0.479482f,  -0.0255439f,
     28    -0.0073141f, -0.147346f, -0.217106f, -0.0846906f, -8.34943f,  3.09065f,
     29    1.42628f,    -0.85235f,  -0.220207f, -0.811163f,  2.09032f,   -2.01425f,
     30    -0.690268f,  -0.925327f, -0.541354f, 0.58455f,    -0.606726f, -0.0372358f,
     31    0.565991f,   0.435854f,  0.420812f,  0.162198f,   -2.13f,     10.0089f};
     32 
     33 void WarmUpRnnVad(RnnVad& rnn_vad) {
     34  for (int i = 0; i < 10; ++i) {
     35    rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
     36  }
     37 }
     38 
     39 // Checks that the speech probability is zero with silence.
     40 TEST(RnnVadTest, CheckZeroProbabilityWithSilence) {
     41  RnnVad rnn_vad(GetAvailableCpuFeatures());
     42  WarmUpRnnVad(rnn_vad);
     43  EXPECT_EQ(rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/true), 0.f);
     44 }
     45 
     46 // Checks that the same output is produced after reset given the same input
     47 // sequence.
     48 TEST(RnnVadTest, CheckRnnVadReset) {
     49  RnnVad rnn_vad(GetAvailableCpuFeatures());
     50  WarmUpRnnVad(rnn_vad);
     51  float pre = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
     52  rnn_vad.Reset();
     53  WarmUpRnnVad(rnn_vad);
     54  float post = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
     55  EXPECT_EQ(pre, post);
     56 }
     57 
     58 // Checks that the same output is produced after silence is observed given the
     59 // same input sequence.
     60 TEST(RnnVadTest, CheckRnnVadSilence) {
     61  RnnVad rnn_vad(GetAvailableCpuFeatures());
     62  WarmUpRnnVad(rnn_vad);
     63  float pre = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
     64  rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/true);
     65  WarmUpRnnVad(rnn_vad);
     66  float post = rnn_vad.ComputeVadProbability(kFeatures, /*is_silence=*/false);
     67  EXPECT_EQ(pre, post);
     68 }
     69 
     70 }  // namespace
     71 }  // namespace rnn_vad
     72 }  // namespace webrtc