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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 FFTSetup* FFTFrame::fftSetups = nullptr; | 43 FFTSetup* FFTFrame::fftSetups = nullptr; |
44 | 44 |
45 // Normal constructor: allocates for a given fftSize | 45 // Normal constructor: allocates for a given fftSize |
46 FFTFrame::FFTFrame(unsigned fftSize) | 46 FFTFrame::FFTFrame(unsigned fftSize) |
47 : m_realData(fftSize), m_imagData(fftSize) { | 47 : m_realData(fftSize), m_imagData(fftSize) { |
48 m_FFTSize = fftSize; | 48 m_FFTSize = fftSize; |
49 m_log2FFTSize = static_cast<unsigned>(log2(fftSize)); | 49 m_log2FFTSize = static_cast<unsigned>(log2(fftSize)); |
50 | 50 |
51 // We only allow power of two | 51 // We only allow power of two |
52 DCHECK_EQ(1UL << m_log2FFTSize, m_FFTSize); | 52 ASSERT(1UL << m_log2FFTSize == m_FFTSize); |
53 | 53 |
54 // Lazily create and share fftSetup with other frames | 54 // Lazily create and share fftSetup with other frames |
55 m_FFTSetup = fftSetupForSize(fftSize); | 55 m_FFTSetup = fftSetupForSize(fftSize); |
56 | 56 |
57 // Setup frame data | 57 // Setup frame data |
58 m_frame.realp = m_realData.data(); | 58 m_frame.realp = m_realData.data(); |
59 m_frame.imagp = m_imagData.data(); | 59 m_frame.imagp = m_imagData.data(); |
60 } | 60 } |
61 | 61 |
62 // Creates a blank/empty frame (interpolate() must later be called) | 62 // Creates a blank/empty frame (interpolate() must later be called) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 VectorMath::vsmul(data, 1, &scale, data, 1, m_FFTSize); | 109 VectorMath::vsmul(data, 1, &scale, data, 1, m_FFTSize); |
110 } | 110 } |
111 | 111 |
112 FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize) { | 112 FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize) { |
113 if (!fftSetups) { | 113 if (!fftSetups) { |
114 fftSetups = (FFTSetup*)malloc(sizeof(FFTSetup) * kMaxFFTPow2Size); | 114 fftSetups = (FFTSetup*)malloc(sizeof(FFTSetup) * kMaxFFTPow2Size); |
115 memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size); | 115 memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size); |
116 } | 116 } |
117 | 117 |
118 int pow2size = static_cast<int>(log2(fftSize)); | 118 int pow2size = static_cast<int>(log2(fftSize)); |
119 DCHECK_LT(pow2size, kMaxFFTPow2Size); | 119 ASSERT(pow2size < kMaxFFTPow2Size); |
120 if (!fftSetups[pow2size]) | 120 if (!fftSetups[pow2size]) |
121 fftSetups[pow2size] = vDSP_create_fftsetup(pow2size, FFT_RADIX2); | 121 fftSetups[pow2size] = vDSP_create_fftsetup(pow2size, FFT_RADIX2); |
122 | 122 |
123 return fftSetups[pow2size]; | 123 return fftSetups[pow2size]; |
124 } | 124 } |
125 | 125 |
126 void FFTFrame::initialize() {} | 126 void FFTFrame::initialize() {} |
127 | 127 |
128 void FFTFrame::cleanup() { | 128 void FFTFrame::cleanup() { |
129 if (!fftSetups) | 129 if (!fftSetups) |
130 return; | 130 return; |
131 | 131 |
132 for (int i = 0; i < kMaxFFTPow2Size; ++i) { | 132 for (int i = 0; i < kMaxFFTPow2Size; ++i) { |
133 if (fftSetups[i]) | 133 if (fftSetups[i]) |
134 vDSP_destroy_fftsetup(fftSetups[i]); | 134 vDSP_destroy_fftsetup(fftSetups[i]); |
135 } | 135 } |
136 | 136 |
137 free(fftSetups); | 137 free(fftSetups); |
138 fftSetups = nullptr; | 138 fftSetups = nullptr; |
139 } | 139 } |
140 | 140 |
141 } // namespace blink | 141 } // namespace blink |
142 | 142 |
143 #endif // #if OS(MACOSX) | 143 #endif // #if OS(MACOSX) |
OLD | NEW |