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

Side by Side Diff: media/audio/simple_sources_unittest.cc

Issue 1538463002: Revert of Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « media/audio/simple_sources.cc ('k') | media/audio/sounds/audio_stream_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 static const uint32 samples = 1024; 21 static const uint32 samples = 1024;
22 static const uint32 bytes_per_sample = 2; 22 static const uint32 bytes_per_sample = 2;
23 static const int freq = 200; 23 static const int freq = 200;
24 24
25 AudioParameters params( 25 AudioParameters params(
26 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 26 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
27 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 8, samples); 27 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 8, samples);
28 28
29 SineWaveAudioSource source(1, freq, params.sample_rate()); 29 SineWaveAudioSource source(1, freq, params.sample_rate());
30 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(params); 30 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(params);
31 source.OnMoreData(audio_bus.get(), 0, 0); 31 source.OnMoreData(audio_bus.get(), 0);
32 EXPECT_EQ(1, source.callbacks()); 32 EXPECT_EQ(1, source.callbacks());
33 EXPECT_EQ(0, source.errors()); 33 EXPECT_EQ(0, source.errors());
34 34
35 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2); 35 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2);
36 36
37 // Spot test positive incursion of sine wave. 37 // Spot test positive incursion of sine wave.
38 EXPECT_NEAR(0, audio_bus->channel(0)[0], 38 EXPECT_NEAR(0, audio_bus->channel(0)[0],
39 std::numeric_limits<float>::epsilon()); 39 std::numeric_limits<float>::epsilon());
40 EXPECT_FLOAT_EQ(0.15643446f, audio_bus->channel(0)[1]); 40 EXPECT_FLOAT_EQ(0.15643446f, audio_bus->channel(0)[1]);
41 EXPECT_LT(audio_bus->channel(0)[1], audio_bus->channel(0)[2]); 41 EXPECT_LT(audio_bus->channel(0)[1], audio_bus->channel(0)[2]);
42 EXPECT_LT(audio_bus->channel(0)[2], audio_bus->channel(0)[3]); 42 EXPECT_LT(audio_bus->channel(0)[2], audio_bus->channel(0)[3]);
43 // Spot test negative incursion of sine wave. 43 // Spot test negative incursion of sine wave.
44 EXPECT_NEAR(0, audio_bus->channel(0)[half_period], 44 EXPECT_NEAR(0, audio_bus->channel(0)[half_period],
45 std::numeric_limits<float>::epsilon()); 45 std::numeric_limits<float>::epsilon());
46 EXPECT_FLOAT_EQ(-0.15643446f, audio_bus->channel(0)[half_period + 1]); 46 EXPECT_FLOAT_EQ(-0.15643446f, audio_bus->channel(0)[half_period + 1]);
47 EXPECT_GT(audio_bus->channel(0)[half_period + 1], 47 EXPECT_GT(audio_bus->channel(0)[half_period + 1],
48 audio_bus->channel(0)[half_period + 2]); 48 audio_bus->channel(0)[half_period + 2]);
49 EXPECT_GT(audio_bus->channel(0)[half_period + 2], 49 EXPECT_GT(audio_bus->channel(0)[half_period + 2],
50 audio_bus->channel(0)[half_period + 3]); 50 audio_bus->channel(0)[half_period + 3]);
51 } 51 }
52 52
53 TEST(SimpleSources, SineWaveAudioCapped) { 53 TEST(SimpleSources, SineWaveAudioCapped) {
54 SineWaveAudioSource source(1, 200, AudioParameters::kTelephoneSampleRate); 54 SineWaveAudioSource source(1, 200, AudioParameters::kTelephoneSampleRate);
55 55
56 static const int kSampleCap = 100; 56 static const int kSampleCap = 100;
57 source.CapSamples(kSampleCap); 57 source.CapSamples(kSampleCap);
58 58
59 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(1, 2 * kSampleCap); 59 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(1, 2 * kSampleCap);
60 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0, 0), kSampleCap); 60 EXPECT_EQ(source.OnMoreData(
61 audio_bus.get(), 0), kSampleCap);
61 EXPECT_EQ(1, source.callbacks()); 62 EXPECT_EQ(1, source.callbacks());
62 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0, 0), 0); 63 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0), 0);
63 EXPECT_EQ(2, source.callbacks()); 64 EXPECT_EQ(2, source.callbacks());
64 source.Reset(); 65 source.Reset();
65 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0, 0), kSampleCap); 66 EXPECT_EQ(source.OnMoreData(
67 audio_bus.get(), 0), kSampleCap);
66 EXPECT_EQ(3, source.callbacks()); 68 EXPECT_EQ(3, source.callbacks());
67 EXPECT_EQ(0, source.errors()); 69 EXPECT_EQ(0, source.errors());
68 } 70 }
69 71
70 TEST(SimpleSources, OnError) { 72 TEST(SimpleSources, OnError) {
71 SineWaveAudioSource source(1, 200, AudioParameters::kTelephoneSampleRate); 73 SineWaveAudioSource source(1, 200, AudioParameters::kTelephoneSampleRate);
72 source.OnError(NULL); 74 source.OnError(NULL);
73 EXPECT_EQ(1, source.errors()); 75 EXPECT_EQ(1, source.errors());
74 source.OnError(NULL); 76 source.OnError(NULL);
75 EXPECT_EQ(2, source.errors()); 77 EXPECT_EQ(2, source.errors());
(...skipping 12 matching lines...) Expand all
88 temp.Close(); 90 temp.Close();
89 91
90 // Create AudioParameters which match those in the WAV data. 92 // Create AudioParameters which match those in the WAV data.
91 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 93 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
92 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames); 94 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames);
93 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames); 95 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
94 audio_bus->Zero(); 96 audio_bus->Zero();
95 97
96 // Create a FileSource that reads this file. 98 // Create a FileSource that reads this file.
97 FileSource source(params, temp_path); 99 FileSource source(params, temp_path);
98 EXPECT_EQ(kNumFrames, source.OnMoreData(audio_bus.get(), 0, 0)); 100 EXPECT_EQ(kNumFrames, source.OnMoreData(audio_bus.get(), 0));
99 101
100 // Convert the test data (little-endian) into floats and compare. 102 // Convert the test data (little-endian) into floats and compare.
101 const int kFirstSampleIndex = 12 + 8 + 16 + 8; 103 const int kFirstSampleIndex = 12 + 8 + 16 + 8;
102 int16_t data[2]; 104 int16_t data[2];
103 data[0] = kTestAudioData[kFirstSampleIndex]; 105 data[0] = kTestAudioData[kFirstSampleIndex];
104 data[0] |= (kTestAudioData[kFirstSampleIndex + 1] << 8); 106 data[0] |= (kTestAudioData[kFirstSampleIndex + 1] << 8);
105 data[1] = kTestAudioData[kFirstSampleIndex + 2]; 107 data[1] = kTestAudioData[kFirstSampleIndex + 2];
106 data[1] |= (kTestAudioData[kFirstSampleIndex + 3] << 8); 108 data[1] |= (kTestAudioData[kFirstSampleIndex + 3] << 8);
107 109
108 // The first frame should hold the WAV data. 110 // The first frame should hold the WAV data.
(...skipping 15 matching lines...) Expand all
124 CHANNEL_LAYOUT_STEREO, 48000, 16, 10); 126 CHANNEL_LAYOUT_STEREO, 48000, 16, 10);
125 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, 10); 127 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, 10);
126 audio_bus->Zero(); 128 audio_bus->Zero();
127 129
128 // Create a FileSource that reads this file. 130 // Create a FileSource that reads this file.
129 base::FilePath path; 131 base::FilePath path;
130 path = path.Append(FILE_PATH_LITERAL("does")) 132 path = path.Append(FILE_PATH_LITERAL("does"))
131 .Append(FILE_PATH_LITERAL("not")) 133 .Append(FILE_PATH_LITERAL("not"))
132 .Append(FILE_PATH_LITERAL("exist")); 134 .Append(FILE_PATH_LITERAL("exist"));
133 FileSource source(params, path); 135 FileSource source(params, path);
134 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0, 0)); 136 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0));
135 137
136 // Confirm all frames are zero-padded. 138 // Confirm all frames are zero-padded.
137 for (int channel = 0; channel < audio_bus->channels(); ++channel) { 139 for (int channel = 0; channel < audio_bus->channels(); ++channel) {
138 for (int frame = 0; frame < audio_bus->frames(); ++frame) { 140 for (int frame = 0; frame < audio_bus->frames(); ++frame) {
139 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]); 141 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]);
140 } 142 }
141 } 143 }
142 } 144 }
143 145
144 TEST(SimpleSources, FileSourceCorruptTestDataFails) { 146 TEST(SimpleSources, FileSourceCorruptTestDataFails) {
(...skipping 13 matching lines...) Expand all
158 temp.Close(); 160 temp.Close();
159 161
160 // Create AudioParameters which match those in the WAV data. 162 // Create AudioParameters which match those in the WAV data.
161 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 163 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
162 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames); 164 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames);
163 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames); 165 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
164 audio_bus->Zero(); 166 audio_bus->Zero();
165 167
166 // Create a FileSource that reads this file. 168 // Create a FileSource that reads this file.
167 FileSource source(params, temp_path); 169 FileSource source(params, temp_path);
168 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0, 0)); 170 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0));
169 171
170 // Confirm all frames are zero-padded. 172 // Confirm all frames are zero-padded.
171 for (int channel = 0; channel < audio_bus->channels(); ++channel) { 173 for (int channel = 0; channel < audio_bus->channels(); ++channel) {
172 for (int frame = 0; frame < audio_bus->frames(); ++frame) { 174 for (int frame = 0; frame < audio_bus->frames(); ++frame) {
173 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]); 175 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]);
174 } 176 }
175 } 177 }
176 } 178 }
177 179
178 } // namespace media 180 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/simple_sources.cc ('k') | media/audio/sounds/audio_stream_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698