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

Side by Side Diff: media/base/fake_audio_render_callback.cc

Issue 2365723003: Break out WebAudio suspension code into new class. Add tests. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 8 #include <cmath>
9 9
10 #include "media/base/fake_audio_render_callback.h" 10 #include "media/base/fake_audio_render_callback.h"
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 last_frames_delayed_(-1), 17 last_frames_delayed_(-1),
18 last_channel_count_(-1), 18 last_channel_count_(-1),
19 volume_(1) { 19 volume_(1) {
20 reset(); 20 reset();
21 } 21 }
22 22
23 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} 23 FakeAudioRenderCallback::~FakeAudioRenderCallback() {}
24 24
25 int FakeAudioRenderCallback::Render(AudioBus* audio_bus, 25 int FakeAudioRenderCallback::Render(AudioBus* audio_bus,
26 uint32_t frames_delayed, 26 uint32_t frames_delayed,
27 uint32_t frames_skipped) { 27 uint32_t frames_skipped) {
28 return RenderInternal(audio_bus, frames_delayed, volume_);
29 }
30
31 double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus,
32 uint32_t frames_delayed) {
33 // Volume should only be applied by the caller to ProvideInput, so don't bake
34 // it into the rendered audio.
35 RenderInternal(audio_bus, frames_delayed, 1.0);
36 return volume_;
37 }
38
39 int FakeAudioRenderCallback::RenderInternal(AudioBus* audio_bus,
40 uint32_t frames_delayed,
41 double volume) {
28 DCHECK_LE(frames_delayed, static_cast<uint32_t>(INT_MAX)); 42 DCHECK_LE(frames_delayed, static_cast<uint32_t>(INT_MAX));
29 last_frames_delayed_ = static_cast<int>(frames_delayed); 43 last_frames_delayed_ = static_cast<int>(frames_delayed);
30
31 last_channel_count_ = audio_bus->channels(); 44 last_channel_count_ = audio_bus->channels();
32 45
33 int number_of_frames = audio_bus->frames(); 46 int number_of_frames = audio_bus->frames();
34 if (half_fill_) 47 if (half_fill_)
35 number_of_frames /= 2; 48 number_of_frames /= 2;
36 49
37 // Fill first channel with a sine wave. 50 // Fill first channel with a sine wave.
38 for (int i = 0; i < number_of_frames; ++i) 51 for (int i = 0; i < number_of_frames; ++i)
39 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)); 52 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)) * volume;
40 x_ += number_of_frames * step_; 53 x_ += number_of_frames * step_;
41 54
42 // Copy first channel into the rest of the channels. 55 // Copy first channel into the rest of the channels.
43 for (int i = 1; i < audio_bus->channels(); ++i) 56 for (int i = 1; i < audio_bus->channels(); ++i) {
44 memcpy(audio_bus->channel(i), audio_bus->channel(0), 57 memcpy(audio_bus->channel(i), audio_bus->channel(0),
45 number_of_frames * sizeof(*audio_bus->channel(i))); 58 number_of_frames * sizeof(*audio_bus->channel(i)));
59 }
46 60
47 return number_of_frames; 61 return number_of_frames;
48 } 62 }
49 63
50 double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus,
51 uint32_t frames_delayed) {
52 Render(audio_bus, frames_delayed, 0);
53 return volume_;
54 }
55
56 } // namespace media 64 } // namespace media
OLDNEW
« 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