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

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

Issue 10871051: Convert WebAudio file handlers to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 static scoped_ptr<AudioBus> WrapMemory(int channels, int frames, void* data); 42 static scoped_ptr<AudioBus> WrapMemory(int channels, int frames, void* data);
43 static scoped_ptr<AudioBus> WrapMemory(const AudioParameters& params, 43 static scoped_ptr<AudioBus> WrapMemory(const AudioParameters& params,
44 void* data); 44 void* data);
45 // Returns the required memory size to use the WrapMemory() method. 45 // Returns the required memory size to use the WrapMemory() method.
46 static int CalculateMemorySize(const AudioParameters& params); 46 static int CalculateMemorySize(const AudioParameters& params);
47 47
48 // Helper methods for converting an AudioBus from and to interleaved integer 48 // Helper methods for converting an AudioBus from and to interleaved integer
49 // data. Expects interleaving to be [ch0, ch1, ..., chN, ch0, ch1, ...] with 49 // data. Expects interleaving to be [ch0, ch1, ..., chN, ch0, ch1, ...] with
50 // |bytes_per_sample| per value. Values are scaled and bias corrected during 50 // |bytes_per_sample| per value. Values are scaled and bias corrected during
51 // conversion. ToInterleaved() will also clip values to format range. 51 // conversion. ToInterleaved() will also clip values to format range.
52 // Handles uint8, int16, and int32 currently. 52 // Handles uint8, int16, and int32 currently. FromInterleaved() will zero out
53 // any unfilled frames when |frames| is less than frames().
53 void FromInterleaved(const void* source, int frames, int bytes_per_sample); 54 void FromInterleaved(const void* source, int frames, int bytes_per_sample);
54 void ToInterleaved(int frames, int bytes_per_sample, void* dest) const; 55 void ToInterleaved(int frames, int bytes_per_sample, void* dest) const;
55 56
57 // Similar to FromInterleaved() above, but meant for streaming sources. Does
58 // not zero out remaining frames, the caller is responsible for doing so using
59 // ZeroFramesPartial(). Frames are deinterleaved from the start of |source|
60 // to channel(x)[start_frame].
61 void FromInterleavedPartial(const void* source, int start_frame, int frames,
62 int bytes_per_sample);
63
56 // Helper method for copying channel data from one AudioBus to another. Both 64 // Helper method for copying channel data from one AudioBus to another. Both
57 // AudioBus object must have the same frames() and channels(). 65 // AudioBus object must have the same frames() and channels().
58 void CopyTo(AudioBus* dest) const; 66 void CopyTo(AudioBus* dest) const;
59 67
60 // Returns a raw pointer to the requested channel. Pointer is guaranteed to 68 // Returns a raw pointer to the requested channel. Pointer is guaranteed to
61 // have a 16-byte alignment. 69 // have a 16-byte alignment.
62 float* channel(int channel) { return channel_data_[channel]; } 70 float* channel(int channel) { return channel_data_[channel]; }
63 const float* channel(int channel) const { return channel_data_[channel]; } 71 const float* channel(int channel) const { return channel_data_[channel]; }
64 72
65 int channels() const { return channel_data_.size(); } 73 int channels() const { return channel_data_.size(); }
66 int frames() const { return frames_; } 74 int frames() const { return frames_; }
67 75
68 // Helper method for zeroing out all channels of audio data. 76 // Helper method for zeroing out all channels of audio data.
69 void Zero(); 77 void Zero();
70 void ZeroFrames(int frames); 78 void ZeroFrames(int frames);
79 void ZeroFramesPartial(int start_frame, int frames);
71 80
72 private: 81 private:
73 friend class scoped_ptr<AudioBus>; 82 friend class scoped_ptr<AudioBus>;
74 ~AudioBus(); 83 ~AudioBus();
75 84
76 AudioBus(int channels, int frames); 85 AudioBus(int channels, int frames);
77 AudioBus(int channels, int frames, float* data); 86 AudioBus(int channels, int frames, float* data);
78 AudioBus(int frames, const std::vector<float*>& channel_data); 87 AudioBus(int frames, const std::vector<float*>& channel_data);
79 88
80 // Helper method for building |channel_data_| from a block of memory. |data| 89 // Helper method for building |channel_data_| from a block of memory. |data|
81 // must be at least BlockSize() bytes in size. 90 // must be at least BlockSize() bytes in size.
82 void BuildChannelData(int channels, int aligned_frame, float* data); 91 void BuildChannelData(int channels, int aligned_frame, float* data);
83 92
84 // Contiguous block of channel memory. 93 // Contiguous block of channel memory.
85 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; 94 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
86 95
87 std::vector<float*> channel_data_; 96 std::vector<float*> channel_data_;
88 int frames_; 97 int frames_;
89 98
90 DISALLOW_COPY_AND_ASSIGN(AudioBus); 99 DISALLOW_COPY_AND_ASSIGN(AudioBus);
91 }; 100 };
92 101
93 } // namespace media 102 } // namespace media
94 103
95 #endif // MEDIA_BASE_AUDIO_BUS_H_ 104 #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