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

Unified Diff: media/base/audio_bus.h

Issue 10829183: Introduce AudioBus to replace std::vector<float*>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. 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
« no previous file with comments | « no previous file | media/base/audio_bus.cc » ('j') | media/base/audio_bus.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_bus.h
diff --git a/media/base/audio_bus.h b/media/base/audio_bus.h
new file mode 100644
index 0000000000000000000000000000000000000000..2cc2f093287b36a4d4feeff13e57f1a5847d43ad
--- /dev/null
+++ b/media/base/audio_bus.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 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.
+
+#ifndef MEDIA_BASE_AUDIO_BUS_H_
+#define MEDIA_BASE_AUDIO_BUS_H_
+
+#include <vector>
+
+#include "base/memory/aligned_memory.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/base/media_export.h"
+
+namespace media {
+class AudioParameters;
+
+// Scoped container for "busing" audio channel data around.
scherkus (not reviewing) 2012/08/07 02:51:16 I'd expand this a tiny bit more to talk about memo
DaleCurtis 2012/08/07 18:29:45 Done.
+class MEDIA_EXPORT AudioBus {
+ public:
+ // Creates a new AudioBus and allocates |channels| of length |frames|. Uses
+ // channels() and frames_per_buffer() if an AudioParameters class is provided.
scherkus (not reviewing) 2012/08/07 02:51:16 s/class/object/
DaleCurtis 2012/08/07 18:29:45 Done.
+ static scoped_ptr<AudioBus> Create(int channels, int frames);
+ static scoped_ptr<AudioBus> Create(const AudioParameters& params);
+
+ // Creates a new AudioBus from an existing channel vector. Does not transfer
+ // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive
+ // the returned AudioBus.
+ static scoped_ptr<AudioBus> WrapVector(
+ int frames, const std::vector<float*>& channel_data);
+
+ // Returns a raw pointer to internal channel data. Useful for copying state
+ // between two AudioBus object created with the same parameters. data_size()
scherkus (not reviewing) 2012/08/07 02:51:16 s/object/objects/
DaleCurtis 2012/08/07 18:29:45 Done.
+ // is in bytes. Can not be used with an AudioBus constructed via wrapping.
+ void* data() const;
+ int data_size() const;
+
+ // Returns a raw pointer to the requested channel. Pointer is guaranteed to
+ // have a 16-byte alignment.
+ float* channel(int channel) const { return channel_data_[channel]; }
+
+ int channels() const { return channel_data_.size(); }
+ int frames() const { return frames_; }
+
+ // Helper method for zeroing out all channels of audio data.
+ void ZeroFrames(int frames) const;
scherkus (not reviewing) 2012/08/07 02:51:16 the const attribute here is completely misleading
DaleCurtis 2012/08/07 18:29:45 We don't for this method, I just went overboard wi
+ void Zero() const { ZeroFrames(frames_); }
scherkus (not reviewing) 2012/08/07 02:51:16 nit: I'd deinline this -- it's technically not a s
DaleCurtis 2012/08/07 18:29:45 Done.
+
+ private:
+ friend class scoped_ptr<AudioBus>;
+ ~AudioBus();
+
+ AudioBus(int channels, int frames);
+ AudioBus(int frames, const std::vector<float*>& channel_data);
+
+ // Contiguous block of channel memory.
+ scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
+ int data_size_;
+
+ // Vector of pointers to each channel's audio data.
scherkus (not reviewing) 2012/08/07 02:51:16 with channel_data_ I think this comment is no long
DaleCurtis 2012/08/07 18:29:45 Done.
+ std::vector<float*> channel_data_;
+ int frames_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioBus);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_AUDIO_BUS_H_
« no previous file with comments | « no previous file | media/base/audio_bus.cc » ('j') | media/base/audio_bus.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698