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

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

Issue 2567143002: media::SilentSinkSuspender should simulate |delay| and |delay_timestamp| (Closed)
Patch Set: Created 4 years 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
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/audio_timestamp_helper.h" 10 #include "media/base/audio_timestamp_helper.h"
11 #include "media/base/fake_audio_render_callback.h" 11 #include "media/base/fake_audio_render_callback.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 FakeAudioRenderCallback::FakeAudioRenderCallback(double step) 15 FakeAudioRenderCallback::FakeAudioRenderCallback(double step)
16 : half_fill_(false), 16 : half_fill_(false),
17 step_(step), 17 step_(step),
18 last_frames_delayed_(-1), 18 last_delay_(base::TimeDelta::Max()),
19 last_channel_count_(-1), 19 last_channel_count_(-1),
20 volume_(1) { 20 volume_(1) {
21 reset(); 21 reset();
22 } 22 }
23 23
24 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} 24 FakeAudioRenderCallback::~FakeAudioRenderCallback() {}
25 25
26 int FakeAudioRenderCallback::Render(base::TimeDelta delay, 26 int FakeAudioRenderCallback::Render(base::TimeDelta delay,
27 base::TimeTicks delay_timestamp, 27 base::TimeTicks delay_timestamp,
28 int prior_frames_skipped, 28 int prior_frames_skipped,
29 AudioBus* audio_bus) { 29 AudioBus* audio_bus) {
30 const int kSampleRate = 48000; 30 return RenderInternal(audio_bus, delay, volume_);
31 auto frames_delayed = AudioTimestampHelper::TimeToFrames(delay, kSampleRate);
32 return RenderInternal(audio_bus, frames_delayed, volume_);
33 } 31 }
34 32
35 double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus, 33 double FakeAudioRenderCallback::ProvideInput(AudioBus* audio_bus,
36 uint32_t frames_delayed) { 34 uint32_t frames_delayed) {
37 // Volume should only be applied by the caller to ProvideInput, so don't bake 35 // Volume should only be applied by the caller to ProvideInput, so don't bake
38 // it into the rendered audio. 36 // it into the rendered audio.
39 RenderInternal(audio_bus, frames_delayed, 1.0); 37 constexpr int kSampleRate = 48000;
chcunningham 2016/12/20 18:36:42 I think this should be defined and passed in (to c
Mikhail 2016/12/20 21:45:50 Done.
38 auto delay = AudioTimestampHelper::FramesToTime(frames_delayed, kSampleRate);
39 RenderInternal(audio_bus, delay, 1.0);
40 return volume_; 40 return volume_;
41 } 41 }
42 42
43 int FakeAudioRenderCallback::RenderInternal(AudioBus* audio_bus, 43 int FakeAudioRenderCallback::RenderInternal(AudioBus* audio_bus,
44 uint32_t frames_delayed, 44 base::TimeDelta delay,
45 double volume) { 45 double volume) {
46 DCHECK_LE(frames_delayed, static_cast<uint32_t>(INT_MAX)); 46 DCHECK_LE(delay, base::TimeDelta::Max());
47 last_frames_delayed_ = static_cast<int>(frames_delayed); 47 last_delay_ = delay;
48 last_channel_count_ = audio_bus->channels(); 48 last_channel_count_ = audio_bus->channels();
49 49
50 int number_of_frames = audio_bus->frames(); 50 int number_of_frames = audio_bus->frames();
51 if (half_fill_) 51 if (half_fill_)
52 number_of_frames /= 2; 52 number_of_frames /= 2;
53 53
54 // Fill first channel with a sine wave. 54 // Fill first channel with a sine wave.
55 for (int i = 0; i < number_of_frames; ++i) 55 for (int i = 0; i < number_of_frames; ++i)
56 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)) * volume; 56 audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)) * volume;
57 x_ += number_of_frames * step_; 57 x_ += number_of_frames * step_;
58 58
59 // Copy first channel into the rest of the channels. 59 // Copy first channel into the rest of the channels.
60 for (int i = 1; i < audio_bus->channels(); ++i) { 60 for (int i = 1; i < audio_bus->channels(); ++i) {
61 memcpy(audio_bus->channel(i), audio_bus->channel(0), 61 memcpy(audio_bus->channel(i), audio_bus->channel(0),
62 number_of_frames * sizeof(*audio_bus->channel(i))); 62 number_of_frames * sizeof(*audio_bus->channel(i)));
63 } 63 }
64 64
65 return number_of_frames; 65 return number_of_frames;
66 } 66 }
67 67
68 } // namespace media 68 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698