Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
staffpad::audio::FourierTransform Class Reference

#include <FourierTransform_pffft.h>

Public Member Functions

 FourierTransform (int32_t newBlockSize)
 
 ~FourierTransform ()
 
int getSize () const
 
void forwardReal (const SamplesReal &t, SamplesComplex &c)
 
void inverseReal (const SamplesComplex &c, SamplesReal &t)
 

Private Attributes

PFFFT_Setup * realFftSpec = nullptr
 
PFFFT_Setup * complexFftSpec = nullptr
 
float * _pffft_scratch = nullptr
 
const int32_t _blockSize
 
int32_t _order = 0
 

Detailed Description

Definition at line 14 of file FourierTransform_pffft.h.

Constructor & Destructor Documentation

◆ FourierTransform()

staffpad::audio::FourierTransform::FourierTransform ( int32_t  newBlockSize)

Definition at line 7 of file FourierTransform_pffft.cpp.

8 : _blockSize { newBlockSize }
9{
10 _pffft_scratch = (float*)pffft_aligned_malloc(_blockSize * sizeof(float));
11 realFftSpec = pffft_new_setup(_blockSize, PFFFT_REAL);
12}

References _blockSize, _pffft_scratch, and realFftSpec.

◆ ~FourierTransform()

staffpad::audio::FourierTransform::~FourierTransform ( )

Definition at line 14 of file FourierTransform_pffft.cpp.

15{
17 {
18 pffft_aligned_free(_pffft_scratch);
19 _pffft_scratch = nullptr;
20 }
21 if (realFftSpec)
22 {
23 pffft_destroy_setup(realFftSpec);
24 realFftSpec = nullptr;
25 }
26}

References _pffft_scratch, and realFftSpec.

Member Function Documentation

◆ forwardReal()

void staffpad::audio::FourierTransform::forwardReal ( const SamplesReal t,
SamplesComplex c 
)

Definition at line 28 of file FourierTransform_pffft.cpp.

29{
30 assert(t.getNumSamples() == _blockSize);
31
32 for (auto ch = 0; ch < t.getNumChannels(); ++ch)
33 {
34 auto* spec = c.getPtr(ch); // interleaved complex numbers, size _blockSize + 2
35 auto* cpx_flt = (float*)spec;
36 pffft_transform_ordered(realFftSpec, t.getPtr(ch), cpx_flt, _pffft_scratch, PFFFT_FORWARD);
37 // pffft combines dc and nyq values into the first complex value,
38 // adjust to CCS format.
39 auto dc = cpx_flt[0];
40 auto nyq = cpx_flt[1];
41 spec[0] = {dc, 0.f};
42 spec[c.getNumSamples() - 1] = {nyq, 0.f};
43 }
44}

References _blockSize, _pffft_scratch, staffpad::SamplesFloat< T >::getNumChannels(), staffpad::SamplesFloat< T >::getNumSamples(), staffpad::SamplesFloat< T >::getPtr(), and realFftSpec.

Here is the call graph for this function:

◆ getSize()

int staffpad::audio::FourierTransform::getSize ( ) const
inline

Definition at line 20 of file FourierTransform_pffft.h.

20{ return static_cast<int>(_blockSize); }

References _blockSize.

◆ inverseReal()

void staffpad::audio::FourierTransform::inverseReal ( const SamplesComplex c,
SamplesReal t 
)

Definition at line 46 of file FourierTransform_pffft.cpp.

47{
48 assert(c.getNumSamples() == _blockSize / 2 + 1);
49
50 for (auto ch = 0; ch < c.getNumChannels(); ++ch)
51 {
52 auto* spec = c.getPtr(ch);
53 // Use t to convert in-place from CCS to pffft format
54 t.assignSamples(ch, (float*)spec);
55 auto* ts = t.getPtr(ch);
56 ts[0] = spec[0].real();
57 ts[1] = spec[c.getNumSamples() - 1].real();
58 pffft_transform_ordered(realFftSpec, ts, ts, _pffft_scratch, PFFFT_BACKWARD);
59 }
60}

References _blockSize, _pffft_scratch, staffpad::SamplesFloat< T >::assignSamples(), staffpad::SamplesFloat< T >::getNumChannels(), staffpad::SamplesFloat< T >::getNumSamples(), staffpad::SamplesFloat< T >::getPtr(), and realFftSpec.

Here is the call graph for this function:

Member Data Documentation

◆ _blockSize

const int32_t staffpad::audio::FourierTransform::_blockSize
private

Definition at line 30 of file FourierTransform_pffft.h.

Referenced by forwardReal(), FourierTransform(), getSize(), and inverseReal().

◆ _order

int32_t staffpad::audio::FourierTransform::_order = 0
private

Definition at line 31 of file FourierTransform_pffft.h.

◆ _pffft_scratch

float* staffpad::audio::FourierTransform::_pffft_scratch = nullptr
private

◆ complexFftSpec

PFFFT_Setup* staffpad::audio::FourierTransform::complexFftSpec = nullptr
private

Definition at line 27 of file FourierTransform_pffft.h.

◆ realFftSpec

PFFFT_Setup* staffpad::audio::FourierTransform::realFftSpec = nullptr
private

The documentation for this class was generated from the following files: