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

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

Issue 2004283002: AudioConverter: Express delay in frames rather than msec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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>
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2, 209 CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2,
210 kBitsPerChannel, kHighLatencyBufferSize); 210 kBitsPerChannel, kHighLatencyBufferSize);
211 output_parameters.set_channels_for_discrete(5); 211 output_parameters.set_channels_for_discrete(5);
212 212
213 AudioConverter converter(input_parameters, output_parameters, false); 213 AudioConverter converter(input_parameters, output_parameters, false);
214 FakeAudioRenderCallback callback(0.2); 214 FakeAudioRenderCallback callback(0.2);
215 std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(output_parameters); 215 std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(output_parameters);
216 converter.AddInput(&callback); 216 converter.AddInput(&callback);
217 converter.Convert(audio_bus.get()); 217 converter.Convert(audio_bus.get());
218 218
219 // Calculate the expected buffer delay for given AudioParameters. 219 // double input_sample_rate = input_parameters.sample_rate();
220 double input_sample_rate = input_parameters.sample_rate(); 220 // int fill_count =
221 int fill_count = 221 // (output_parameters.frames_per_buffer() * input_sample_rate /
222 (output_parameters.frames_per_buffer() * input_sample_rate / 222 // output_parameters.sample_rate()) /
223 output_parameters.sample_rate()) / input_parameters.frames_per_buffer(); 223 // input_parameters.frames_per_buffer();
224 //
225 // This magic number is the accumulated MultiChannelResampler delay after
226 // |fill_count| (4) callbacks to provide input. The number of frames delayed
227 // is an implementation detail of the SincResampler chunk size (480 for the
228 // first two callbacks, 512 for the last two callbacks). See
229 // SincResampler.ChunkSize().
230 int kExpectedDelay = 992;
224 231
225 base::TimeDelta input_frame_duration = base::TimeDelta::FromMicroseconds( 232 EXPECT_EQ(kExpectedDelay, callback.last_frames_delayed());
226 base::Time::kMicrosecondsPerSecond / input_sample_rate);
227
228 int expected_last_delay_milliseconds =
229 fill_count * input_parameters.frames_per_buffer() *
230 input_frame_duration.InMillisecondsF();
231
232 EXPECT_EQ(expected_last_delay_milliseconds,
chcunningham 2016/05/24 01:34:38 This old method for building an expectation is bus
233 callback.last_audio_delay_milliseconds());
234 EXPECT_EQ(input_parameters.channels(), callback.last_channel_count()); 233 EXPECT_EQ(input_parameters.channels(), callback.last_channel_count());
235 } 234 }
236 235
237 TEST_P(AudioConverterTest, ArbitraryOutputRequestSize) { 236 TEST_P(AudioConverterTest, ArbitraryOutputRequestSize) {
238 // Resize output bus to be half of |output_parameters_|'s frames_per_buffer(). 237 // Resize output bus to be half of |output_parameters_|'s frames_per_buffer().
239 audio_bus_ = AudioBus::Create(output_parameters_.channels(), 238 audio_bus_ = AudioBus::Create(output_parameters_.channels(),
240 output_parameters_.frames_per_buffer() / 2); 239 output_parameters_.frames_per_buffer() / 2);
241 RunTest(1); 240 RunTest(1);
242 } 241 }
243 242
(...skipping 15 matching lines...) Expand all
259 // No resampling. No channel mixing. 258 // No resampling. No channel mixing.
260 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048), 259 std::tr1::make_tuple(44100, 44100, CHANNEL_LAYOUT_STEREO, 0.00000048),
261 260
262 // Upsampling. Channel upmixing. 261 // Upsampling. Channel upmixing.
263 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033), 262 std::tr1::make_tuple(44100, 48000, CHANNEL_LAYOUT_QUAD, 0.033),
264 263
265 // Downsampling. Channel downmixing. 264 // Downsampling. Channel downmixing.
266 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042))); 265 std::tr1::make_tuple(48000, 41000, CHANNEL_LAYOUT_MONO, 0.042)));
267 266
268 } // namespace media 267 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698