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

Side by Side 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: Line endings? 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/audio_bus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698