Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / audio_modem / test / random_samples.cc
blob815beaa24de1904af8f5379ba45c072bc2f7e5d4
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.
5 #include "components/audio_modem/test/random_samples.h"
7 #include <cstdlib>
9 #include "media/base/audio_bus.h"
11 namespace audio_modem {
13 void PopulateSamples(unsigned int random_seed, size_t size, float* samples) {
14 // On Windows, rand() is threadsafe, and rand_r() is not available.
15 #if defined(OS_WIN)
16 srand(random_seed);
17 for (size_t i = 0; i < size; ++i)
18 samples[i] = (2.0 * rand() / RAND_MAX) - 1; // NOLINT
19 #else
20 for (size_t i = 0; i < size; ++i)
21 samples[i] = (2.0 * rand_r(&random_seed) / RAND_MAX) - 1;
22 #endif
25 scoped_refptr<media::AudioBusRefCounted>
26 CreateRandomAudioRefCounted(int random_seed, int channels, int samples) {
27 scoped_refptr<media::AudioBusRefCounted> bus =
28 media::AudioBusRefCounted::Create(channels, samples);
29 for (int ch = 0; ch < channels; ++ch)
30 PopulateSamples(random_seed, samples, bus->channel(ch));
31 return bus;
34 } // namespace audio_modem