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

Unified Diff: ppapi/native_client/tests/ppapi_example_audio/audio.cc

Issue 9129007: Work on improving PpbAudioConfig:RecommendSampleFrameCount (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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
Index: ppapi/native_client/tests/ppapi_example_audio/audio.cc
===================================================================
--- ppapi/native_client/tests/ppapi_example_audio/audio.cc (revision 122585)
+++ ppapi/native_client/tests/ppapi_example_audio/audio.cc (working copy)
@@ -35,12 +35,6 @@
const double kDefaultFrequencyRight = 1000.0;
const uint32_t kDefaultDuration = 10000;
-// This sample frequency is guaranteed to work.
-const PP_AudioSampleRate kSampleFrequency = PP_AUDIOSAMPLERATE_44100;
-// Buffer size in units of sample frames.
-// 4096 is a conservative size that should avoid underruns on most systems.
-const uint32_t kSampleFrameCount = 4096;
-
const double kPi = 3.141592653589;
const double kTwoPi = 2.0 * kPi;
@@ -198,11 +192,13 @@
}
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
+ const int32_t kSampleFrameCount = 2048;
ParseArgs(argc, argn, argv);
+ obtained_sample_rate_ = pp::AudioConfig::RecommendSampleRate(this);
obtained_sample_frame_count_ = pp::AudioConfig::RecommendSampleFrameCount(
- kSampleFrequency, kSampleFrameCount);
- config_ = new
- pp::AudioConfig(this, kSampleFrequency, obtained_sample_frame_count_);
+ this, obtained_sample_rate_, kSampleFrameCount);
+ config_ = new pp::AudioConfig(
+ this, obtained_sample_rate_, obtained_sample_frame_count_);
CHECK(NULL != config_);
audio_ = new pp::Audio(this, *config_, SineWaveCallback, this);
CHECK(NULL != audio_);
@@ -214,8 +210,10 @@
private:
static void SineWaveCallback(void* samples, uint32_t num_bytes, void* thiz) {
MyInstance* instance = reinterpret_cast<MyInstance*>(thiz);
- const double delta_l = kTwoPi * instance->frequency_l_ / kSampleFrequency;
- const double delta_r = kTwoPi * instance->frequency_r_ / kSampleFrequency;
+ const double delta_l = kTwoPi * instance->frequency_l_ /
+ instance->obtained_sample_rate_;
+ const double delta_r = kTwoPi * instance->frequency_r_ /
+ instance->obtained_sample_rate_;
// Verify num_bytes and obtained_sample_frame_count match up.
const int kNumChannelsForStereo = 2;
@@ -277,6 +275,7 @@
bool stress_tests_;
uint32_t duration_msec_;
+ PP_AudioSampleRate obtained_sample_rate_;
uint32_t obtained_sample_frame_count_;
int callback_count_;

Powered by Google App Engine
This is Rietveld 408576698