Redo type HFFT as a smart pointer, remove malloc and free

This commit is contained in:
Paul Licameli 2016-08-13 11:02:35 -04:00
parent c5007d846e
commit 58574f2f78
12 changed files with 210 additions and 246 deletions

View File

@ -113,8 +113,6 @@ void InitFFT()
void DeinitFFT()
{
gFFTBitTable.reset();
// Deallocate any unused RealFFTf tables
CleanupFFT();
}
static inline size_t FastReverseBits(size_t i, size_t NumBits)
@ -230,14 +228,14 @@ void FFT(size_t NumSamples,
void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
{
HFFT hFFT = GetFFT(NumSamples);
auto hFFT = GetFFT(NumSamples);
Floats pFFT{ NumSamples };
// Copy the data into the processing buffer
for(size_t i = 0; i < NumSamples; i++)
pFFT[i] = RealIn[i];
// Perform the FFT
RealFFTf(pFFT.get(), hFFT);
RealFFTf(pFFT.get(), hFFT.get());
// Copy the data into the real and imaginary outputs
for (size_t i = 1; i<(NumSamples / 2); i++) {
@ -253,8 +251,6 @@ void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *Imag
RealOut[i] = RealOut[NumSamples-i];
ImagOut[i] = -ImagOut[NumSamples-i];
}
ReleaseFFT(hFFT);
}
/*
@ -271,7 +267,7 @@ void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *Imag
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn,
float *RealOut)
{
HFFT hFFT = GetFFT(NumSamples);
auto hFFT = GetFFT(NumSamples);
Floats pFFT{ NumSamples };
// Copy the data into the processing buffer
for (size_t i = 0; i < (NumSamples / 2); i++)
@ -287,12 +283,10 @@ void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn,
pFFT[1] = RealIn[NumSamples / 2];
// Perform the FFT
InverseRealFFTf(pFFT.get(), hFFT);
InverseRealFFTf(pFFT.get(), hFFT.get());
// Copy the data to the (purely real) output buffer
ReorderToTime(hFFT, pFFT.get(), RealOut);
ReleaseFFT(hFFT);
ReorderToTime(hFFT.get(), pFFT.get(), RealOut);
}
/*
@ -308,14 +302,14 @@ void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn,
void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
{
HFFT hFFT = GetFFT(NumSamples);
auto hFFT = GetFFT(NumSamples);
Floats pFFT{ NumSamples };
// Copy the data into the processing buffer
for (size_t i = 0; i<NumSamples; i++)
pFFT[i] = In[i];
// Perform the FFT
RealFFTf(pFFT.get(), hFFT);
RealFFTf(pFFT.get(), hFFT.get());
// Copy the data into the real and imaginary outputs
for (size_t i = 1; i<NumSamples / 2; i++) {
@ -325,7 +319,6 @@ void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
// Handle the (real-only) DC and Fs/2 bins
Out[0] = pFFT[0]*pFFT[0];
Out[NumSamples / 2] = pFFT[1]*pFFT[1];
ReleaseFFT(hFFT);
}
/*

View File

@ -37,11 +37,14 @@
*/
#include "Audacity.h"
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "Experimental.h"
#include <wx/thread.h>
#include "RealFFTf.h"
#ifdef EXPERIMENTAL_EQ_SSE_THREADED
#include "RealFFTf48x.h"
@ -58,13 +61,8 @@
HFFT InitializeFFT(size_t fftlen)
{
int temp;
HFFT h;
HFFT h{ safenew FFTParam };
if((h=(HFFT)malloc(sizeof(FFTParam)))==NULL)
{
fprintf(stderr,"Error allocating memory for FFT\n");
exit(8);
}
/*
* FFT size is only half the number of data points
* The full FFT output can be reconstructed from this FFT's output.
@ -72,17 +70,9 @@ HFFT InitializeFFT(size_t fftlen)
*/
h->Points = fftlen / 2;
if((h->SinTable=(fft_type *)malloc(2*h->Points*sizeof(fft_type)))==NULL)
{
fprintf(stderr,"Error allocating memory for Sine table.\n");
exit(8);
}
h->SinTable.reinit(2*h->Points);
if((h->BitReversed=(int *)malloc(h->Points*sizeof(int)))==NULL)
{
fprintf(stderr,"Error allocating memory for BitReversed.\n");
exit(8);
}
h->BitReversed.reinit(h->Points);
for(size_t i = 0; i < h->Points; i++)
{
@ -109,40 +99,33 @@ HFFT InitializeFFT(size_t fftlen)
return h;
}
/*
* Free up the memory allotted for Sin table and Twiddle Pointers
*/
void EndFFT(HFFT h)
{
if(h->Points > 0) {
free(h->BitReversed);
free(h->SinTable);
}
h->Points = 0;
free(h);
}
enum : size_t { MAX_HFFT = 10 };
static HFFT hFFTArray[MAX_HFFT] = { NULL };
static int nFFTLockCount[MAX_HFFT] = { 0 };
// Maintain a pool:
static std::vector< movable_ptr<FFTParam> > hFFTArray(MAX_HFFT);
wxCriticalSection getFFTMutex;
/* Get a handle to the FFT tables of the desired length */
/* This version keeps common tables rather than allocating a NEW table every time */
HFFT GetFFT(size_t fftlen)
{
// To do: smarter policy about when to retain in the pool and when to
// allocate a unique instance.
wxCriticalSectionLocker locker{ getFFTMutex };
size_t h = 0;
auto n = fftlen/2;
auto size = hFFTArray.size();
for(;
(h < MAX_HFFT) && (hFFTArray[h] != NULL) && (n != hFFTArray[h]->Points);
(h < size) && hFFTArray[h] && (n != hFFTArray[h]->Points);
h++)
;
if(h < MAX_HFFT) {
if(h < size) {
if(hFFTArray[h] == NULL) {
hFFTArray[h] = InitializeFFT(fftlen);
nFFTLockCount[h] = 0;
hFFTArray[h].reset( InitializeFFT(fftlen).release() );
}
nFFTLockCount[h]++;
return hFFTArray[h];
return HFFT{ hFFTArray[h].get() };
} else {
// All buffers used, so fall back to allocating a NEW set of tables
return InitializeFFT(fftlen);
@ -150,31 +133,21 @@ HFFT GetFFT(size_t fftlen)
}
/* Release a previously requested handle to the FFT tables */
void ReleaseFFT(HFFT hFFT)
void FFTDeleter::operator() (FFTParam *hFFT) const
{
int h;
for(h=0; (h<MAX_HFFT) && (hFFTArray[h] != hFFT); h++);
if(h<MAX_HFFT) {
nFFTLockCount[h]--;
} else {
EndFFT(hFFT);
}
}
wxCriticalSectionLocker locker{ getFFTMutex };
/* Deallocate any unused FFT tables */
void CleanupFFT()
{
int h;
for(h=0; (h<MAX_HFFT); h++) {
if((nFFTLockCount[h] <= 0) && (hFFTArray[h] != NULL)) {
EndFFT(hFFTArray[h]);
hFFTArray[h] = NULL;
}
}
auto it = hFFTArray.begin(), end = hFFTArray.end();
while (it != end && it->get() != hFFT)
++it;
if ( it != end )
;
else
delete hFFT;
}
/*
* Forward FFT routine. Must call InitializeFFT(fftlen) first!
* Forward FFT routine. Must call GetFFT(fftlen) first!
*
* Note: Output is BIT-REVERSED! so you must use the BitReversed to
* get legible output, (i.e. Real_i = buffer[ h->BitReversed[i] ]
@ -191,7 +164,7 @@ void CleanupFFT()
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void RealFFTf(fft_type *buffer,HFFT h)
void RealFFTf(fft_type *buffer, const FFTParam *h)
{
fft_type *A,*B;
const fft_type *sptr;
@ -216,7 +189,7 @@ void RealFFTf(fft_type *buffer,HFFT h)
{
A = buffer;
B = buffer + ButterfliesPerGroup * 2;
sptr = h->SinTable;
sptr = h->SinTable.get();
while(A < endptr1)
{
@ -239,8 +212,8 @@ void RealFFTf(fft_type *buffer,HFFT h)
ButterfliesPerGroup >>= 1;
}
/* Massage output to get the output for a real input sequence. */
br1 = h->BitReversed + 1;
br2 = h->BitReversed + h->Points - 1;
br1 = h->BitReversed.get() + 1;
br2 = h->BitReversed.get() + h->Points - 1;
while(br1<br2)
{
@ -281,7 +254,7 @@ void RealFFTf(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -293,7 +266,7 @@ void RealFFTf(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf(fft_type *buffer,HFFT h)
void InverseRealFFTf(fft_type *buffer, const FFTParam *h)
{
fft_type *A,*B;
const fft_type *sptr;
@ -307,7 +280,7 @@ void InverseRealFFTf(fft_type *buffer,HFFT h)
/* Massage input to get the input for a real output sequence. */
A = buffer + 2;
B = buffer + h->Points * 2 - 2;
br1 = h->BitReversed + 1;
br1 = h->BitReversed.get() + 1;
while(A<B)
{
sin=h->SinTable[*br1];
@ -353,7 +326,7 @@ void InverseRealFFTf(fft_type *buffer,HFFT h)
{
A = buffer;
B = buffer + ButterfliesPerGroup * 2;
sptr = h->SinTable;
sptr = h->SinTable.get();
while(A < endptr1)
{
@ -376,7 +349,7 @@ void InverseRealFFTf(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq(HFFT hFFT, const fft_type *buffer,
void ReorderToFreq(const FFTParam *hFFT, const fft_type *buffer,
fft_type *RealOut, fft_type *ImagOut)
{
// Copy the data into the real and imaginary outputs
@ -390,7 +363,7 @@ void ReorderToFreq(HFFT hFFT, const fft_type *buffer,
ImagOut[hFFT->Points] = 0;
}
void ReorderToTime(HFFT hFFT, const fft_type *buffer, fft_type *TimeOut)
void ReorderToTime(const FFTParam *hFFT, const fft_type *buffer, fft_type *TimeOut)
{
// Copy the data into the real outputs
for(size_t i = 0; i < hFFT->Points; i++) {

View File

@ -1,28 +1,33 @@
#ifndef __realfftf_h
#define __realfftf_h
#include "Audacity.h"
#include "Experimental.h"
#include "MemoryX.h"
#define fft_type float
using fft_type = float;
struct FFTParam {
int *BitReversed;
fft_type *SinTable;
ArrayOf<int> BitReversed;
ArrayOf<fft_type> SinTable;
size_t Points;
#ifdef EXPERIMENTAL_EQ_SSE_THREADED
int pow2Bits;
#endif
};
typedef FFTParam * HFFT;
HFFT InitializeFFT(size_t);
void EndFFT(HFFT);
struct FFTDeleter{
void operator () (FFTParam *p) const;
};
using HFFT = std::unique_ptr<
FFTParam, FFTDeleter
>;
HFFT GetFFT(size_t);
void ReleaseFFT(HFFT);
void CleanupFFT();
void RealFFTf(fft_type *,HFFT);
void InverseRealFFTf(fft_type *,HFFT);
void ReorderToTime(HFFT hFFT, const fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq(HFFT hFFT, const fft_type *buffer,
void RealFFTf(fft_type *, const FFTParam *);
void InverseRealFFTf(fft_type *, const FFTParam *);
void ReorderToTime(const FFTParam *hFFT, const fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq(const FFTParam *hFFT, const fft_type *buffer,
fft_type *RealOut, fft_type *ImagOut);
#endif

View File

@ -146,7 +146,7 @@ int SmallRB(int bits, int numberBits)
};
/* wrapper funcitons. If passed -1 function choice will be made locally */
void RealFFTf1x(fft_type *buffer, HFFT h, int functionType)
void RealFFTf1x(fft_type *buffer, FFTParam *h, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -167,7 +167,7 @@ void RealFFTf1x(fft_type *buffer, HFFT h, int functionType)
};
}
void InverseRealFFTf1x(fft_type *buffer, HFFT h, int functionType)
void InverseRealFFTf1x(fft_type *buffer, FFTParam *h, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -188,7 +188,7 @@ void InverseRealFFTf1x(fft_type *buffer, HFFT h, int functionType)
};
}
void ReorderToTime1x(HFFT hFFT, fft_type *buffer, fft_type *TimeOut, int functionType)
void ReorderToTime1x(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -209,7 +209,7 @@ void ReorderToTime1x(HFFT hFFT, fft_type *buffer, fft_type *TimeOut, int functio
};
}
void ReorderToFreq1x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType)
void ReorderToFreq1x(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -230,7 +230,7 @@ void ReorderToFreq1x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *I
};
}
void RealFFTf4x( fft_type *buffer, HFFT h, int functionType)
void RealFFTf4x( fft_type *buffer, FFTParam *h, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -251,7 +251,7 @@ void RealFFTf4x( fft_type *buffer, HFFT h, int functionType)
};
}
void InverseRealFFTf4x( fft_type *buffer, HFFT h, int functionType)
void InverseRealFFTf4x( fft_type *buffer, FFTParam *h, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -272,7 +272,7 @@ void InverseRealFFTf4x( fft_type *buffer, HFFT h, int functionType)
};
}
void ReorderToTime4x(HFFT hFFT, fft_type *buffer, fft_type *TimeOut, int functionType)
void ReorderToTime4x(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -293,7 +293,7 @@ void ReorderToTime4x(HFFT hFFT, fft_type *buffer, fft_type *TimeOut, int functio
};
}
void ReorderToFreq4x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType)
void ReorderToFreq4x(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType)
{
switch(functionType) {
case FFT_SinCosTableVBR16:
@ -318,7 +318,7 @@ void ReorderToFreq4x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *I
#ifdef REAL_SINCOSBRTABLE
/*
* Forward FFT routine. Must call InitializeFFT(fftlen) first!
* Forward FFT routine. Must call GetFFT(fftlen) first!
*
* Note: Output is BIT-REVERSED! so you must use the BitReversed to
* get legible output, (i.e. Real_i = buffer[ h->BitReversed[i] ]
@ -335,7 +335,7 @@ void ReorderToFreq4x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *I
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void RealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
void RealFFTf1xSinCosBRTable(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *sptr;
@ -360,7 +360,7 @@ void RealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
{
A = buffer;
B = buffer + ButterfliesPerGroup * 2;
sptr = h->SinTable;
sptr = h->SinTable.get();
while(A < endptr1)
{
@ -383,8 +383,8 @@ void RealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
ButterfliesPerGroup >>= 1;
}
/* Massage output to get the output for a real input sequence. */
br1 = h->BitReversed + 1;
br2 = h->BitReversed + h->Points - 1;
br1 = h->BitReversed.get() + 1;
br2 = h->BitReversed.get() + h->Points - 1;
while(br1 < br2)
{
@ -425,7 +425,7 @@ void RealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -437,7 +437,7 @@ void RealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
void InverseRealFFTf1xSinCosBRTable(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *sptr;
@ -451,7 +451,7 @@ void InverseRealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
/* Massage input to get the input for a real output sequence. */
A = buffer + 2;
B = buffer + h->Points * 2 - 2;
br1 = h->BitReversed + 1;
br1 = h->BitReversed.get() + 1;
while(A < B)
{
sin=h->SinTable[*br1];
@ -497,7 +497,7 @@ void InverseRealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
{
A = buffer;
B = buffer + ButterfliesPerGroup * 2;
sptr = h->SinTable;
sptr = h->SinTable.get();
while(A < endptr1)
{
@ -520,7 +520,7 @@ void InverseRealFFTf1xSinCosBRTable(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq1xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
// Copy the data into the real and imaginary outputs
for(size_t i = 1; i < hFFT->Points; i++) {
@ -533,7 +533,7 @@ void ReorderToFreq1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut
ImagOut[hFFT->Points] = 0;
}
void ReorderToTime1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime1xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
// Copy the data into the real outputs
for(size_t i = 0; i < hFFT->Points; i++) {
@ -543,7 +543,7 @@ void ReorderToTime1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut
}
// 4x processing simd
void RealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
void RealFFTf4xSinCosBRTable(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -571,7 +571,7 @@ void RealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
{
A = localBuffer;
B = &localBuffer[ButterfliesPerGroup * 2];
sptr = h->SinTable;
sptr = h->SinTable.get();
while(A < endptr1)
{
sin = _mm_set1_ps(*(sptr++));
@ -637,7 +637,7 @@ void RealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -649,7 +649,7 @@ void RealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
void InverseRealFFTf4xSinCosBRTable(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -717,7 +717,7 @@ void InverseRealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
{
A = localBuffer;
B = localBuffer + ButterfliesPerGroup * 2;
sptr = h->SinTable;
sptr = h->SinTable.get();
while(A < endptr1)
{
sin = _mm_set1_ps(*(sptr++));
@ -739,7 +739,7 @@ void InverseRealFFTf4xSinCosBRTable(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq4xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
__m128 *localBuffer=(__m128 *)buffer;
__m128 *localRealOut=(__m128 *)RealOut;
@ -758,7 +758,7 @@ void ReorderToFreq4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut
localImagOut[hFFT->Points] = _mm_set1_ps(0.0);
}
void ReorderToTime4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime4xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
__m128 *localBuffer=(__m128 *)buffer;
__m128 *localTimeOut=(__m128 *)TimeOut;
@ -777,7 +777,7 @@ void ReorderToTime4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut
#ifdef REAL_SINCOSTABLE_VBR16
/*
* Forward FFT routine. Must call InitializeFFT(fftlen) first!
* Forward FFT routine. Must call GetFFT(fftlen) first!
*
* Note: Output is BIT-REVERSED! so you must use the BitReversed to
* get legible output, (i.e. Real_i = buffer[ h->BitReversed[i] ]
@ -794,7 +794,7 @@ void ReorderToTime4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void RealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
void RealFFTf1xSinCosTableVBR16(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1,*endptr2;
@ -880,7 +880,7 @@ void RealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -892,7 +892,7 @@ void RealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
void InverseRealFFTf1xSinCosTableVBR16(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1,*endptr2;
@ -907,7 +907,7 @@ void InverseRealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
/* Massage input to get the input for a real output sequence. */
A = buffer + 2;
B = buffer + h->Points * 2 - 2;
br1 = h->BitReversed + 1;
br1 = h->BitReversed.get() + 1;
br1Index = 1; //h->BitReversed + 1;
while(A < B)
{
@ -980,7 +980,7 @@ void InverseRealFFTf1xSinCosTableVBR16(fft_type *buffer,HFFT h)
}
}
void ReorderToTime1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime1xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
// Copy the data into the real outputs
for(size_t i = 0;i < hFFT->Points; i++) {
@ -991,7 +991,7 @@ void ReorderToTime1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Time
}
}
void ReorderToFreq1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq1xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
// Copy the data into the real and imaginary outputs
for(size_t i = 1; i < hFFT->Points; i++) {
@ -1007,7 +1007,7 @@ void ReorderToFreq1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Real
}
// 4x processing simd
void RealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
void RealFFTf4xSinCosTableVBR16(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -1105,7 +1105,7 @@ void RealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -1117,7 +1117,7 @@ void RealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
void InverseRealFFTf4xSinCosTableVBR16(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -1210,7 +1210,7 @@ void InverseRealFFTf4xSinCosTableVBR16(fft_type *buffer,HFFT h)
}
}
void ReorderToTime4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime4xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
__m128 *localBuffer = (__m128 *)buffer;
__m128 *localTimeOut = (__m128 *)TimeOut;
@ -1223,7 +1223,7 @@ void ReorderToTime4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Time
}
}
void ReorderToFreq4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq4xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
__m128 *localBuffer = (__m128 *)buffer;
__m128 *localRealOut = (__m128 *)RealOut;
@ -1247,7 +1247,7 @@ void ReorderToFreq4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Real
#ifdef REAL_SINCOSTABLE_BR16
/*
* Forward FFT routine. Must call InitializeFFT(fftlen) first!
* Forward FFT routine. Must call GetFFT(fftlen) first!
*
* Note: Output is BIT-REVERSED! so you must use the BitReversed to
* get legible output, (i.e. Real_i = buffer[ h->BitReversed[i] ]
@ -1264,7 +1264,7 @@ void ReorderToFreq4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *Real
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void RealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
void RealFFTf1xSinCosTableBR16(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1, *endptr2;
@ -1354,7 +1354,7 @@ void RealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -1366,7 +1366,7 @@ void RealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
void InverseRealFFTf1xSinCosTableBR16(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1,*endptr2;
@ -1453,7 +1453,7 @@ void InverseRealFFTf1xSinCosTableBR16(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq1xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs
@ -1470,7 +1470,7 @@ void ReorderToFreq1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealO
ImagOut[hFFT->Points] = 0;
}
void ReorderToTime1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime1xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real outputs
@ -1484,7 +1484,7 @@ void ReorderToTime1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeO
}
// 4x processing simd
void RealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
void RealFFTf4xSinCosTableBR16(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -1586,7 +1586,7 @@ void RealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -1598,7 +1598,7 @@ void RealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
void InverseRealFFTf4xSinCosTableBR16(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -1692,7 +1692,7 @@ void InverseRealFFTf4xSinCosTableBR16(fft_type *buffer,HFFT h)
}
}
void ReorderToTime4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime4xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
__m128 *localBuffer = (__m128 *)buffer;
__m128 *localTimeOut = (__m128 *)TimeOut;
@ -1708,7 +1708,7 @@ void ReorderToTime4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeO
}
}
void ReorderToFreq4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq4xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
__m128 *localBuffer = (__m128 *)buffer;
__m128 *localRealOut = (__m128 *)RealOut;
@ -1734,7 +1734,7 @@ void ReorderToFreq4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealO
#ifdef FAST_MATH_BR24
/*
* Forward FFT routine. Must call InitializeFFT(fftlen) first!
* Forward FFT routine. Must call GetFFT(fftlen) first!
*
* Note: Output is BIT-REVERSED! so you must use the BitReversed to
* get legible output, (i.e. Real_i = buffer[ h->BitReversed[i] ]
@ -1751,7 +1751,7 @@ void ReorderToFreq4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealO
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void RealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
void RealFFTf1xFastMathBR24(fft_type *buffer, FFTParam *h)
{
fft_type *A, *B;
fft_type *endptr1, *endptr2;
@ -1886,7 +1886,7 @@ void RealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -1898,7 +1898,7 @@ void RealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
void InverseRealFFTf1xFastMathBR24(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1,*endptr2;
@ -2019,7 +2019,7 @@ void InverseRealFFTf1xFastMathBR24(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq1xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
int bitReverseShift = 24 - hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs
@ -2037,7 +2037,7 @@ void ReorderToFreq1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
ImagOut[hFFT->Points] = 0;
}
void ReorderToTime1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime1xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
int bitReverseShift = 24 - hFFT->pow2Bits;
// Copy the data into the real outputs
@ -2050,7 +2050,7 @@ void ReorderToTime1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
}
}
void RealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
void RealFFTf4xFastMathBR24(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -2186,7 +2186,7 @@ void RealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -2198,7 +2198,7 @@ void RealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
void InverseRealFFTf4xFastMathBR24(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -2325,7 +2325,7 @@ void InverseRealFFTf4xFastMathBR24(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq4xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
__m128 *localBuffer = (__m128 *)buffer;
__m128 *localRealOut = (__m128 *)RealOut;
@ -2347,7 +2347,7 @@ void ReorderToFreq4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
localImagOut[hFFT->Points] = _mm_set1_ps(0.0);
}
void ReorderToTime4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime4xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
__m128 *localBuffer = (__m128 *)buffer;
__m128 *localTimeOut = (__m128 *)TimeOut;
@ -2369,7 +2369,7 @@ void ReorderToTime4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
#ifdef FAST_MATH_BR16
/*
* Forward FFT routine. Must call InitializeFFT(fftlen) first!
* Forward FFT routine. Must call GetFFT(fftlen) first!
*
* Note: Output is BIT-REVERSED! so you must use the BitReversed to
* get legible output, (i.e. Real_i = buffer[ h->BitReversed[i] ]
@ -2386,7 +2386,7 @@ void ReorderToTime4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void RealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
void RealFFTf1xFastMathBR16(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1,*endptr2;
@ -2517,7 +2517,7 @@ void RealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -2529,7 +2529,7 @@ void RealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
void InverseRealFFTf1xFastMathBR16(fft_type *buffer, FFTParam *h)
{
fft_type *A,*B;
fft_type *endptr1,*endptr2;
@ -2650,7 +2650,7 @@ void InverseRealFFTf1xFastMathBR16(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq1xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
int bitReverseShift = 16 - hFFT->pow2Bits;
// Copy the data into the real and imaginary outputs
@ -2667,7 +2667,7 @@ void ReorderToFreq1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
ImagOut[hFFT->Points] = 0;
}
void ReorderToTime1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime1xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
int bitReverseShift=16-hFFT->pow2Bits;
// Copy the data into the real outputs
@ -2680,7 +2680,7 @@ void ReorderToTime1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
}
}
void RealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
void RealFFTf4xFastMathBR16(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer = (__m128 *)buffer;
@ -2816,7 +2816,7 @@ void RealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
* get legible output, (i.e. wave[2*i] = buffer[ BitReversed[i] ]
* wave[2*i+1] = buffer[ BitReversed[i]+1 ] )
* Input is in normal order, interleaved (real,imaginary) complex data
* You must call InitializeFFT(fftlen) first to initialize some buffers!
* You must call GetFFT(fftlen) first to initialize some buffers!
*
* Input buffer[0] is the DC bin, and input buffer[1] is the Fs/2 bin
* - this can be done because both values will always be real only
@ -2828,7 +2828,7 @@ void RealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
* values would be similar in amplitude to the input values, which is
* good when using fixed point arithmetic)
*/
void InverseRealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
void InverseRealFFTf4xFastMathBR16(fft_type *buffer, FFTParam *h)
{
__m128 *localBuffer=(__m128 *)buffer;
@ -2955,7 +2955,7 @@ void InverseRealFFTf4xFastMathBR16(fft_type *buffer,HFFT h)
}
}
void ReorderToFreq4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
void ReorderToFreq4xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
{
__m128 *localBuffer=(__m128 *)buffer;
__m128 *localRealOut=(__m128 *)RealOut;
@ -2977,7 +2977,7 @@ void ReorderToFreq4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut,
localImagOut[hFFT->Points] = _mm_set1_ps(0.0);
}
void ReorderToTime4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut)
void ReorderToTime4xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut)
{
__m128 *localBuffer=(__m128 *)buffer;
__m128 *localTimeOut=(__m128 *)TimeOut;

View File

@ -16,64 +16,64 @@ enum {
};
/* wrapper funcitons. If passed -1 function choice will be made locally */
void RealFFTf1x(fft_type *,HFFT, int functionType=-1);
void InverseRealFFTf1x(fft_type *,HFFT, int functionType=-1);
void ReorderToTime1x(HFFT hFFT, fft_type *buffer, fft_type *TimeOut, int functionType=-1);
void ReorderToFreq1x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType=-1);
void RealFFTf4x(fft_type *,HFFT, int functionType=-1);
void InverseRealFFTf4x(fft_type *,HFFT, int functionType=-1);
void ReorderToTime4x(HFFT hFFT, fft_type *buffer, fft_type *TimeOut, int functionType=-1);
void ReorderToFreq4x(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType=-1);
void RealFFTf1x(fft_type *, FFTParam*, int functionType=-1);
void InverseRealFFTf1x(fft_type *, FFTParam*, int functionType=-1);
void ReorderToTime1x(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut, int functionType=-1);
void ReorderToFreq1x(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType=-1);
void RealFFTf4x(fft_type *, FFTParam *, int functionType=-1);
void InverseRealFFTf4x(fft_type *, FFTParam *, int functionType=-1);
void ReorderToTime4x(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut, int functionType=-1);
void ReorderToFreq4x(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut, int functionType=-1);
/* SinCosBRTable versions */
void RealFFTf1xSinCosBRTable(fft_type *,HFFT);
void InverseRealFFTf1xSinCosBRTable(fft_type *,HFFT);
void ReorderToTime1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xSinCosBRTable(fft_type *,HFFT);
void InverseRealFFTf4xSinCosBRTable(fft_type *,HFFT);
void ReorderToTime4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xSinCosBRTable(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf1xSinCosBRTable(fft_type *, FFTParam*);
void InverseRealFFTf1xSinCosBRTable(fft_type *, FFTParam*);
void ReorderToTime1xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xSinCosBRTable(fft_type *, FFTParam *);
void InverseRealFFTf4xSinCosBRTable(fft_type *, FFTParam *);
void ReorderToTime4xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xSinCosBRTable(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
/* Fast Math BR16 versions */
void RealFFTf1xFastMathBR16(fft_type *,HFFT);
void InverseRealFFTf1xFastMathBR16(fft_type *,HFFT);
void ReorderToTime1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xFastMathBR16(fft_type *,HFFT);
void InverseRealFFTf4xFastMathBR16(fft_type *,HFFT);
void ReorderToTime4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xFastMathBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf1xFastMathBR16(fft_type *, FFTParam*);
void InverseRealFFTf1xFastMathBR16(fft_type *, FFTParam*);
void ReorderToTime1xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xFastMathBR16(fft_type *, FFTParam *);
void InverseRealFFTf4xFastMathBR16(fft_type *, FFTParam *);
void ReorderToTime4xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xFastMathBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
/* Fast Math BR24 versions */
void RealFFTf1xFastMathBR24(fft_type *,HFFT);
void InverseRealFFTf1xFastMathBR24(fft_type *,HFFT);
void ReorderToTime1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xFastMathBR24(fft_type *,HFFT);
void InverseRealFFTf4xFastMathBR24(fft_type *,HFFT);
void ReorderToTime4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xFastMathBR24(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf1xFastMathBR24(fft_type *, FFTParam*);
void InverseRealFFTf1xFastMathBR24(fft_type *, FFTParam*);
void ReorderToTime1xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xFastMathBR24(fft_type *, FFTParam *);
void InverseRealFFTf4xFastMathBR24(fft_type *, FFTParam *);
void ReorderToTime4xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xFastMathBR24(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
/* SinCosTable virtual BR versions */
void RealFFTf1xSinCosTableVBR16(fft_type *,HFFT);
void InverseRealFFTf1xSinCosTableVBR16(fft_type *,HFFT);
void ReorderToTime1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xSinCosTableVBR16(fft_type *,HFFT);
void InverseRealFFTf4xSinCosTableVBR16(fft_type *,HFFT);
void ReorderToTime4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xSinCosTableVBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf1xSinCosTableVBR16(fft_type *, FFTParam*);
void InverseRealFFTf1xSinCosTableVBR16(fft_type *, FFTParam*);
void ReorderToTime1xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xSinCosTableVBR16(fft_type *, FFTParam *);
void InverseRealFFTf4xSinCosTableVBR16(fft_type *, FFTParam *);
void ReorderToTime4xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xSinCosTableVBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
/* SinCosTable BR16 versions */
void RealFFTf1xSinCosTableBR16(fft_type *,HFFT);
void InverseRealFFTf1xSinCosTableBR16(fft_type *,HFFT);
void ReorderToTime1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xSinCosTableBR16(fft_type *,HFFT);
void InverseRealFFTf4xSinCosTableBR16(fft_type *,HFFT);
void ReorderToTime4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xSinCosTableBR16(HFFT hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf1xSinCosTableBR16(fft_type *, FFTParam*);
void InverseRealFFTf1xSinCosTableBR16(fft_type *, FFTParam*);
void ReorderToTime1xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq1xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void RealFFTf4xSinCosTableBR16(fft_type *, FFTParam *);
void InverseRealFFTf4xSinCosTableBR16(fft_type *, FFTParam *);
void ReorderToTime4xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *TimeOut);
void ReorderToFreq4xSinCosTableBR16(FFTParam *hFFT, fft_type *buffer, fft_type *RealOut, fft_type *ImagOut);
void TableUsage(int iMask);

View File

@ -273,7 +273,8 @@ protected:
};
static void ComputeSpectrumUsingRealFFTf
(float * __restrict buffer, HFFT hFFT, const float * __restrict window, size_t len, float * __restrict out)
(float * __restrict buffer, const FFTParam *hFFT,
const float * __restrict window, size_t len, float * __restrict out)
{
size_t i;
if(len > hFFT->Points * 2)
@ -924,7 +925,7 @@ bool SpecCache::CalculateOneSpectrum
}
else if (reassignment) {
static const double epsilon = 1e-16;
const HFFT hFFT = settings.hFFT;
const auto hFFT = settings.hFFT.get();
float *const scratch2 = scratch + fftLen;
std::copy(scratch, scratch2, scratch2);
@ -1024,7 +1025,7 @@ bool SpecCache::CalculateOneSpectrum
// This function mutates useBuffer
ComputeSpectrumUsingRealFFTf
(useBuffer, settings.hFFT, settings.window.get(), fftLen, results);
(useBuffer, settings.hFFT.get(), settings.window.get(), fftLen, results);
if (!gainFactors.empty()) {
// Apply a frequency-dependant gain factor
for (size_t ii = 0; ii < nBins; ++ii)
@ -1160,7 +1161,7 @@ void SpecCache::Populate
#endif
for (auto xx = lowerBoundX; xx < upperBoundX; ++xx) {
float *const results = &freq[nBins * xx];
const HFFT hFFT = settings.hFFT;
const auto hFFT = settings.hFFT.get();
for (size_t ii = 0; ii < nBins; ++ii) {
float &power = results[ii];
if (power <= 0)

View File

@ -220,7 +220,7 @@ EffectEqualization::EffectEqualization()
mCurve = NULL;
mPanel = NULL;
hFFT = InitializeFFT(windowSize);
hFFT = GetFFT(windowSize);
SetLinearEffectFlag(true);
@ -282,9 +282,6 @@ EffectEqualization::EffectEqualization()
EffectEqualization::~EffectEqualization()
{
if(hFFT)
EndFFT(hFFT);
hFFT = NULL;
}
// IdentInterface implementation
@ -1319,7 +1316,7 @@ void EffectEqualization::Filter(size_t len, float *buffer)
{
float re,im;
// Apply FFT
RealFFTf(buffer, hFFT);
RealFFTf(buffer, hFFT.get());
//FFT(len, false, inr, NULL, outr, outi);
// Apply filter
@ -1336,8 +1333,8 @@ void EffectEqualization::Filter(size_t len, float *buffer)
mFFTBuffer[1] = buffer[1] * mFilterFuncR[len/2];
// Inverse FFT and normalization
InverseRealFFTf(mFFTBuffer.get(), hFFT);
ReorderToTime(hFFT, mFFTBuffer.get(), buffer);
InverseRealFFTf(mFFTBuffer.get(), hFFT.get());
ReorderToTime(hFFT.get(), mFFTBuffer.get(), buffer);
}
//

View File

@ -688,7 +688,7 @@ void EffectEqualization48x::Filter1x(size_t len,
int i;
float real, imag;
// Apply FFT
RealFFTf1x(buffer, mEffectEqualization->hFFT);
RealFFTf1x(buffer, mEffectEqualization->hFFT.get());
// Apply filter
// DC component is purely real
@ -721,8 +721,8 @@ void EffectEqualization48x::Filter1x(size_t len,
scratchBuffer[1] = buffer[1] * filterFuncR;
// Inverse FFT and normalization
InverseRealFFTf1x(scratchBuffer, mEffectEqualization->hFFT);
ReorderToTime1x(mEffectEqualization->hFFT, scratchBuffer, buffer);
InverseRealFFTf1x(scratchBuffer, mEffectEqualization->hFFT.get());
ReorderToTime1x(mEffectEqualization->hFFT.get(), scratchBuffer, buffer);
}
bool EffectEqualization48x::ProcessBuffer4x(BufferInfo *bufferInfo)
@ -981,7 +981,7 @@ void EffectEqualization48x::Filter4x(size_t len,
int i;
__m128 real128, imag128;
// Apply FFT
RealFFTf4x(buffer, mEffectEqualization->hFFT);
RealFFTf4x(buffer, mEffectEqualization->hFFT.get());
// Apply filter
// DC component is purely real
@ -1015,8 +1015,8 @@ void EffectEqualization48x::Filter4x(size_t len,
localFFTBuffer[1] = _mm_mul_ps(localBuffer[1], filterFuncR);
// Inverse FFT and normalization
InverseRealFFTf4x(scratchBuffer, mEffectEqualization->hFFT);
ReorderToTime4x(mEffectEqualization->hFFT, scratchBuffer, buffer);
InverseRealFFTf4x(scratchBuffer, mEffectEqualization->hFFT.get());
ReorderToTime4x(mEffectEqualization->hFFT.get(), scratchBuffer, buffer);
}
#ifdef __AVX_ENABLED

View File

@ -640,7 +640,6 @@ bool EffectNoiseReduction::Process()
EffectNoiseReduction::Worker::~Worker()
{
EndFFT(hFFT);
}
bool EffectNoiseReduction::Worker::Process
@ -727,7 +726,7 @@ EffectNoiseReduction::Worker::Worker
, mSampleRate(sampleRate)
, mWindowSize(settings.WindowSize())
, hFFT(InitializeFFT(mWindowSize))
, hFFT(GetFFT(mWindowSize))
, mFFTBuffer(mWindowSize)
, mInWaveBuffer(mWindowSize)
, mOutOverlapBuffer(mWindowSize)
@ -945,7 +944,7 @@ void EffectNoiseReduction::Worker::FillFirstHistoryWindow()
mFFTBuffer[ii] = mInWaveBuffer[ii] * mInWindow[ii];
else
memmove(&mFFTBuffer[0], &mInWaveBuffer[0], mWindowSize * sizeof(float));
RealFFTf(&mFFTBuffer[0], hFFT);
RealFFTf(&mFFTBuffer[0], hFFT.get());
Record &record = *mQueue[0];
@ -1243,7 +1242,7 @@ void EffectNoiseReduction::Worker::ReduceNoise
}
// Invert the FFT into the output buffer
InverseRealFFTf(&mFFTBuffer[0], hFFT);
InverseRealFFTf(&mFFTBuffer[0], hFFT.get());
// Overlap-add
if (mOutWindow.size() > 0) {

View File

@ -288,7 +288,7 @@ void EffectNoiseRemoval::Initialize()
mImagFFTs.reinit(mHistoryLen, mSpectrumSize);
// Initialize the FFT
hFFT = InitializeFFT(mWindowSize);
hFFT = GetFFT(mWindowSize);
mFFTBuffer.reinit(mWindowSize);
mInWaveBuffer.reinit(mWindowSize);
@ -307,7 +307,7 @@ void EffectNoiseRemoval::Initialize()
void EffectNoiseRemoval::Cleanup()
{
EndFFT(hFFT);
hFFT.reset();
if (mDoProfile) {
ApplyFreqSmoothing(mNoiseThreshold.get());
@ -374,8 +374,8 @@ void EffectNoiseRemoval::FillFirstHistoryWindow()
{
for(size_t i = 0; i < mWindowSize; i++)
mFFTBuffer[i] = mInWaveBuffer[i];
RealFFTf(mFFTBuffer.get(), hFFT);
for(size_t i = 1; i < (mSpectrumSize-1); i++) {
RealFFTf(mFFTBuffer.get(), hFFT.get());
for(size_t i = 1; i + 1 < mSpectrumSize; i++) {
mRealFFTs[0][i] = mFFTBuffer[hFFT->BitReversed[i] ];
mImagFFTs[0][i] = mFFTBuffer[hFFT->BitReversed[i]+1];
mSpectrums[0][i] = mRealFFTs[0][i]*mRealFFTs[0][i] + mImagFFTs[0][i]*mImagFFTs[0][i];
@ -502,7 +502,7 @@ void EffectNoiseRemoval::RemoveNoise()
mFFTBuffer[1] = mRealFFTs[out][mSpectrumSize-1] * mGains[out][mSpectrumSize-1];
// Invert the FFT into the output buffer
InverseRealFFTf(mFFTBuffer.get(), hFFT);
InverseRealFFTf(mFFTBuffer.get(), hFFT.get());
// Overlap-add
for(size_t j = 0; j < (mSpectrumSize-1); j++) {

View File

@ -348,10 +348,7 @@ SpectrogramSettings::~SpectrogramSettings()
void SpectrogramSettings::DestroyWindows()
{
if (hFFT != NULL) {
EndFFT(hFFT);
hFFT = NULL;
}
hFFT.reset();
window.reset();
dWindow.reset();
tWindow.reset();
@ -420,9 +417,7 @@ void SpectrogramSettings::CacheWindows() const
const auto fftLen = WindowSize() * ZeroPaddingFactor();
const auto padding = (WindowSize() * (zeroPaddingFactor - 1)) / 2;
if (hFFT != NULL)
EndFFT(hFFT);
hFFT = InitializeFFT(fftLen);
hFFT = GetFFT(fftLen);
RecreateWindow(window, WINDOW, fftLen, padding, windowType, windowSize, scale);
if (algorithm == algReassignment) {
RecreateWindow(tWindow, TWINDOW, fftLen, padding, windowType, windowSize, scale);

View File

@ -13,6 +13,7 @@ Paul Licameli
#include "../Experimental.h"
#include "../SampleFormat.h"
#include "../RealFFTf.h"
#undef SPECTRAL_SELECTION_GLOBAL_SWITCH
@ -153,7 +154,7 @@ public:
// Following fields are derived from preferences.
// Variables used for computing the spectrum
mutable FFTParam *hFFT{};
mutable HFFT hFFT;
mutable Floats window;
// Two other windows for computing reassigned spectrogram