| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/copresence/test/audio_test_support.h" | 5 #include "components/copresence/test/audio_test_support.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 | 8 |
| 9 #include "media/base/audio_bus.h" | 9 #include "media/base/audio_bus.h" |
| 10 | 10 |
| 11 namespace copresence { | 11 namespace copresence { |
| 12 | 12 |
| 13 void PopulateSamples(int random_seed, size_t size, float* samples) { | 13 void PopulateSamples(unsigned int random_seed, size_t size, float* samples) { |
| 14 #if defined(OS_WIN) |
| 14 srand(random_seed); | 15 srand(random_seed); |
| 15 #if defined(OS_WIN) | |
| 16 for (size_t i = 0; i < size; ++i) | 16 for (size_t i = 0; i < size; ++i) |
| 17 samples[i] = (2.0 * rand() / RAND_MAX) - 1; | 17 samples[i] = (2.0 * rand() / RAND_MAX) - 1; |
| 18 #else | 18 #else |
| 19 unsigned int rand_state; | |
| 20 for (size_t i = 0; i < size; ++i) | 19 for (size_t i = 0; i < size; ++i) |
| 21 samples[i] = (2.0 * rand_r(&rand_state) / RAND_MAX) - 1; | 20 samples[i] = (2.0 * rand_r(&random_seed) / RAND_MAX) - 1; |
| 22 #endif | 21 #endif |
| 23 } | 22 } |
| 24 | 23 |
| 25 scoped_refptr<media::AudioBusRefCounted> | 24 scoped_refptr<media::AudioBusRefCounted> |
| 26 CreateRandomAudioRefCounted(int random_seed, int channels, int samples) { | 25 CreateRandomAudioRefCounted(int random_seed, int channels, int samples) { |
| 27 scoped_refptr<media::AudioBusRefCounted> bus = | 26 scoped_refptr<media::AudioBusRefCounted> bus = |
| 28 media::AudioBusRefCounted::Create(channels, samples); | 27 media::AudioBusRefCounted::Create(channels, samples); |
| 29 for (int ch = 0; ch < channels; ++ch) | 28 for (int ch = 0; ch < channels; ++ch) |
| 30 PopulateSamples(random_seed, samples, bus->channel(ch)); | 29 PopulateSamples(random_seed, samples, bus->channel(ch)); |
| 31 return bus; | 30 return bus; |
| 32 } | 31 } |
| 33 | 32 |
| 34 } // namespace copresence | 33 } // namespace copresence |
| OLD | NEW |