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

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: Comments. 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() from AudioParameters if given.
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 BlockSize() bytes of memory. |data| must outlive
37 // the returned AudioBus.
38 static scoped_ptr<AudioBus> WrapBlock(int channels, int frames, void* data);
scherkus (not reviewing) 2012/08/16 18:58:19 WrapData? "Block" isn't a very widely used term a
DaleCurtis 2012/08/16 19:50:33 Agreed, ideally we'd have no Wrap methods :) Since
DaleCurtis 2012/08/17 02:15:58 Pared these down a bit to only the known use cases
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 BlockSize(int channels, int frames);
scherkus (not reviewing) 2012/08/16 18:58:19 try to use verbs for functions -- this should be C
DaleCurtis 2012/08/17 02:15:58 Done.
44 static int BlockSize(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 converting an AudioBus from and to interleaved integer
53 // data. Expects interleaving to be [ch0, ch1, ..., chN, ch0, ch1, ...] with
54 // |bytes_per_sample| per value. Values are scaled and bias corrected during
55 // conversion. ToInterleaved will also clip values to format range. Handles
scherkus (not reviewing) 2012/08/16 18:58:19 ToInterleaved()
DaleCurtis 2012/08/17 02:15:58 Done.
56 // uint8, int16, and int32 currently.
57 void FromInterleaved(const void* source, int frames, int bytes_per_sample);
scherkus (not reviewing) 2012/08/16 18:58:19 at some point in time it would be *fantastic* if w
DaleCurtis 2012/08/16 19:50:33 Yeah, I've been thinking the same thing. However,
58 void ToInterleaved(int frames, int bytes_per_sample, void* dest);
59
41 // Returns a raw pointer to the requested channel. Pointer is guaranteed to 60 // Returns a raw pointer to the requested channel. Pointer is guaranteed to
42 // have a 16-byte alignment. 61 // have a 16-byte alignment.
43 float* channel(int channel) { return channel_data_[channel]; } 62 float* channel(int channel) { return channel_data_[channel]; }
44 const float* channel(int channel) const { return channel_data_[channel]; } 63 const float* channel(int channel) const { return channel_data_[channel]; }
45 64
46 int channels() const { return channel_data_.size(); } 65 int channels() const { return channel_data_.size(); }
47 int frames() const { return frames_; } 66 int frames() const { return frames_; }
48 67
49 // Helper method for zeroing out all channels of audio data. 68 // Helper method for zeroing out all channels of audio data.
50 void Zero(); 69 void Zero();
51 void ZeroFrames(int frames); 70 void ZeroFrames(int frames);
52 71
53 private: 72 private:
54 friend class scoped_ptr<AudioBus>; 73 friend class scoped_ptr<AudioBus>;
55 ~AudioBus(); 74 ~AudioBus();
56 75
57 AudioBus(int channels, int frames); 76 AudioBus(int channels, int frames);
77 AudioBus(int channels, int frames, float* data);
58 AudioBus(int frames, const std::vector<float*>& channel_data); 78 AudioBus(int frames, const std::vector<float*>& channel_data);
59 79
80 // Helper method for building |channel_data_| from a block of memory. |data|
81 // must be at least BlockSize() bytes in size.
82 void BuildChannelData(int channels, int aligned_frame, float* data);
83
84 // Helper method for validating construction parameters.
85 void ValidateConfig(int channels, int frames);
scherkus (not reviewing) 2012/08/16 18:58:19 const method
DaleCurtis 2012/08/17 02:15:58 Moved to static, not really any point to have it i
86
60 // Contiguous block of channel memory. 87 // Contiguous block of channel memory.
61 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; 88 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
62 int data_size_; 89 int data_size_;
63 90
64 std::vector<float*> channel_data_; 91 std::vector<float*> channel_data_;
65 int frames_; 92 int frames_;
66 93
67 DISALLOW_COPY_AND_ASSIGN(AudioBus); 94 DISALLOW_COPY_AND_ASSIGN(AudioBus);
68 }; 95 };
69 96
70 } // namespace media 97 } // namespace media
71 98
72 #endif // MEDIA_BASE_AUDIO_BUS_H_ 99 #endif // MEDIA_BASE_AUDIO_BUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698