mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Re-fixed the last FFT fix.
This commit is contained in:
parent
9538d0dfc8
commit
560b314111
2 changed files with 36 additions and 17 deletions
|
|
@ -225,19 +225,43 @@ void FFT::perform (const Complex* const input, Complex* const output) const noex
|
|||
config->perform (input, output);
|
||||
}
|
||||
|
||||
const size_t maxFFTScratchSpaceToAlloca = 256 * 1024;
|
||||
|
||||
void FFT::performRealOnlyForwardTransform (float* d) const noexcept
|
||||
{
|
||||
const size_t scratchSize = 16 + sizeof (FFT::Complex) * (size_t) size;
|
||||
|
||||
if (scratchSize < maxFFTScratchSpaceToAlloca)
|
||||
{
|
||||
performRealOnlyForwardTransform (static_cast<Complex*> (alloca (scratchSize)), d);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeapBlock<char> heapSpace (scratchSize);
|
||||
performRealOnlyForwardTransform (reinterpret_cast<Complex*> (heapSpace.getData()), d);
|
||||
}
|
||||
}
|
||||
|
||||
void FFT::performRealOnlyInverseTransform (float* d) const noexcept
|
||||
{
|
||||
const size_t scratchSize = 16 + sizeof (FFT::Complex) * (size_t) size;
|
||||
|
||||
if (scratchSize < maxFFTScratchSpaceToAlloca)
|
||||
{
|
||||
performRealOnlyForwardTransform (static_cast<Complex*> (alloca (scratchSize)), d);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeapBlock<char> heapSpace (scratchSize);
|
||||
performRealOnlyInverseTransform (reinterpret_cast<Complex*> (heapSpace.getData()), d);
|
||||
}
|
||||
}
|
||||
|
||||
void FFT::performRealOnlyForwardTransform (Complex* scratch, float* d) const noexcept
|
||||
{
|
||||
// This can only be called on an FFT object that was created to do forward transforms.
|
||||
jassert (! config->inverse);
|
||||
|
||||
const size_t sizeInBytes = 16 + sizeof (Complex) * (size_t) size;
|
||||
|
||||
Complex* scratch = static_cast<Complex*> (alloca (sizeInBytes));
|
||||
|
||||
// try malloc if alloca fails
|
||||
if (scratch == nullptr)
|
||||
scratch = static_cast<Complex*> (malloc (sizeInBytes));
|
||||
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
scratch[i].r = d[i];
|
||||
|
|
@ -247,19 +271,11 @@ void FFT::performRealOnlyForwardTransform (float* d) const noexcept
|
|||
perform (scratch, reinterpret_cast<Complex*> (d));
|
||||
}
|
||||
|
||||
void FFT::performRealOnlyInverseTransform (float* d) const noexcept
|
||||
void FFT::performRealOnlyInverseTransform (Complex* scratch, float* d) const noexcept
|
||||
{
|
||||
// This can only be called on an FFT object that was created to do inverse transforms.
|
||||
jassert (config->inverse);
|
||||
|
||||
const size_t sizeInBytes = 16 + sizeof (Complex) * (size_t) size;
|
||||
|
||||
Complex* scratch = static_cast<Complex*> (alloca (sizeInBytes));
|
||||
|
||||
// try malloc if alloca fails
|
||||
if (scratch == nullptr)
|
||||
scratch = static_cast<Complex*> (malloc (sizeInBytes));
|
||||
|
||||
perform (reinterpret_cast<const Complex*> (d), scratch);
|
||||
|
||||
const float scaleFactor = 1.0f / size;
|
||||
|
|
|
|||
|
|
@ -88,5 +88,8 @@ private:
|
|||
ScopedPointer<FFTConfig> config;
|
||||
const int size;
|
||||
|
||||
void performRealOnlyForwardTransform (Complex*, float*) const noexcept;
|
||||
void performRealOnlyInverseTransform (Complex*, float*) const noexcept;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FFT)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue