Chromium Code Reviews| Index: components/copresence/test/audio_test_support.cc |
| diff --git a/components/copresence/test/audio_test_support.cc b/components/copresence/test/audio_test_support.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a05d30045b62e6c8962ae05b473f2ef1d218347 |
| --- /dev/null |
| +++ b/components/copresence/test/audio_test_support.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/copresence/test/audio_test_support.h" |
| + |
| +#include <cstdlib> |
| + |
| +#include "media/base/audio_bus.h" |
| + |
| +namespace { |
| + |
| +const int kFixedRandomSeed = 0x1337; |
| + |
| +} // namespace |
| + |
| +namespace copresence { |
| + |
| +void PopulateSamples(int random_seed, size_t size, float* samples) { |
| + srand(random_seed); |
| + for (size_t i = 0; i < size; ++i) |
| + samples[i] = (2.0 * rand() / RAND_MAX) - 1; |
| +} |
| + |
| +scoped_ptr<media::AudioBus> CreateRandomAudio(int channels, int samples) { |
| + scoped_ptr<media::AudioBus> bus = media::AudioBus::Create(channels, samples); |
| + for (int ch = 0; ch < channels; ++ch) |
| + PopulateSamples(kFixedRandomSeed, samples, bus->channel(ch)); |
|
Daniel Erat
2014/07/31 22:31:16
it seems strange that one of the methods in this f
rkc
2014/08/01 21:08:57
Changed to allow passed in seeds for all three.
Do
|
| + return bus.Pass(); |
| +} |
| + |
| +scoped_refptr<media::AudioBusRefCounted> CreateRandomAudioRefCounted( |
| + int channels, int samples) { |
| + scoped_refptr<media::AudioBusRefCounted> bus = |
| + media::AudioBusRefCounted::Create(channels, samples); |
| + for (int ch = 0; ch < channels; ++ch) |
| + PopulateSamples(kFixedRandomSeed, samples, bus->channel(ch)); |
| + return bus; |
| +} |
| + |
| +} // namespace copresence |