diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 22:37:35 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 22:37:35 +0000 |
commit | 0bbca872a2407e598d4c9257700568c17f591e78 (patch) | |
tree | e414bdd9db2ba45bebf0e5724daad6c4c6728918 /media/audio/simple_sources.cc | |
parent | 5d5f7e314f9b4997c0f02cc2bc0e12f6c227f398 (diff) | |
download | chromium_src-0bbca872a2407e598d4c9257700568c17f591e78.zip chromium_src-0bbca872a2407e598d4c9257700568c17f591e78.tar.gz chromium_src-0bbca872a2407e598d4c9257700568c17f591e78.tar.bz2 |
Second part of the low level audio for Mac
-Fixed leaks (audiomanager singleton, audiostream)
-Moved simple_sources to be common for all platforms
-Added trivial check for sinesource
-Added some logic on the audio callback, not used yet
Review URL: http://codereview.chromium.org/67058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/simple_sources.cc')
-rw-r--r-- | media/audio/simple_sources.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/media/audio/simple_sources.cc b/media/audio/simple_sources.cc new file mode 100644 index 0000000..b6fda23 --- /dev/null +++ b/media/audio/simple_sources.cc @@ -0,0 +1,43 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <math.h> + +#include "base/basictypes.h" +#include "base/logging.h" +#include "media/audio/audio_output.h" +#include "media/audio/simple_sources.h" + +SineWaveAudioSource::SineWaveAudioSource(Format format, int channels, + double freq, double sample_freq) + : format_(format), + channels_(channels), + freq_(freq), + sample_freq_(sample_freq) { + // TODO(cpu): support other formats. + DCHECK((format_ == FORMAT_16BIT_LINEAR_PCM) && (channels_ == 1)); +} + +// The implementation could be more efficient if a lookup table is constructed +// but it is efficient enough for our simple needs. +size_t SineWaveAudioSource::OnMoreData(AudioOutputStream* stream, + void* dest, size_t max_size) { + const double kTwoPi = 2.0 * 3.141592653589; + double f = freq_ / sample_freq_; + int16* sin_tbl = reinterpret_cast<int16*>(dest); + size_t len = max_size / sizeof(int16); + // The table is filled with s(t) = 32768*sin(2PI*f*t). + for (size_t ix = 0; ix != len; ++ix) { + double th = kTwoPi * ix * f; + sin_tbl[ix] = static_cast<int16>((1 << 15) * sin(th)); + } + return max_size; +} + +void SineWaveAudioSource::OnClose(AudioOutputStream* stream) { +} + +void SineWaveAudioSource::OnError(AudioOutputStream* stream, int code) { + NOTREACHED(); +} |