OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/audio_modem/test/random_samples.h" | |
6 | |
7 #include <cstdlib> | |
8 | |
9 #include "build/build_config.h" | |
10 #include "media/base/audio_bus.h" | |
11 | |
12 namespace audio_modem { | |
13 | |
14 void PopulateSamples(unsigned int random_seed, size_t size, float* samples) { | |
15 // On Windows, rand() is threadsafe, and rand_r() is not available. | |
16 #if defined(OS_WIN) | |
17 srand(random_seed); | |
18 for (size_t i = 0; i < size; ++i) | |
19 samples[i] = (2.0 * rand() / RAND_MAX) - 1; // NOLINT | |
20 #else | |
21 for (size_t i = 0; i < size; ++i) | |
22 samples[i] = (2.0 * rand_r(&random_seed) / RAND_MAX) - 1; | |
23 #endif | |
24 } | |
25 | |
26 scoped_refptr<media::AudioBusRefCounted> | |
27 CreateRandomAudioRefCounted(int random_seed, int channels, int samples) { | |
28 scoped_refptr<media::AudioBusRefCounted> bus = | |
29 media::AudioBusRefCounted::Create(channels, samples); | |
30 for (int ch = 0; ch < channels; ++ch) | |
31 PopulateSamples(random_seed, samples, bus->channel(ch)); | |
32 return bus; | |
33 } | |
34 | |
35 } // namespace audio_modem | |
OLD | NEW |