| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Copy/setup frame data | 91 // Copy/setup frame data |
| 92 unsigned nbytes = sizeof(float) * m_FFTSize; | 92 unsigned nbytes = sizeof(float) * m_FFTSize; |
| 93 memcpy(realData(), frame.m_frame.realp, nbytes); | 93 memcpy(realData(), frame.m_frame.realp, nbytes); |
| 94 memcpy(imagData(), frame.m_frame.imagp, nbytes); | 94 memcpy(imagData(), frame.m_frame.imagp, nbytes); |
| 95 } | 95 } |
| 96 | 96 |
| 97 FFTFrame::~FFTFrame() | 97 FFTFrame::~FFTFrame() |
| 98 { | 98 { |
| 99 } | 99 } |
| 100 | 100 |
| 101 void FFTFrame::multiply(const FFTFrame& frame) | |
| 102 { | |
| 103 FFTFrame& frame1 = *this; | |
| 104 const FFTFrame& frame2 = frame; | |
| 105 | |
| 106 float* realP1 = frame1.realData(); | |
| 107 float* imagP1 = frame1.imagData(); | |
| 108 const float* realP2 = frame2.realData(); | |
| 109 const float* imagP2 = frame2.imagData(); | |
| 110 | |
| 111 unsigned halfSize = m_FFTSize / 2; | |
| 112 float real0 = realP1[0]; | |
| 113 float imag0 = imagP1[0]; | |
| 114 | |
| 115 // Complex multiply | |
| 116 VectorMath::zvmul(realP1, imagP1, realP2, imagP2, realP1, imagP1, halfSize); | |
| 117 | |
| 118 // Multiply the packed DC/nyquist component | |
| 119 realP1[0] = real0 * realP2[0]; | |
| 120 imagP1[0] = imag0 * imagP2[0]; | |
| 121 } | |
| 122 | |
| 123 void FFTFrame::doFFT(const float* data) | 101 void FFTFrame::doFFT(const float* data) |
| 124 { | 102 { |
| 125 AudioFloatArray scaledData(m_FFTSize); | 103 AudioFloatArray scaledData(m_FFTSize); |
| 126 // veclib fft returns a result that is twice as large as would be expected.
Compensate for that | 104 // veclib fft returns a result that is twice as large as would be expected.
Compensate for that |
| 127 // by scaling the input by half so the FFT has the correct scaling. | 105 // by scaling the input by half so the FFT has the correct scaling. |
| 128 float scale = 0.5f; | 106 float scale = 0.5f; |
| 129 VectorMath::vsmul(data, 1, &scale, scaledData.data(), 1, m_FFTSize); | 107 VectorMath::vsmul(data, 1, &scale, scaledData.data(), 1, m_FFTSize); |
| 130 | 108 |
| 131 vDSP_ctoz((DSPComplex*)scaledData.data(), 2, &m_frame, 1, m_FFTSize / 2); | 109 vDSP_ctoz((DSPComplex*)scaledData.data(), 2, &m_frame, 1, m_FFTSize / 2); |
| 132 vDSP_fft_zrip(m_FFTSetup, &m_frame, 1, m_log2FFTSize, FFT_FORWARD); | 110 vDSP_fft_zrip(m_FFTSetup, &m_frame, 1, m_log2FFTSize, FFT_FORWARD); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 float* FFTFrame::imagData() const | 161 float* FFTFrame::imagData() const |
| 184 { | 162 { |
| 185 return m_frame.imagp; | 163 return m_frame.imagp; |
| 186 } | 164 } |
| 187 | 165 |
| 188 } // namespace WebCore | 166 } // namespace WebCore |
| 189 | 167 |
| 190 #endif // #if OS(MACOSX) | 168 #endif // #if OS(MACOSX) |
| 191 | 169 |
| 192 #endif // ENABLE(WEB_AUDIO) | 170 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |