OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 14 matching lines...) Expand all Loading... |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #ifndef AudioChannel_h | 29 #ifndef AudioChannel_h |
30 #define AudioChannel_h | 30 #define AudioChannel_h |
31 | 31 |
32 #include "platform/PlatformExport.h" | 32 #include "platform/PlatformExport.h" |
33 #include "platform/audio/AudioArray.h" | 33 #include "platform/audio/AudioArray.h" |
34 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
35 #include "wtf/PtrUtil.h" | 35 #include "wtf/PassOwnPtr.h" |
36 #include <memory> | |
37 | 36 |
38 namespace blink { | 37 namespace blink { |
39 | 38 |
40 // An AudioChannel represents a buffer of non-interleaved floating-point audio s
amples. | 39 // An AudioChannel represents a buffer of non-interleaved floating-point audio s
amples. |
41 // The PCM samples are normally assumed to be in a nominal range -1.0 -> +1.0 | 40 // The PCM samples are normally assumed to be in a nominal range -1.0 -> +1.0 |
42 class PLATFORM_EXPORT AudioChannel { | 41 class PLATFORM_EXPORT AudioChannel { |
43 USING_FAST_MALLOC(AudioChannel); | 42 USING_FAST_MALLOC(AudioChannel); |
44 WTF_MAKE_NONCOPYABLE(AudioChannel); | 43 WTF_MAKE_NONCOPYABLE(AudioChannel); |
45 public: | 44 public: |
46 // Memory can be externally referenced, or can be internally allocated with
an AudioFloatArray. | 45 // Memory can be externally referenced, or can be internally allocated with
an AudioFloatArray. |
47 | 46 |
48 // Reference an external buffer. | 47 // Reference an external buffer. |
49 AudioChannel(float* storage, size_t length) | 48 AudioChannel(float* storage, size_t length) |
50 : m_length(length) | 49 : m_length(length) |
51 , m_rawPointer(storage) | 50 , m_rawPointer(storage) |
52 , m_silent(false) | 51 , m_silent(false) |
53 { | 52 { |
54 } | 53 } |
55 | 54 |
56 // Manage storage for us. | 55 // Manage storage for us. |
57 explicit AudioChannel(size_t length) | 56 explicit AudioChannel(size_t length) |
58 : m_length(length) | 57 : m_length(length) |
59 , m_rawPointer(nullptr) | 58 , m_rawPointer(nullptr) |
60 , m_silent(true) | 59 , m_silent(true) |
61 { | 60 { |
62 m_memBuffer = wrapUnique(new AudioFloatArray(length)); | 61 m_memBuffer = adoptPtr(new AudioFloatArray(length)); |
63 } | 62 } |
64 | 63 |
65 // A "blank" audio channel -- must call set() before it's useful... | 64 // A "blank" audio channel -- must call set() before it's useful... |
66 AudioChannel() | 65 AudioChannel() |
67 : m_length(0) | 66 : m_length(0) |
68 , m_rawPointer(nullptr) | 67 , m_rawPointer(nullptr) |
69 , m_silent(true) | 68 , m_silent(true) |
70 { | 69 { |
71 } | 70 } |
72 | 71 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // Sums (with unity gain) from the source channel. | 126 // Sums (with unity gain) from the source channel. |
128 void sumFrom(const AudioChannel* sourceChannel); | 127 void sumFrom(const AudioChannel* sourceChannel); |
129 | 128 |
130 // Returns maximum absolute value (useful for normalization). | 129 // Returns maximum absolute value (useful for normalization). |
131 float maxAbsValue() const; | 130 float maxAbsValue() const; |
132 | 131 |
133 private: | 132 private: |
134 size_t m_length; | 133 size_t m_length; |
135 | 134 |
136 float* m_rawPointer; | 135 float* m_rawPointer; |
137 std::unique_ptr<AudioFloatArray> m_memBuffer; | 136 OwnPtr<AudioFloatArray> m_memBuffer; |
138 bool m_silent; | 137 bool m_silent; |
139 }; | 138 }; |
140 | 139 |
141 } // namespace blink | 140 } // namespace blink |
142 | 141 |
143 #endif // AudioChannel_h | 142 #endif // AudioChannel_h |
OLD | NEW |