Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
PowerSpectrumGetter Class Reference

Much faster that FFT.h's PowerSpectrum, at least in Short-Time Fourier Transform-like situations, where many power spectra of the same size are needed. Currently only power spectrum, but may be generalized to other uses. More...

#include <PowerSpectrumGetter.h>

Collaboration diagram for PowerSpectrumGetter:
[legend]

Public Member Functions

 PowerSpectrumGetter (int fftSize)
 
 ~PowerSpectrumGetter ()
 
void operator() (PffftFloats alignedBuffer, PffftFloats alignedOutput)
 Computes the power spectrum of buffer into output. More...
 

Private Attributes

const int mFftSize
 
PffftSetupHolder mSetup
 
PffftFloatVector mWork
 

Detailed Description

Much faster that FFT.h's PowerSpectrum, at least in Short-Time Fourier Transform-like situations, where many power spectra of the same size are needed. Currently only power spectrum, but may be generalized to other uses.

Definition at line 208 of file PowerSpectrumGetter.h.

Constructor & Destructor Documentation

◆ PowerSpectrumGetter()

PowerSpectrumGetter::PowerSpectrumGetter ( int  fftSize)
explicit

Definition at line 41 of file PowerSpectrumGetter.cpp.

42 : mFftSize { fftSize }
43 , mSetup { pffft_new_setup(fftSize, PFFFT_REAL) }
44 , mWork(fftSize)
45{
46}
PffftFloatVector mWork
PffftSetupHolder mSetup

◆ ~PowerSpectrumGetter()

PowerSpectrumGetter::~PowerSpectrumGetter ( )

Definition at line 48 of file PowerSpectrumGetter.cpp.

49{
50}

Member Function Documentation

◆ operator()()

void PowerSpectrumGetter::operator() ( PffftFloats  alignedBuffer,
PffftFloats  alignedOutput 
)

Computes the power spectrum of buffer into output.

Parameters
bufferInput samples of size fftSize. Also gets used as placeholder and gets overwritten, so copy your data elsewhere if you need it again afterwards.
outputfftSize / 2 + 1 samples.

Definition at line 52 of file PowerSpectrumGetter.cpp.

54{
55 const auto buffer = alignedBuffer.get();
56 const auto output = alignedOutput.get();
57 pffft_transform_ordered(mSetup.get(),
58 buffer, buffer, mWork.data(), PFFFT_FORWARD);
59 output[0] = buffer[0] * buffer[0];
60 for (auto i = 1; i < mFftSize / 2; ++i)
61 output[i] =
62 buffer[i * 2] * buffer[i * 2] + buffer[i * 2 + 1] * buffer[i * 2 + 1];
63 output[mFftSize / 2] = buffer[1] * buffer[1];
64}
float * get() const noexcept

References PffftFloats::get(), mFftSize, mSetup, and mWork.

Here is the call graph for this function:

Member Data Documentation

◆ mFftSize

const int PowerSpectrumGetter::mFftSize
private

Definition at line 224 of file PowerSpectrumGetter.h.

Referenced by operator()().

◆ mSetup

PffftSetupHolder PowerSpectrumGetter::mSetup
private

Definition at line 225 of file PowerSpectrumGetter.h.

Referenced by operator()().

◆ mWork

PffftFloatVector PowerSpectrumGetter::mWork
private

Definition at line 226 of file PowerSpectrumGetter.h.

Referenced by operator()().


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