Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BASE_AUDIO_BUS_H_ | |
| 6 #define MEDIA_BASE_AUDIO_BUS_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/aligned_memory.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "media/base/media_export.h" | |
| 13 | |
| 14 namespace media { | |
| 15 class AudioParameters; | |
| 16 | |
| 17 // 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.
| |
| 18 class MEDIA_EXPORT AudioBus { | |
| 19 public: | |
| 20 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses | |
| 21 // 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.
| |
| 22 static scoped_ptr<AudioBus> Create(int channels, int frames); | |
| 23 static scoped_ptr<AudioBus> Create(const AudioParameters& params); | |
| 24 | |
| 25 // Creates a new AudioBus from an existing channel vector. Does not transfer | |
| 26 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive | |
| 27 // the returned AudioBus. | |
| 28 static scoped_ptr<AudioBus> WrapVector( | |
| 29 int frames, const std::vector<float*>& channel_data); | |
| 30 | |
| 31 // Returns a raw pointer to internal channel data. Useful for copying state | |
| 32 // 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.
| |
| 33 // is in bytes. Can not be used with an AudioBus constructed via wrapping. | |
| 34 void* data() const; | |
| 35 int data_size() const; | |
| 36 | |
| 37 // Returns a raw pointer to the requested channel. Pointer is guaranteed to | |
| 38 // have a 16-byte alignment. | |
| 39 float* channel(int channel) const { return channel_data_[channel]; } | |
| 40 | |
| 41 int channels() const { return channel_data_.size(); } | |
| 42 int frames() const { return frames_; } | |
| 43 | |
| 44 // Helper method for zeroing out all channels of audio data. | |
| 45 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
| |
| 46 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.
| |
| 47 | |
| 48 private: | |
| 49 friend class scoped_ptr<AudioBus>; | |
| 50 ~AudioBus(); | |
| 51 | |
| 52 AudioBus(int channels, int frames); | |
| 53 AudioBus(int frames, const std::vector<float*>& channel_data); | |
| 54 | |
| 55 // Contiguous block of channel memory. | |
| 56 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; | |
| 57 int data_size_; | |
| 58 | |
| 59 // 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.
| |
| 60 std::vector<float*> channel_data_; | |
| 61 int frames_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(AudioBus); | |
| 64 }; | |
| 65 | |
| 66 } // namespace media | |
| 67 | |
| 68 #endif // MEDIA_BASE_AUDIO_BUS_H_ | |
| OLD | NEW |