Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Unified Diff: media/base/fake_audio_render_callback.cc

Issue 2382473002: Merge M54: "Break out WebAudio suspension code into new class. Add tests." (Closed)
Patch Set: Fix conflicts. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/fake_audio_render_callback.h ('k') | media/base/silent_sink_suspender.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/fake_audio_render_callback.cc
diff --git a/media/base/fake_audio_render_callback.cc b/media/base/fake_audio_render_callback.cc
index fb686c56c14f05e0ce34da32602c1039eb005522..65de1187640f5669553fb8e5946b2cfcca8dc607 100644
--- a/media/base/fake_audio_render_callback.cc
+++ b/media/base/fake_audio_render_callback.cc
@@ -25,9 +25,22 @@ FakeAudioRenderCallback::~FakeAudioRenderCallback() {}
int FakeAudioRenderCallback::Render(AudioBus* audio_bus,
uint32_t frames_delayed,
uint32_t frames_skipped) {
+ return RenderInternal(audio_bus, frames_delayed, volume_);
+}
+
+double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus,
+ uint32_t frames_delayed) {
+ // Volume should only be applied by the caller to ProvideInput, so don't bake
+ // it into the rendered audio.
+ RenderInternal(audio_bus, frames_delayed, 1.0);
+ return volume_;
+}
+
+int FakeAudioRenderCallback::RenderInternal(AudioBus* audio_bus,
+ uint32_t frames_delayed,
+ double volume) {
DCHECK_LE(frames_delayed, static_cast<uint32_t>(INT_MAX));
last_frames_delayed_ = static_cast<int>(frames_delayed);
-
last_channel_count_ = audio_bus->channels();
int number_of_frames = audio_bus->frames();
@@ -36,21 +49,16 @@ int FakeAudioRenderCallback::Render(AudioBus* audio_bus,
// Fill first channel with a sine wave.
for (int i = 0; i < number_of_frames; ++i)
- audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i));
+ audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)) * volume;
x_ += number_of_frames * step_;
// Copy first channel into the rest of the channels.
- for (int i = 1; i < audio_bus->channels(); ++i)
+ for (int i = 1; i < audio_bus->channels(); ++i) {
memcpy(audio_bus->channel(i), audio_bus->channel(0),
number_of_frames * sizeof(*audio_bus->channel(i)));
+ }
return number_of_frames;
}
-double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus,
- uint32_t frames_delayed) {
- Render(audio_bus, frames_delayed, 0);
- return volume_;
-}
-
} // namespace media
« no previous file with comments | « media/base/fake_audio_render_callback.h ('k') | media/base/silent_sink_suspender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698