| 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 "media/base/fake_audio_render_callback.h" | 8 #include "media/base/fake_audio_render_callback.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 | 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 reset(); | 17 reset(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} | 20 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} |
| 21 | 21 |
| 22 int FakeAudioRenderCallback::Render(const std::vector<float*>& audio_data, | 22 int FakeAudioRenderCallback::Render(AudioBus* audio_bus, int number_of_frames, |
| 23 int number_of_frames, | |
| 24 int audio_delay_milliseconds) { | 23 int audio_delay_milliseconds) { |
| 25 if (half_fill_) | 24 if (half_fill_) |
| 26 number_of_frames /= 2; | 25 number_of_frames /= 2; |
| 27 | 26 |
| 28 // Fill first channel with a sine wave. | 27 // Fill first channel with a sine wave. |
| 29 for (int i = 0; i < number_of_frames; ++i) | 28 for (int i = 0; i < number_of_frames; ++i) |
| 30 audio_data[0][i] = sin(2 * M_PI * (x_ + step_ * i)); | 29 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)); |
| 31 x_ += number_of_frames * step_; | 30 x_ += number_of_frames * step_; |
| 32 | 31 |
| 33 // Copy first channel into the rest of the channels. | 32 // Copy first channel into the rest of the channels. |
| 34 for (size_t i = 1; i < audio_data.size(); ++i) | 33 for (int i = 1; i < audio_bus->channels(); ++i) |
| 35 memcpy(audio_data[i], audio_data[0], | 34 memcpy(audio_bus->channel(i), audio_bus->channel(0), |
| 36 number_of_frames * sizeof(*audio_data[0])); | 35 number_of_frames * sizeof(*audio_bus->channel(i))); |
| 37 | 36 |
| 38 return number_of_frames; | 37 return number_of_frames; |
| 39 } | 38 } |
| 40 | 39 |
| 41 } // namespace media | 40 } // namespace media |
| OLD | NEW |