Delete unused downloads page asset.
[chromium-blink-merge.git] / media / base / fake_audio_render_callback.cc
blob73d606ec3fb66f06f40e1584bc40c7a367ed1626
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
3 // found in the LICENSE file.
5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES
8 #include <cmath>
10 #include "media/base/fake_audio_render_callback.h"
12 namespace media {
14 FakeAudioRenderCallback::FakeAudioRenderCallback(double step)
15 : half_fill_(false),
16 step_(step),
17 last_audio_delay_milliseconds_(-1),
18 last_channel_count_(-1),
19 volume_(1) {
20 reset();
23 FakeAudioRenderCallback::~FakeAudioRenderCallback() {}
25 int FakeAudioRenderCallback::Render(AudioBus* audio_bus,
26 int audio_delay_milliseconds) {
27 last_audio_delay_milliseconds_ = audio_delay_milliseconds;
28 last_channel_count_ = audio_bus->channels();
30 int number_of_frames = audio_bus->frames();
31 if (half_fill_)
32 number_of_frames /= 2;
34 // Fill first channel with a sine wave.
35 for (int i = 0; i < number_of_frames; ++i)
36 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i));
37 x_ += number_of_frames * step_;
39 // Copy first channel into the rest of the channels.
40 for (int i = 1; i < audio_bus->channels(); ++i)
41 memcpy(audio_bus->channel(i), audio_bus->channel(0),
42 number_of_frames * sizeof(*audio_bus->channel(i)));
44 return number_of_frames;
47 double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus,
48 base::TimeDelta buffer_delay) {
49 Render(audio_bus, buffer_delay.InMillisecondsF() + 0.5);
50 return volume_;
53 } // namespace media