| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include <cmath> |
| 9 |
| 8 #include "media/base/fake_audio_render_callback.h" | 10 #include "media/base/fake_audio_render_callback.h" |
| 9 | 11 |
| 10 #include <cmath> | |
| 11 | |
| 12 namespace media { | 12 namespace media { |
| 13 | 13 |
| 14 FakeAudioRenderCallback::FakeAudioRenderCallback(double step) | 14 FakeAudioRenderCallback::FakeAudioRenderCallback(double step) |
| 15 : half_fill_(false), | 15 : half_fill_(false), |
| 16 step_(step), | 16 step_(step), |
| 17 last_audio_delay_milliseconds_(-1) { | 17 last_audio_delay_milliseconds_(-1), |
| 18 volume_(1) { |
| 18 reset(); | 19 reset(); |
| 19 } | 20 } |
| 20 | 21 |
| 21 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} | 22 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} |
| 22 | 23 |
| 23 int FakeAudioRenderCallback::Render(AudioBus* audio_bus, | 24 int FakeAudioRenderCallback::Render(AudioBus* audio_bus, |
| 24 int audio_delay_milliseconds) { | 25 int audio_delay_milliseconds) { |
| 25 last_audio_delay_milliseconds_ = audio_delay_milliseconds; | 26 last_audio_delay_milliseconds_ = audio_delay_milliseconds; |
| 26 int number_of_frames = audio_bus->frames(); | 27 int number_of_frames = audio_bus->frames(); |
| 27 if (half_fill_) | 28 if (half_fill_) |
| 28 number_of_frames /= 2; | 29 number_of_frames /= 2; |
| 29 | 30 |
| 30 // Fill first channel with a sine wave. | 31 // Fill first channel with a sine wave. |
| 31 for (int i = 0; i < number_of_frames; ++i) | 32 for (int i = 0; i < number_of_frames; ++i) |
| 32 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)); | 33 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)); |
| 33 x_ += number_of_frames * step_; | 34 x_ += number_of_frames * step_; |
| 34 | 35 |
| 35 // Copy first channel into the rest of the channels. | 36 // Copy first channel into the rest of the channels. |
| 36 for (int i = 1; i < audio_bus->channels(); ++i) | 37 for (int i = 1; i < audio_bus->channels(); ++i) |
| 37 memcpy(audio_bus->channel(i), audio_bus->channel(0), | 38 memcpy(audio_bus->channel(i), audio_bus->channel(0), |
| 38 number_of_frames * sizeof(*audio_bus->channel(i))); | 39 number_of_frames * sizeof(*audio_bus->channel(i))); |
| 39 | 40 |
| 40 return number_of_frames; | 41 return number_of_frames; |
| 41 } | 42 } |
| 42 | 43 |
| 44 double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus, |
| 45 base::TimeDelta buffer_delay) { |
| 46 Render(audio_bus, buffer_delay.InMilliseconds()); |
| 47 return volume_; |
| 48 } |
| 49 |
| 43 } // namespace media | 50 } // namespace media |
| OLD | NEW |