Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 m_frame.imagp = 0; | 73 m_frame.imagp = 0; |
| 74 | 74 |
| 75 m_FFTSize = 0; | 75 m_FFTSize = 0; |
| 76 m_log2FFTSize = 0; | 76 m_log2FFTSize = 0; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Copy constructor | 79 // Copy constructor |
| 80 FFTFrame::FFTFrame(const FFTFrame& frame) | 80 FFTFrame::FFTFrame(const FFTFrame& frame) |
| 81 : m_FFTSize(frame.m_FFTSize) | 81 : m_FFTSize(frame.m_FFTSize) |
| 82 , m_log2FFTSize(frame.m_log2FFTSize) | 82 , m_log2FFTSize(frame.m_log2FFTSize) |
| 83 , m_FFTSetup(frame.m_FFTSetup) | |
| 84 , m_realData(frame.m_FFTSize) | 83 , m_realData(frame.m_FFTSize) |
| 85 , m_imagData(frame.m_FFTSize) | 84 , m_imagData(frame.m_FFTSize) |
| 85 , m_FFTSetup(frame.m_FFTSetup) | |
| 86 { | 86 { |
| 87 // Setup frame data | 87 // Setup frame data |
| 88 m_frame.realp = m_realData.data(); | 88 m_frame.realp = m_realData.data(); |
| 89 m_frame.imagp = m_imagData.data(); | 89 m_frame.imagp = m_imagData.data(); |
| 90 | 90 |
| 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::doFFT(const float* data) | 101 void FFTFrame::doFFT(const float* data) |
| 102 { | 102 { |
| 103 AudioFloatArray scaledData(m_FFTSize); | 103 AudioFloatArray scaledData(m_FFTSize); |
| 104 // 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 |
| 105 // 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. |
| 106 float scale = 0.5f; | 106 float scale = 0.5f; |
| 107 VectorMath::vsmul(data, 1, &scale, scaledData.data(), 1, m_FFTSize); | 107 VectorMath::vsmul(data, 1, &scale, scaledData.data(), 1, m_FFTSize); |
|
KhNo
2014/09/04 04:11:36
It is using VectorMath::vsmul since vDSP_vsmul is
| |
| 108 | 108 |
| 109 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); |
| 110 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); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void FFTFrame::doInverseFFT(float* data) | 113 void FFTFrame::doInverseFFT(float* data) |
| 114 { | 114 { |
| 115 vDSP_fft_zrip(m_FFTSetup, &m_frame, 1, m_log2FFTSize, FFT_INVERSE); | 115 vDSP_fft_zrip(m_FFTSetup, &m_frame, 1, m_log2FFTSize, FFT_INVERSE); |
| 116 vDSP_ztoc(&m_frame, 1, (DSPComplex*)data, 2, m_FFTSize / 2); | 116 vDSP_ztoc(&m_frame, 1, (DSPComplex*)data, 2, m_FFTSize / 2); |
| 117 | 117 |
| 118 // Do final scaling so that x == IFFT(FFT(x)) | 118 // Do final scaling so that x == IFFT(FFT(x)) |
| 119 float scale = 1.0f / m_FFTSize; | 119 float scale = 1.0f / m_FFTSize; |
| 120 vDSP_vsmul(data, 1, &scale, data, 1, m_FFTSize); | 120 VectorMath::vsmul(data, 1, &scale, data, 1, m_FFTSize); |
|
Raymond Toy
2014/09/03 16:42:47
This looks wrong. Why the change from vDSP_vsmul
KhNo
2014/09/04 04:11:36
To make it has unity and code maintenance.
Raymond Toy
2014/09/04 17:14:57
I would prefer this change be done separately. Th
| |
| 121 } | 121 } |
| 122 | 122 |
| 123 FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize) | 123 FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize) |
| 124 { | 124 { |
| 125 if (!fftSetups) { | 125 if (!fftSetups) { |
| 126 fftSetups = (FFTSetup*)malloc(sizeof(FFTSetup) * kMaxFFTPow2Size); | 126 fftSetups = (FFTSetup*)malloc(sizeof(FFTSetup) * kMaxFFTPow2Size); |
| 127 memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size); | 127 memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size); |
| 128 } | 128 } |
| 129 | 129 |
| 130 int pow2size = static_cast<int>(log2(fftSize)); | 130 int pow2size = static_cast<int>(log2(fftSize)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 146 | 146 |
| 147 for (int i = 0; i < kMaxFFTPow2Size; ++i) { | 147 for (int i = 0; i < kMaxFFTPow2Size; ++i) { |
| 148 if (fftSetups[i]) | 148 if (fftSetups[i]) |
| 149 vDSP_destroy_fftsetup(fftSetups[i]); | 149 vDSP_destroy_fftsetup(fftSetups[i]); |
| 150 } | 150 } |
| 151 | 151 |
| 152 free(fftSetups); | 152 free(fftSetups); |
| 153 fftSetups = 0; | 153 fftSetups = 0; |
| 154 } | 154 } |
| 155 | 155 |
| 156 float* FFTFrame::realData() const | |
| 157 { | |
| 158 return m_frame.realp; | |
|
KhNo
2014/09/04 04:11:36
.realp and .imap are just pointer of m_realData.da
Raymond Toy
2014/09/04 17:14:57
Oh, because of line 62-63 in FFTFrame::FFTFrame.
| |
| 159 } | |
| 160 | |
| 161 float* FFTFrame::imagData() const | |
| 162 { | |
| 163 return m_frame.imagp; | |
| 164 } | |
| 165 | |
| 166 } // namespace blink | 156 } // namespace blink |
| 167 | 157 |
| 168 #endif // #if OS(MACOSX) | 158 #endif // #if OS(MACOSX) |
| 169 | 159 |
| 170 #endif // ENABLE(WEB_AUDIO) | 160 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |