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

Unified Diff: media/base/audio_bus.h

Issue 10824304: Upgrade AudioBus to support wrapping, interleaving. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lint. Created 8 years, 4 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.h
diff --git a/media/base/audio_bus.h b/media/base/audio_bus.h
index 0dff19576dde5c5129b206daa2076b689918647b..80ea4776cf6b53bcfae69cf8cb044e3c7f611f3d 100644
--- a/media/base/audio_bus.h
+++ b/media/base/audio_bus.h
@@ -32,12 +32,28 @@ class MEDIA_EXPORT AudioBus {
static scoped_ptr<AudioBus> WrapVector(
int frames, const std::vector<float*>& channel_data);
+ // Creates a new AudioBus by wrapping an existing block of memory. Block must
+ // be large enough to hold ExpectedDataSize() bytes of memory. |data| must
+ // outlive the returned AudioBus.
+ static scoped_ptr<AudioBus> WrapBlock(int channels, int frames, void* data);
henrika (OOO until Aug 14) 2012/08/15 09:59:37 I have actually never really understood why we nee
DaleCurtis 2012/08/15 19:16:47 These are necessary to save a memcpy between the A
+ static scoped_ptr<AudioBus> WrapBlock(const AudioParameters& params,
+ void* data);
+
+ // Returns the data_size() of an AudioBus created with the given parameters.
+ static int ExpectedDataSize(int channels, int frames);
henrika (OOO until Aug 14) 2012/08/15 09:59:37 Hope this is not a stupid comment but, "expected"
DaleCurtis 2012/08/15 19:16:47 Agreed, I don't like it either :) Will keep thinki
Chris Rogers 2012/08/15 19:39:31 How about CalculateSize() or CalculateDataSize() o
DaleCurtis 2012/08/16 01:54:14 Since this method is intended to be used with Wrap
+ static int ExpectedDataSize(const AudioParameters& params);
+
// Returns a raw pointer to internal channel data. Useful for copying state
// between two AudioBus objects created with the same parameters. data_size()
// is in bytes. Can not be used with an AudioBus constructed via wrapping.
void* data();
int data_size() const;
+ // Helper methods for working with interleaved data. Expects interleaving to
+ // be [ch0, ch1, ..., chN, ch0, ch1, ...] with |bytes_per_channel| per value.
+ void FromInterleaved(const void* source, int frames, int bytes_per_channel);
henrika (OOO until Aug 14) 2012/08/15 09:59:37 Signature is not inline with the function definiti
DaleCurtis 2012/08/16 01:54:14 Done.
+ void ToInterleaved(void* dest, int frames, int bytes_per_channel);
+
// Returns a raw pointer to the requested channel. Pointer is guaranteed to
// have a 16-byte alignment.
float* channel(int channel) { return channel_data_[channel]; }
@@ -46,6 +62,10 @@ class MEDIA_EXPORT AudioBus {
int channels() const { return channel_data_.size(); }
int frames() const { return frames_; }
+ // Output sample rate for the frames in this buffer. Can only be used with
DaleCurtis 2012/08/15 05:18:44 I actually don't like this and pending discussion
henrika (OOO until Aug 14) 2012/08/15 09:59:37 "Output sample rate": not sure if it is a good ide
DaleCurtis 2012/08/15 19:16:47 I'm pretty confident this can be removed now. I'll
+ // an AudioBus created via AudioParameters.
+ int sample_rate() const;
+
// Helper method for zeroing out all channels of audio data.
void Zero();
void ZeroFrames(int frames);
@@ -54,9 +74,17 @@ class MEDIA_EXPORT AudioBus {
friend class scoped_ptr<AudioBus>;
~AudioBus();
- AudioBus(int channels, int frames);
+ AudioBus(int channels, int frames, int sample_rate);
+ AudioBus(int channels, int frames, int sample_rate, float* data);
AudioBus(int frames, const std::vector<float*>& channel_data);
+ // Helper method for building |channel_data_| from a block of memory. |data|
+ // must be at least ExpectedDataSize() bytes in size.
+ void BuildChannelData(int channels, int aligned_frame, float* data);
+
+ // Helper method for validating construction parameters.
+ void ValidateConfig(int channels, int frames, int sample_rate);
+
// Contiguous block of channel memory.
scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
int data_size_;
@@ -64,6 +92,9 @@ class MEDIA_EXPORT AudioBus {
std::vector<float*> channel_data_;
int frames_;
+ // Output sample rate of the data contained in the bus.
henrika (OOO until Aug 14) 2012/08/15 09:59:37 ditto
DaleCurtis 2012/08/16 01:54:14 Removed.
+ int sample_rate_;
+
DISALLOW_COPY_AND_ASSIGN(AudioBus);
};
« no previous file with comments | « media/audio/audio_util.cc ('k') | media/base/audio_bus.cc » ('j') | media/base/audio_bus.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698