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

Side by Side Diff: media/base/audio_converter_unittest.cc

Issue 2567143002: media::SilentSinkSuspender should simulate |delay| and |delay_timestamp| (Closed)
Patch Set: build fix content_unittets & media_blink_unittsests Created 3 years, 11 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
« no previous file with comments | « media/base/audio_bus_perftest.cc ('k') | media/base/audio_hash_unittest.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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "media/base/audio_converter.h" 8 #include "media/base/audio_converter.h"
9 9
10 #include <stddef.h> 10 #include <stddef.h>
11 11
12 #include <cmath> 12 #include <cmath>
13 #include <memory> 13 #include <memory>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "media/base/audio_timestamp_helper.h"
18 #include "media/base/fake_audio_render_callback.h" 19 #include "media/base/fake_audio_render_callback.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace media { 23 namespace media {
23 24
24 // Parameters which control the many input case tests. 25 // Parameters which control the many input case tests.
25 static const int kConvertInputs = 8; 26 static const int kConvertInputs = 8;
26 static const int kConvertCycles = 3; 27 static const int kConvertCycles = 3;
27 28
(...skipping 24 matching lines...) Expand all
52 53
53 converter_.reset(new AudioConverter( 54 converter_.reset(new AudioConverter(
54 input_parameters_, output_parameters_, false)); 55 input_parameters_, output_parameters_, false));
55 56
56 audio_bus_ = AudioBus::Create(output_parameters_); 57 audio_bus_ = AudioBus::Create(output_parameters_);
57 expected_audio_bus_ = AudioBus::Create(output_parameters_); 58 expected_audio_bus_ = AudioBus::Create(output_parameters_);
58 59
59 // Allocate one callback for generating expected results. 60 // Allocate one callback for generating expected results.
60 double step = kSineCycles / static_cast<double>( 61 double step = kSineCycles / static_cast<double>(
61 output_parameters_.frames_per_buffer()); 62 output_parameters_.frames_per_buffer());
62 expected_callback_.reset(new FakeAudioRenderCallback(step)); 63 expected_callback_.reset(new FakeAudioRenderCallback(step, kSampleRate));
63 } 64 }
64 65
65 // Creates |count| input callbacks to be used for conversion testing. 66 // Creates |count| input callbacks to be used for conversion testing.
66 void InitializeInputs(int count) { 67 void InitializeInputs(int count) {
67 // Setup FakeAudioRenderCallback step to compensate for resampling. 68 // Setup FakeAudioRenderCallback step to compensate for resampling.
68 double scale_factor = input_parameters_.sample_rate() / 69 double scale_factor = input_parameters_.sample_rate() /
69 static_cast<double>(output_parameters_.sample_rate()); 70 static_cast<double>(output_parameters_.sample_rate());
70 double step = kSineCycles / (scale_factor * 71 double step = kSineCycles / (scale_factor *
71 static_cast<double>(output_parameters_.frames_per_buffer())); 72 static_cast<double>(output_parameters_.frames_per_buffer()));
72 73
73 for (int i = 0; i < count; ++i) { 74 for (int i = 0; i < count; ++i) {
74 fake_callbacks_.push_back(new FakeAudioRenderCallback(step)); 75 fake_callbacks_.push_back(new FakeAudioRenderCallback(step, kSampleRate));
75 converter_->AddInput(fake_callbacks_[i]); 76 converter_->AddInput(fake_callbacks_[i]);
76 } 77 }
77 } 78 }
78 79
79 // Resets all input callbacks to a pristine state. 80 // Resets all input callbacks to a pristine state.
80 void Reset() { 81 void Reset() {
81 converter_->Reset(); 82 converter_->Reset();
82 for (size_t i = 0; i < fake_callbacks_.size(); ++i) 83 for (size_t i = 0; i < fake_callbacks_.size(); ++i)
83 fake_callbacks_[i]->reset(); 84 fake_callbacks_[i]->reset();
84 expected_callback_->reset(); 85 expected_callback_->reset();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 AudioParameters input_parameters(AudioParameters::AUDIO_PCM_LINEAR, 206 AudioParameters input_parameters(AudioParameters::AUDIO_PCM_LINEAR,
206 CHANNEL_LAYOUT_DISCRETE, kSampleRate, 207 CHANNEL_LAYOUT_DISCRETE, kSampleRate,
207 kBitsPerChannel, kLowLatencyBufferSize); 208 kBitsPerChannel, kLowLatencyBufferSize);
208 input_parameters.set_channels_for_discrete(10); 209 input_parameters.set_channels_for_discrete(10);
209 AudioParameters output_parameters(AudioParameters::AUDIO_PCM_LINEAR, 210 AudioParameters output_parameters(AudioParameters::AUDIO_PCM_LINEAR,
210 CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2, 211 CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2,
211 kBitsPerChannel, kHighLatencyBufferSize); 212 kBitsPerChannel, kHighLatencyBufferSize);
212 output_parameters.set_channels_for_discrete(5); 213 output_parameters.set_channels_for_discrete(5);
213 214
214 AudioConverter converter(input_parameters, output_parameters, false); 215 AudioConverter converter(input_parameters, output_parameters, false);
215 FakeAudioRenderCallback callback(0.2); 216 FakeAudioRenderCallback callback(0.2, kSampleRate);
216 std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(output_parameters); 217 std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(output_parameters);
217 converter.AddInput(&callback); 218 converter.AddInput(&callback);
218 converter.Convert(audio_bus.get()); 219 converter.Convert(audio_bus.get());
219 220
220 // double input_sample_rate = input_parameters.sample_rate(); 221 // double input_sample_rate = input_parameters.sample_rate();
221 // int fill_count = 222 // int fill_count =
222 // (output_parameters.frames_per_buffer() * input_sample_rate / 223 // (output_parameters.frames_per_buffer() * input_sample_rate /
223 // output_parameters.sample_rate()) / 224 // output_parameters.sample_rate()) /
224 // input_parameters.frames_per_buffer(); 225 // input_parameters.frames_per_buffer();
225 // 226 //
226 // This magic number is the accumulated MultiChannelResampler delay after 227 // This magic number is the accumulated MultiChannelResampler delay after
227 // |fill_count| (4) callbacks to provide input. The number of frames delayed 228 // |fill_count| (4) callbacks to provide input. The number of frames delayed
228 // is an implementation detail of the SincResampler chunk size (480 for the 229 // is an implementation detail of the SincResampler chunk size (480 for the
229 // first two callbacks, 512 for the last two callbacks). See 230 // first two callbacks, 512 for the last two callbacks). See
230 // SincResampler.ChunkSize(). 231 // SincResampler.ChunkSize().
231 int kExpectedDelay = 992; 232 int kExpectedDelay = 992;
232 233 auto expected_delay =
233 EXPECT_EQ(kExpectedDelay, callback.last_frames_delayed()); 234 AudioTimestampHelper::FramesToTime(kExpectedDelay, kSampleRate);
235 EXPECT_EQ(expected_delay, callback.last_delay());
234 EXPECT_EQ(input_parameters.channels(), callback.last_channel_count()); 236 EXPECT_EQ(input_parameters.channels(), callback.last_channel_count());
235 } 237 }
236 238
237 TEST_P(AudioConverterTest, ArbitraryOutputRequestSize) { 239 TEST_P(AudioConverterTest, ArbitraryOutputRequestSize) {
238 // Resize output bus to be half of |output_parameters_|'s frames_per_buffer(). 240 // Resize output bus to be half of |output_parameters_|'s frames_per_buffer().
239 audio_bus_ = AudioBus::Create(output_parameters_.channels(), 241 audio_bus_ = AudioBus::Create(output_parameters_.channels(),
240 output_parameters_.frames_per_buffer() / 2); 242 output_parameters_.frames_per_buffer() / 2);
241 RunTest(1); 243 RunTest(1);
242 } 244 }
243 245
(...skipping 15 matching lines...) Expand all
259 // No resampling. No channel mixing. 261 // No resampling. No channel mixing.
260 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), 262 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048),
261 263
262 // Upsampling. Channel upmixing. 264 // Upsampling. Channel upmixing.
263 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), 265 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033),
264 266
265 // Downsampling. Channel downmixing. 267 // Downsampling. Channel downmixing.
266 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); 268 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042)));
267 269
268 } // namespace media 270 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_bus_perftest.cc ('k') | media/base/audio_hash_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698