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

Side by Side Diff: media/base/audio_bus.h

Issue 10909185: Add Mac OS X synchronized audio I/O back-end (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_AUDIO_BUS_H_ 5 #ifndef MEDIA_BASE_AUDIO_BUS_H_
6 #define MEDIA_BASE_AUDIO_BUS_H_ 6 #define MEDIA_BASE_AUDIO_BUS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/aligned_memory.h" 10 #include "base/memory/aligned_memory.h"
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 // Guaranteed alignment of each channel's data; use 16-byte alignment for easy 24 // Guaranteed alignment of each channel's data; use 16-byte alignment for easy
25 // SSE optimizations. 25 // SSE optimizations.
26 enum { kChannelAlignment = 16 }; 26 enum { kChannelAlignment = 16 };
27 27
28 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses 28 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses
29 // channels() and frames_per_buffer() from AudioParameters if given. 29 // channels() and frames_per_buffer() from AudioParameters if given.
30 static scoped_ptr<AudioBus> Create(int channels, int frames); 30 static scoped_ptr<AudioBus> Create(int channels, int frames);
31 static scoped_ptr<AudioBus> Create(const AudioParameters& params); 31 static scoped_ptr<AudioBus> Create(const AudioParameters& params);
32 32
33 // Creates a new AudioBus with the given number of channels, but zero length.
34 // It's expected to be used with SetChannelData() and set_frames() to
35 // wrap externally allocated memory.
36 static scoped_ptr<AudioBus> CreateWrapper(int channels);
37
33 // Creates a new AudioBus from an existing channel vector. Does not transfer 38 // Creates a new AudioBus from an existing channel vector. Does not transfer
34 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive 39 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive
35 // the returned AudioBus. Each channel must be aligned by kChannelAlignment. 40 // the returned AudioBus. Each channel must be aligned by kChannelAlignment.
36 static scoped_ptr<AudioBus> WrapVector( 41 static scoped_ptr<AudioBus> WrapVector(
37 int frames, const std::vector<float*>& channel_data); 42 int frames, const std::vector<float*>& channel_data);
38 43
39 // Creates a new AudioBus by wrapping an existing block of memory. Block must 44 // Creates a new AudioBus by wrapping an existing block of memory. Block must
40 // be at least CalculateMemorySize() bytes in size. |data| must outlive the 45 // be at least CalculateMemorySize() bytes in size. |data| must outlive the
41 // returned AudioBus. |data| must be aligned by kChannelAlignment. 46 // returned AudioBus. |data| must be aligned by kChannelAlignment.
42 static scoped_ptr<AudioBus> WrapMemory(int channels, int frames, void* data); 47 static scoped_ptr<AudioBus> WrapMemory(int channels, int frames, void* data);
(...skipping 24 matching lines...) Expand all
67 72
68 // Helper method for copying channel data from one AudioBus to another. Both 73 // Helper method for copying channel data from one AudioBus to another. Both
69 // AudioBus object must have the same frames() and channels(). 74 // AudioBus object must have the same frames() and channels().
70 void CopyTo(AudioBus* dest) const; 75 void CopyTo(AudioBus* dest) const;
71 76
72 // Returns a raw pointer to the requested channel. Pointer is guaranteed to 77 // Returns a raw pointer to the requested channel. Pointer is guaranteed to
73 // have a 16-byte alignment. Warning: Do not rely on having sane (i.e. not 78 // have a 16-byte alignment. Warning: Do not rely on having sane (i.e. not
74 // inf, nan, or between [-1.0, 1.0]) values in the channel data. 79 // inf, nan, or between [-1.0, 1.0]) values in the channel data.
75 float* channel(int channel) { return channel_data_[channel]; } 80 float* channel(int channel) { return channel_data_[channel]; }
76 const float* channel(int channel) const { return channel_data_[channel]; } 81 const float* channel(int channel) const { return channel_data_[channel]; }
82 void SetChannelData(int channel, float* data);
77 83
78 int channels() const { return channel_data_.size(); } 84 int channels() const { return channel_data_.size(); }
79 int frames() const { return frames_; } 85 int frames() const { return frames_; }
86 void set_frames(int frames);
80 87
81 // Helper method for zeroing out all channels of audio data. 88 // Helper method for zeroing out all channels of audio data.
82 void Zero(); 89 void Zero();
83 void ZeroFrames(int frames); 90 void ZeroFrames(int frames);
84 void ZeroFramesPartial(int start_frame, int frames); 91 void ZeroFramesPartial(int start_frame, int frames);
85 92
86 private: 93 private:
87 friend class scoped_ptr<AudioBus>; 94 friend class scoped_ptr<AudioBus>;
88 ~AudioBus(); 95 ~AudioBus();
89 96
90 AudioBus(int channels, int frames); 97 AudioBus(int channels, int frames);
91 AudioBus(int channels, int frames, float* data); 98 AudioBus(int channels, int frames, float* data);
92 AudioBus(int frames, const std::vector<float*>& channel_data); 99 AudioBus(int frames, const std::vector<float*>& channel_data);
100 explicit AudioBus(int channels);
93 101
94 // Helper method for building |channel_data_| from a block of memory. |data| 102 // Helper method for building |channel_data_| from a block of memory. |data|
95 // must be at least BlockSize() bytes in size. 103 // must be at least BlockSize() bytes in size.
96 void BuildChannelData(int channels, int aligned_frame, float* data); 104 void BuildChannelData(int channels, int aligned_frame, float* data);
97 105
98 // Contiguous block of channel memory. 106 // Contiguous block of channel memory.
99 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; 107 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
100 108
101 std::vector<float*> channel_data_; 109 std::vector<float*> channel_data_;
102 int frames_; 110 int frames_;
103 111
112 // Protect SetChannelData() and set_frames() for use by CreateWrapper().
113 bool can_set_channel_data_;
114
104 DISALLOW_COPY_AND_ASSIGN(AudioBus); 115 DISALLOW_COPY_AND_ASSIGN(AudioBus);
105 }; 116 };
106 117
107 } // namespace media 118 } // namespace media
108 119
109 #endif // MEDIA_BASE_AUDIO_BUS_H_ 120 #endif // MEDIA_BASE_AUDIO_BUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698