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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 public: | 45 public: |
46 AudioArray() : m_allocation(nullptr), m_alignedData(nullptr), m_size(0) {} | 46 AudioArray() : m_allocation(nullptr), m_alignedData(nullptr), m_size(0) {} |
47 explicit AudioArray(size_t n) | 47 explicit AudioArray(size_t n) |
48 : m_allocation(nullptr), m_alignedData(nullptr), m_size(0) { | 48 : m_allocation(nullptr), m_alignedData(nullptr), m_size(0) { |
49 allocate(n); | 49 allocate(n); |
50 } | 50 } |
51 | 51 |
52 ~AudioArray() { WTF::Partitions::fastFree(m_allocation); } | 52 ~AudioArray() { WTF::Partitions::fastFree(m_allocation); } |
53 | 53 |
54 // It's OK to call allocate() multiple times, but data will *not* be copied fr
om an initial allocation | 54 // It's OK to call allocate() multiple times, but data will *not* be copied |
55 // if re-allocated. Allocations are zero-initialized. | 55 // from an initial allocation if re-allocated. Allocations are |
| 56 // zero-initialized. |
56 void allocate(size_t n) { | 57 void allocate(size_t n) { |
57 // Although n is a size_t, its true limit is max unsigned because we use uns
igned in zeroRange() | 58 // Although n is a size_t, its true limit is max unsigned because we use |
58 // and copyToRange(). Also check for integer overflow. | 59 // unsigned in zeroRange() and copyToRange(). Also check for integer |
| 60 // overflow. |
59 RELEASE_ASSERT(n <= std::numeric_limits<unsigned>::max() / sizeof(T)); | 61 RELEASE_ASSERT(n <= std::numeric_limits<unsigned>::max() / sizeof(T)); |
60 | 62 |
61 unsigned initialSize = sizeof(T) * n; | 63 unsigned initialSize = sizeof(T) * n; |
62 | 64 |
63 #if USE(WEBAUDIO_FFMPEG) || USE(WEBAUDIO_OPENMAX_DL_FFT) | 65 #if USE(WEBAUDIO_FFMPEG) || USE(WEBAUDIO_OPENMAX_DL_FFT) |
64 const size_t alignment = 32; | 66 const size_t alignment = 32; |
65 #else | 67 #else |
66 const size_t alignment = 16; | 68 const size_t alignment = 16; |
67 #endif | 69 #endif |
68 | 70 |
(...skipping 17 matching lines...) Expand all Loading... |
86 | 88 |
87 T* alignedData = alignedAddress(allocation, alignment); | 89 T* alignedData = alignedAddress(allocation, alignment); |
88 | 90 |
89 if (alignedData == allocation || extraAllocationBytes == alignment) { | 91 if (alignedData == allocation || extraAllocationBytes == alignment) { |
90 m_allocation = allocation; | 92 m_allocation = allocation; |
91 m_alignedData = alignedData; | 93 m_alignedData = alignedData; |
92 m_size = n; | 94 m_size = n; |
93 isAllocationGood = true; | 95 isAllocationGood = true; |
94 zero(); | 96 zero(); |
95 } else { | 97 } else { |
96 extraAllocationBytes = | 98 // always allocate extra after the first alignment failure. |
97 alignment; // always allocate extra after the first alignment failu
re. | 99 extraAllocationBytes = alignment; |
98 WTF::Partitions::fastFree(allocation); | 100 WTF::Partitions::fastFree(allocation); |
99 } | 101 } |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 T* data() { return m_alignedData; } | 105 T* data() { return m_alignedData; } |
104 const T* data() const { return m_alignedData; } | 106 const T* data() const { return m_alignedData; } |
105 size_t size() const { return m_size; } | 107 size_t size() const { return m_size; } |
106 | 108 |
107 T& at(size_t i) { | 109 T& at(size_t i) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 T* m_alignedData; | 152 T* m_alignedData; |
151 size_t m_size; | 153 size_t m_size; |
152 }; | 154 }; |
153 | 155 |
154 typedef AudioArray<float> AudioFloatArray; | 156 typedef AudioArray<float> AudioFloatArray; |
155 typedef AudioArray<double> AudioDoubleArray; | 157 typedef AudioArray<double> AudioDoubleArray; |
156 | 158 |
157 } // namespace blink | 159 } // namespace blink |
158 | 160 |
159 #endif // AudioArray_h | 161 #endif // AudioArray_h |
OLD | NEW |