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

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

Issue 1538563002: 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: Code review fix. git cl format. Rebase. 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); 31 source.OnMoreData(audio_bus.get(), 0, 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( 60 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0, 0), kSampleCap);
61 audio_bus.get(), 0), kSampleCap);
62 EXPECT_EQ(1, source.callbacks()); 61 EXPECT_EQ(1, source.callbacks());
63 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0), 0); 62 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0, 0), 0);
64 EXPECT_EQ(2, source.callbacks()); 63 EXPECT_EQ(2, source.callbacks());
65 source.Reset(); 64 source.Reset();
66 EXPECT_EQ(source.OnMoreData( 65 EXPECT_EQ(source.OnMoreData(audio_bus.get(), 0, 0), kSampleCap);
67 audio_bus.get(), 0), kSampleCap);
68 EXPECT_EQ(3, source.callbacks()); 66 EXPECT_EQ(3, source.callbacks());
69 EXPECT_EQ(0, source.errors()); 67 EXPECT_EQ(0, source.errors());
70 } 68 }
71 69
72 TEST(SimpleSources, OnError) { 70 TEST(SimpleSources, OnError) {
73 SineWaveAudioSource source(1, 200, AudioParameters::kTelephoneSampleRate); 71 SineWaveAudioSource source(1, 200, AudioParameters::kTelephoneSampleRate);
74 source.OnError(NULL); 72 source.OnError(NULL);
75 EXPECT_EQ(1, source.errors()); 73 EXPECT_EQ(1, source.errors());
76 source.OnError(NULL); 74 source.OnError(NULL);
77 EXPECT_EQ(2, source.errors()); 75 EXPECT_EQ(2, source.errors());
(...skipping 12 matching lines...) Expand all
90 temp.Close(); 88 temp.Close();
91 89
92 // Create AudioParameters which match those in the WAV data. 90 // Create AudioParameters which match those in the WAV data.
93 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 91 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
94 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames); 92 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames);
95 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames); 93 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
96 audio_bus->Zero(); 94 audio_bus->Zero();
97 95
98 // Create a FileSource that reads this file. 96 // Create a FileSource that reads this file.
99 FileSource source(params, temp_path); 97 FileSource source(params, temp_path);
100 EXPECT_EQ(kNumFrames, source.OnMoreData(audio_bus.get(), 0)); 98 EXPECT_EQ(kNumFrames, source.OnMoreData(audio_bus.get(), 0, 0));
101 99
102 // Convert the test data (little-endian) into floats and compare. 100 // Convert the test data (little-endian) into floats and compare.
103 const int kFirstSampleIndex = 12 + 8 + 16 + 8; 101 const int kFirstSampleIndex = 12 + 8 + 16 + 8;
104 int16_t data[2]; 102 int16_t data[2];
105 data[0] = kTestAudioData[kFirstSampleIndex]; 103 data[0] = kTestAudioData[kFirstSampleIndex];
106 data[0] |= (kTestAudioData[kFirstSampleIndex + 1] << 8); 104 data[0] |= (kTestAudioData[kFirstSampleIndex + 1] << 8);
107 data[1] = kTestAudioData[kFirstSampleIndex + 2]; 105 data[1] = kTestAudioData[kFirstSampleIndex + 2];
108 data[1] |= (kTestAudioData[kFirstSampleIndex + 3] << 8); 106 data[1] |= (kTestAudioData[kFirstSampleIndex + 3] << 8);
109 107
110 // The first frame should hold the WAV data. 108 // The first frame should hold the WAV data.
(...skipping 15 matching lines...) Expand all
126 CHANNEL_LAYOUT_STEREO, 48000, 16, 10); 124 CHANNEL_LAYOUT_STEREO, 48000, 16, 10);
127 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, 10); 125 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, 10);
128 audio_bus->Zero(); 126 audio_bus->Zero();
129 127
130 // Create a FileSource that reads this file. 128 // Create a FileSource that reads this file.
131 base::FilePath path; 129 base::FilePath path;
132 path = path.Append(FILE_PATH_LITERAL("does")) 130 path = path.Append(FILE_PATH_LITERAL("does"))
133 .Append(FILE_PATH_LITERAL("not")) 131 .Append(FILE_PATH_LITERAL("not"))
134 .Append(FILE_PATH_LITERAL("exist")); 132 .Append(FILE_PATH_LITERAL("exist"));
135 FileSource source(params, path); 133 FileSource source(params, path);
136 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0)); 134 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0, 0));
137 135
138 // Confirm all frames are zero-padded. 136 // Confirm all frames are zero-padded.
139 for (int channel = 0; channel < audio_bus->channels(); ++channel) { 137 for (int channel = 0; channel < audio_bus->channels(); ++channel) {
140 for (int frame = 0; frame < audio_bus->frames(); ++frame) { 138 for (int frame = 0; frame < audio_bus->frames(); ++frame) {
141 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]); 139 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]);
142 } 140 }
143 } 141 }
144 } 142 }
145 143
146 TEST(SimpleSources, FileSourceCorruptTestDataFails) { 144 TEST(SimpleSources, FileSourceCorruptTestDataFails) {
(...skipping 13 matching lines...) Expand all
160 temp.Close(); 158 temp.Close();
161 159
162 // Create AudioParameters which match those in the WAV data. 160 // Create AudioParameters which match those in the WAV data.
163 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 161 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
164 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames); 162 CHANNEL_LAYOUT_STEREO, 48000, 16, kNumFrames);
165 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames); 163 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
166 audio_bus->Zero(); 164 audio_bus->Zero();
167 165
168 // Create a FileSource that reads this file. 166 // Create a FileSource that reads this file.
169 FileSource source(params, temp_path); 167 FileSource source(params, temp_path);
170 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0)); 168 EXPECT_EQ(0, source.OnMoreData(audio_bus.get(), 0, 0));
171 169
172 // Confirm all frames are zero-padded. 170 // Confirm all frames are zero-padded.
173 for (int channel = 0; channel < audio_bus->channels(); ++channel) { 171 for (int channel = 0; channel < audio_bus->channels(); ++channel) {
174 for (int frame = 0; frame < audio_bus->frames(); ++frame) { 172 for (int frame = 0; frame < audio_bus->frames(); ++frame) {
175 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]); 173 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]);
176 } 174 }
177 } 175 }
178 } 176 }
179 177
180 } // namespace media 178 } // 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