Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: remoting/host/audio_volume_applier_unittest.cc

Issue 2840773004: [Chromoting] Add AudioVolumeApplier to reduce the complexity and the dependency of kChannels (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/audio_volume_applier.h"
6
7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace remoting {
11
12 namespace {
13
14 class FakeAudioVolumeApplier : public AudioVolumeApplier {
15 public:
16 FakeAudioVolumeApplier(int silence_threshold)
17 : AudioVolumeApplier(silence_threshold) {}
18 ~FakeAudioVolumeApplier() override = default;
19
20 void set_audio_level(float level) { level_ = level; }
21
22 protected:
23 float GetAudioLevel() override { return level_; }
24
25 private:
26 float level_ = 0;
27 };
28
29 } // namespace
30
31 TEST(AudioVolumeApplierTest, TwoChannels) {
32 int16_t samples[] =
33 {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10};
34 FakeAudioVolumeApplier applier(0);
35 applier.set_audio_level(0.5f);
36 applier.Initialize(9, 2);
37 // After applying the audio volume, the |samples| should still pass the
38 // AudioSilenceDetector, AudioVolumeApplier::Apply() returns true under this
39 // condition. Ditto.
40 ASSERT_TRUE(applier.Apply(samples, arraysize(samples) / 2));
41 }
42
43 TEST(AudioVolumeApplierTest, ThreeChannels) {
44 int16_t samples[] =
45 {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11};
46 FakeAudioVolumeApplier applier(0);
47 applier.set_audio_level(0.5f);
48 applier.Initialize(6, 3);
49 ASSERT_TRUE(applier.Apply(samples, arraysize(samples) / 3));
50 }
51
52 TEST(AudioVolumeApplierTest, SilentSamples) {
53 int16_t samples[] =
54 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
55 FakeAudioVolumeApplier applier(0);
56 applier.set_audio_level(0.5f);
57 applier.Initialize(9, 2);
58 ASSERT_FALSE(applier.Apply(samples, arraysize(samples) / 2));
59 }
60
61 TEST(AudioVolumeApplierTest, AudioLevel0) {
62 int16_t samples[] =
63 {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10};
64 FakeAudioVolumeApplier applier(0);
65 applier.set_audio_level(0);
66 applier.Initialize(9, 2);
67 ASSERT_FALSE(applier.Apply(samples, arraysize(samples) / 2));
68 }
69
70 TEST(AudioVolumeApplierTest, SilcentAfterApplying) {
71 int16_t samples[] =
72 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
73 FakeAudioVolumeApplier applier(0);
74 applier.set_audio_level(0.9f);
75 applier.Initialize(9, 2);
76 ASSERT_FALSE(applier.Apply(samples, arraysize(samples) / 2));
77 }
78
79 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698