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

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

Issue 10698066: Switch to pcm_low_latency and enable resampling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 8 years, 5 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 | Annotate | Revision Log
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 "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 // Arbitrarily chosen prime value for the fake random number generator. 14 FakeAudioRenderCallback::FakeAudioRenderCallback(double step)
15 static const int kFakeRandomSeed = 9440671;
16
17 FakeAudioRenderCallback::FakeAudioRenderCallback(const AudioParameters& params)
18 : half_fill_(false), 15 : half_fill_(false),
19 fill_value_(1.0f), 16 step_(step) {
20 audio_parameters_(params) { 17 reset();
21 } 18 }
22 19
23 FakeAudioRenderCallback::~FakeAudioRenderCallback() {} 20 FakeAudioRenderCallback::~FakeAudioRenderCallback() {}
24 21
25 int FakeAudioRenderCallback::Render(const std::vector<float*>& audio_data, 22 int FakeAudioRenderCallback::Render(const std::vector<float*>& audio_data,
26 int number_of_frames, 23 int number_of_frames,
27 int audio_delay_milliseconds) { 24 int audio_delay_milliseconds) {
28 if (half_fill_) 25 if (half_fill_)
29 number_of_frames /= 2; 26 number_of_frames /= 2;
30 for (size_t i = 0; i < audio_data.size(); ++i) 27
31 std::fill(audio_data[i], audio_data[i] + number_of_frames, fill_value_); 28 // Fill first channel with a sine wave.
29 for (int i = 0; i < number_of_frames; ++i)
30 audio_data[0][i] = sin(2 * M_PI * (x_ + step_ * i));
31 x_ += number_of_frames * step_;
32
33 // Copy first channel into the rest of the channels.
34 for (size_t i = 1; i < audio_data.size(); ++i)
35 memcpy(audio_data[i], audio_data[0],
36 number_of_frames * sizeof(*audio_data[0]));
32 37
33 return number_of_frames; 38 return number_of_frames;
34 } 39 }
35 40
36 void FakeAudioRenderCallback::NextFillValue() {
37 // Use irrationality of PI to fake random numbers; square fill_value_ to keep
38 // numbers between [0, 1) so range extension to [-1, 1) by 2 * x - 1 works.
39 fill_value_ = 2.0f * (static_cast<int>(
40 M_PI * fill_value_ * fill_value_ * kFakeRandomSeed) % kFakeRandomSeed) /
41 static_cast<float>(kFakeRandomSeed) - 1.0f;
42 }
43
44 } // namespace media 41 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698