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. Each channel is |
| 18 // stored in planar format and guaranteed to have a 16-byte alignment. AudioBus |
| 19 // objects can be created normally or via wrapping. Normally, AudioBus will |
| 20 // dice up a contiguous memory block for channel data. When wrapped, AudioBus |
| 21 // instead routes requests for channel data to the wrapped object. |
| 22 class MEDIA_EXPORT AudioBus { |
| 23 public: |
| 24 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses |
| 25 // channels() and frames_per_buffer() if given an AudioParameters object. |
| 26 static scoped_ptr<AudioBus> Create(int channels, int frames); |
| 27 static scoped_ptr<AudioBus> Create(const AudioParameters& params); |
| 28 |
| 29 // Creates a new AudioBus from an existing channel vector. Does not transfer |
| 30 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive |
| 31 // the returned AudioBus. Each channel pointer must be 16-byte aligned. |
| 32 static scoped_ptr<AudioBus> WrapVector( |
| 33 int frames, const std::vector<float*>& channel_data); |
| 34 |
| 35 // Returns a raw pointer to internal channel data. Useful for copying state |
| 36 // between two AudioBus objects created with the same parameters. data_size() |
| 37 // is in bytes. Can not be used with an AudioBus constructed via wrapping. |
| 38 void* data(); |
| 39 int data_size() const; |
| 40 |
| 41 // Returns a raw pointer to the requested channel. Pointer is guaranteed to |
| 42 // have a 16-byte alignment. |
| 43 float* channel(int channel) { return channel_data_[channel]; } |
| 44 const float* channel(int channel) const { return channel_data_[channel]; } |
| 45 |
| 46 int channels() const { return channel_data_.size(); } |
| 47 int frames() const { return frames_; } |
| 48 |
| 49 // Helper method for zeroing out all channels of audio data. |
| 50 void Zero(); |
| 51 void ZeroFrames(int frames); |
| 52 |
| 53 private: |
| 54 friend class scoped_ptr<AudioBus>; |
| 55 ~AudioBus(); |
| 56 |
| 57 AudioBus(int channels, int frames); |
| 58 AudioBus(int frames, const std::vector<float*>& channel_data); |
| 59 |
| 60 // Contiguous block of channel memory. |
| 61 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; |
| 62 int data_size_; |
| 63 |
| 64 std::vector<float*> channel_data_; |
| 65 int frames_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(AudioBus); |
| 68 }; |
| 69 |
| 70 } // namespace media |
| 71 |
| 72 #endif // MEDIA_BASE_AUDIO_BUS_H_ |
OLD | NEW |