1 /*
2  *  Copyright (c) 2014 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 "webrtc/common_audio/window_generator.h"
12 
13 #include <cstring>
14 
15 #include "testing/gtest/include/gtest/gtest.h"
16 
17 namespace webrtc {
18 
TEST(WindowGeneratorTest,KaiserBesselDerived)19 TEST(WindowGeneratorTest, KaiserBesselDerived) {
20   float window[7];
21 
22   memset(window, 0, sizeof(window));
23 
24   WindowGenerator::KaiserBesselDerived(0.397856f, 2, window);
25   ASSERT_NEAR(window[0], 0.707106f, 1e-6f);
26   ASSERT_NEAR(window[1], 0.707106f, 1e-6f);
27   ASSERT_NEAR(window[2], 0.0f, 1e-6f);
28   ASSERT_NEAR(window[3], 0.0f, 1e-6f);
29   ASSERT_NEAR(window[4], 0.0f, 1e-6f);
30   ASSERT_NEAR(window[5], 0.0f, 1e-6f);
31   ASSERT_NEAR(window[6], 0.0f, 1e-6f);
32 
33   WindowGenerator::KaiserBesselDerived(0.397856f, 3, window);
34   ASSERT_NEAR(window[0], 0.598066f, 1e-6f);
35   ASSERT_NEAR(window[1], 0.922358f, 1e-6f);
36   ASSERT_NEAR(window[2], 0.598066f, 1e-6f);
37   ASSERT_NEAR(window[3], 0.0f, 1e-6f);
38   ASSERT_NEAR(window[4], 0.0f, 1e-6f);
39   ASSERT_NEAR(window[5], 0.0f, 1e-6f);
40   ASSERT_NEAR(window[6], 0.0f, 1e-6f);
41 
42   WindowGenerator::KaiserBesselDerived(0.397856f, 6, window);
43   ASSERT_NEAR(window[0], 0.458495038865344f, 1e-6f);
44   ASSERT_NEAR(window[1], 0.707106781186548f, 1e-6f);
45   ASSERT_NEAR(window[2], 0.888696967101760f, 1e-6f);
46   ASSERT_NEAR(window[3], 0.888696967101760f, 1e-6f);
47   ASSERT_NEAR(window[4], 0.707106781186548f, 1e-6f);
48   ASSERT_NEAR(window[5], 0.458495038865344f, 1e-6f);
49   ASSERT_NEAR(window[6], 0.0f, 1e-6f);
50 }
51 
TEST(WindowGeneratorTest,Hanning)52 TEST(WindowGeneratorTest, Hanning) {
53   float window[7];
54 
55   memset(window, 0, sizeof(window));
56 
57   window[0] = -1.0f;
58   window[1] = -1.0f;
59   WindowGenerator::Hanning(2, window);
60   ASSERT_NEAR(window[0], 0.0f, 1e-6f);
61   ASSERT_NEAR(window[1], 0.0f, 1e-6f);
62   ASSERT_NEAR(window[2], 0.0f, 1e-6f);
63   ASSERT_NEAR(window[3], 0.0f, 1e-6f);
64   ASSERT_NEAR(window[4], 0.0f, 1e-6f);
65   ASSERT_NEAR(window[5], 0.0f, 1e-6f);
66   ASSERT_NEAR(window[6], 0.0f, 1e-6f);
67 
68   window[0] = -1.0f;
69   window[2] = -1.0f;
70   WindowGenerator::Hanning(3, window);
71   ASSERT_NEAR(window[0], 0.0f, 1e-6f);
72   ASSERT_NEAR(window[1], 1.0f, 1e-6f);
73   ASSERT_NEAR(window[2], 0.0f, 1e-6f);
74   ASSERT_NEAR(window[3], 0.0f, 1e-6f);
75   ASSERT_NEAR(window[4], 0.0f, 1e-6f);
76   ASSERT_NEAR(window[5], 0.0f, 1e-6f);
77   ASSERT_NEAR(window[6], 0.0f, 1e-6f);
78 
79   window[0] = -1.0f;
80   window[5] = -1.0f;
81   WindowGenerator::Hanning(6, window);
82   ASSERT_NEAR(window[0], 0.0f, 1e-6f);
83   ASSERT_NEAR(window[1], 0.345491f, 1e-6f);
84   ASSERT_NEAR(window[2], 0.904508f, 1e-6f);
85   ASSERT_NEAR(window[3], 0.904508f, 1e-6f);
86   ASSERT_NEAR(window[4], 0.345491f, 1e-6f);
87   ASSERT_NEAR(window[5], 0.0f, 1e-6f);
88   ASSERT_NEAR(window[6], 0.0f, 1e-6f);
89 }
90 
91 }  // namespace webrtc
92 
93