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

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

Issue 10824304: Upgrade AudioBus to support wrapping, interleaving. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lint. 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
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
13 13
14 namespace media { 14 namespace media {
15 class AudioParameters; 15 class AudioParameters;
16 16
17 // Scoped container for "busing" audio channel data around. Each channel is 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 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 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 20 // dice up a contiguous memory block for channel data. When wrapped, AudioBus
21 // instead routes requests for channel data to the wrapped object. 21 // instead routes requests for channel data to the wrapped object.
22 class MEDIA_EXPORT AudioBus { 22 class MEDIA_EXPORT AudioBus {
23 public: 23 public:
24 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses 24 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses
25 // channels() and frames_per_buffer() if given an AudioParameters object. 25 // channels() and frames_per_buffer() if given an AudioParameters object.
henrika (OOO until Aug 14) 2012/08/15 09:59:37 nit, channels() and frames_per_buffer() can also m
DaleCurtis 2012/08/16 01:54:14 Reworded, sample rate dropped.
26 static scoped_ptr<AudioBus> Create(int channels, int frames); 26 static scoped_ptr<AudioBus> Create(int channels, int frames);
27 static scoped_ptr<AudioBus> Create(const AudioParameters& params); 27 static scoped_ptr<AudioBus> Create(const AudioParameters& params);
28 28
29 // Creates a new AudioBus from an existing channel vector. Does not transfer 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 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. 31 // the returned AudioBus. Each channel pointer must be 16-byte aligned.
32 static scoped_ptr<AudioBus> WrapVector( 32 static scoped_ptr<AudioBus> WrapVector(
33 int frames, const std::vector<float*>& channel_data); 33 int frames, const std::vector<float*>& channel_data);
34 34
35 // Creates a new AudioBus by wrapping an existing block of memory. Block must
36 // be large enough to hold ExpectedDataSize() bytes of memory. |data| must
37 // outlive the returned AudioBus.
38 static scoped_ptr<AudioBus> WrapBlock(int channels, int frames, void* data);
henrika (OOO until Aug 14) 2012/08/15 09:59:37 I have actually never really understood why we nee
DaleCurtis 2012/08/15 19:16:47 These are necessary to save a memcpy between the A
39 static scoped_ptr<AudioBus> WrapBlock(const AudioParameters& params,
40 void* data);
41
42 // Returns the data_size() of an AudioBus created with the given parameters.
43 static int ExpectedDataSize(int channels, int frames);
henrika (OOO until Aug 14) 2012/08/15 09:59:37 Hope this is not a stupid comment but, "expected"
DaleCurtis 2012/08/15 19:16:47 Agreed, I don't like it either :) Will keep thinki
Chris Rogers 2012/08/15 19:39:31 How about CalculateSize() or CalculateDataSize() o
DaleCurtis 2012/08/16 01:54:14 Since this method is intended to be used with Wrap
44 static int ExpectedDataSize(const AudioParameters& params);
45
35 // Returns a raw pointer to internal channel data. Useful for copying state 46 // Returns a raw pointer to internal channel data. Useful for copying state
36 // between two AudioBus objects created with the same parameters. data_size() 47 // 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. 48 // is in bytes. Can not be used with an AudioBus constructed via wrapping.
38 void* data(); 49 void* data();
39 int data_size() const; 50 int data_size() const;
40 51
52 // Helper methods for working with interleaved data. Expects interleaving to
53 // be [ch0, ch1, ..., chN, ch0, ch1, ...] with |bytes_per_channel| per value.
54 void FromInterleaved(const void* source, int frames, int bytes_per_channel);
henrika (OOO until Aug 14) 2012/08/15 09:59:37 Signature is not inline with the function definiti
DaleCurtis 2012/08/16 01:54:14 Done.
55 void ToInterleaved(void* dest, int frames, int bytes_per_channel);
56
41 // Returns a raw pointer to the requested channel. Pointer is guaranteed to 57 // Returns a raw pointer to the requested channel. Pointer is guaranteed to
42 // have a 16-byte alignment. 58 // have a 16-byte alignment.
43 float* channel(int channel) { return channel_data_[channel]; } 59 float* channel(int channel) { return channel_data_[channel]; }
44 const float* channel(int channel) const { return channel_data_[channel]; } 60 const float* channel(int channel) const { return channel_data_[channel]; }
45 61
46 int channels() const { return channel_data_.size(); } 62 int channels() const { return channel_data_.size(); }
47 int frames() const { return frames_; } 63 int frames() const { return frames_; }
48 64
65 // Output sample rate for the frames in this buffer. Can only be used with
DaleCurtis 2012/08/15 05:18:44 I actually don't like this and pending discussion
henrika (OOO until Aug 14) 2012/08/15 09:59:37 "Output sample rate": not sure if it is a good ide
DaleCurtis 2012/08/15 19:16:47 I'm pretty confident this can be removed now. I'll
66 // an AudioBus created via AudioParameters.
67 int sample_rate() const;
68
49 // Helper method for zeroing out all channels of audio data. 69 // Helper method for zeroing out all channels of audio data.
50 void Zero(); 70 void Zero();
51 void ZeroFrames(int frames); 71 void ZeroFrames(int frames);
52 72
53 private: 73 private:
54 friend class scoped_ptr<AudioBus>; 74 friend class scoped_ptr<AudioBus>;
55 ~AudioBus(); 75 ~AudioBus();
56 76
57 AudioBus(int channels, int frames); 77 AudioBus(int channels, int frames, int sample_rate);
78 AudioBus(int channels, int frames, int sample_rate, float* data);
58 AudioBus(int frames, const std::vector<float*>& channel_data); 79 AudioBus(int frames, const std::vector<float*>& channel_data);
59 80
81 // Helper method for building |channel_data_| from a block of memory. |data|
82 // must be at least ExpectedDataSize() bytes in size.
83 void BuildChannelData(int channels, int aligned_frame, float* data);
84
85 // Helper method for validating construction parameters.
86 void ValidateConfig(int channels, int frames, int sample_rate);
87
60 // Contiguous block of channel memory. 88 // Contiguous block of channel memory.
61 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; 89 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
62 int data_size_; 90 int data_size_;
63 91
64 std::vector<float*> channel_data_; 92 std::vector<float*> channel_data_;
65 int frames_; 93 int frames_;
66 94
95 // Output sample rate of the data contained in the bus.
henrika (OOO until Aug 14) 2012/08/15 09:59:37 ditto
DaleCurtis 2012/08/16 01:54:14 Removed.
96 int sample_rate_;
97
67 DISALLOW_COPY_AND_ASSIGN(AudioBus); 98 DISALLOW_COPY_AND_ASSIGN(AudioBus);
68 }; 99 };
69 100
70 } // namespace media 101 } // namespace media
71 102
72 #endif // MEDIA_BASE_AUDIO_BUS_H_ 103 #endif // MEDIA_BASE_AUDIO_BUS_H_
OLDNEW
« no previous file with comments | « media/audio/audio_util.cc ('k') | media/base/audio_bus.cc » ('j') | media/base/audio_bus.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698