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

Unified Diff: media/base/audio_bus.cc

Issue 10830268: Allow audio system to handle synchronized low-latency audio I/O (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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: media/base/audio_bus.cc
===================================================================
--- media/base/audio_bus.cc (revision 155437)
+++ media/base/audio_bus.cc (working copy)
@@ -17,19 +17,6 @@
(AudioBus::kChannelAlignment - 1)) == 0U;
}
-// Calculates the required size for an AudioBus with the given params, sets
-// |aligned_frames| to the actual frame length of each channel array.
-static int CalculateMemorySizeInternal(int channels, int frames,
- int* aligned_frames) {
- CHECK(aligned_frames);
- // Choose a size such that each channel will be aligned by kChannelAlignment
- // when stored in a contiguous block.
- *aligned_frames =
- ((frames * sizeof(float) + AudioBus::kChannelAlignment - 1) &
- ~(AudioBus::kChannelAlignment - 1)) / sizeof(float);
- return sizeof(float) * channels * (*aligned_frames);
-}
-
// |Format| is the destination type, |Fixed| is a type larger than |Format|
// such that operations can be made without overflowing.
template<class Format, class Fixed>
@@ -106,7 +93,7 @@
ValidateConfig(channels, frames_);
int aligned_frames = 0;
- int size = CalculateMemorySizeInternal(channels, frames, &aligned_frames);
+ int size = CalculateMemorySizeFromChannels(channels, frames, &aligned_frames);
data_.reset(static_cast<float*>(base::AlignedAlloc(
size, AudioBus::kChannelAlignment)));
@@ -119,7 +106,7 @@
ValidateConfig(channels, frames_);
int aligned_frames = 0;
- CalculateMemorySizeInternal(channels, frames, &aligned_frames);
+ CalculateMemorySizeFromChannels(channels, frames, &aligned_frames);
BuildChannelData(channels, aligned_frames, data);
}
@@ -187,9 +174,25 @@
ZeroFrames(frames_);
}
+// Calculates the required size for an AudioBus with the given params, sets
+// |aligned_frames| to the actual frame length of each channel array.
+int AudioBus::CalculateMemorySizeFromChannels(int channels, int frames,
+ int* out_aligned_frames) {
+ // Choose a size such that each channel will be aligned by
+ // kChannelAlignment when stored in a contiguous block.
+ int aligned_frames =
+ ((frames * sizeof(float) + AudioBus::kChannelAlignment - 1) &
+ ~(AudioBus::kChannelAlignment - 1)) / sizeof(float);
+
+ if (out_aligned_frames)
+ *out_aligned_frames = aligned_frames;
+
+ return sizeof(float) * channels * aligned_frames;
+}
+
int AudioBus::CalculateMemorySize(const AudioParameters& params) {
int aligned_frames = 0;
- return CalculateMemorySizeInternal(
+ return CalculateMemorySizeFromChannels(
params.channels(), params.frames_per_buffer(), &aligned_frames);
}

Powered by Google App Engine
This is Rietveld 408576698