Audacity 3.2.0
|
A class that transforms a portion of a wave track (preserving duration) by applying Fourier transform, then modifying coefficients, then inverse Fourier transform and overlap-add to reconstruct. More...
#include <SpectrumTransformer.h>
Classes | |
struct | Window |
Derive this class to add information to the queue. More... | |
Public Types | |
using | FloatVector = std::vector< float > |
using | WindowProcessor = std::function< bool(SpectrumTransformer &) > |
Type of function that transforms windows in the queue. More... | |
Public Member Functions | |
SpectrumTransformer (bool needsOutput, eWindowFunctions inWindowType, eWindowFunctions outWindowType, size_t windowSize, unsigned stepsPerWindow, bool leadingPadding, bool trailingPadding) | |
virtual | ~SpectrumTransformer () |
bool | NeedsOutput () const |
bool | Start (size_t queueLength) |
Call once before a sequence of calls to ProcessSamples; Invokes DoStart. More... | |
bool | ProcessSamples (const WindowProcessor &processor, const float *buffer, size_t len) |
Call multiple times. More... | |
bool | Finish (const WindowProcessor &processor) |
virtual std::unique_ptr< Window > | NewWindow (size_t windowSize) |
Allocates a window to place in the queue. More... | |
virtual bool | DoStart () |
Called before any calls to ProcessWindow. More... | |
virtual void | DoOutput (const float *outBuffer, size_t mStepSize)=0 |
Called within ProcessSamples if output was requested. More... | |
virtual bool | DoFinish () |
Called after the last call to ProcessWindow(). More... | |
size_t | TotalQueueSize () const |
Useful functions to implement WindowProcesser: More... | |
size_t | CurrentQueueSize () const |
How many windows in the queue have been filled? More... | |
bool | QueueIsFull () const |
Window & | Nth (int n) |
Access the queue, so you can inspect and modify any window in it. More... | |
Window & | Newest () |
Window & | Latest () |
Protected Attributes | |
const size_t | mWindowSize |
const size_t | mSpectrumSize |
const unsigned | mStepsPerWindow |
const size_t | mStepSize |
const bool | mLeadingPadding |
const bool | mTrailingPadding |
Private Member Functions | |
void | ResizeQueue (size_t queueLength) |
void | FillFirstWindow () |
void | RotateWindows () |
void | OutputStep () |
Private Attributes | |
std::vector< std::unique_ptr< Window > > | mQueue |
HFFT | hFFT |
sampleCount | mInSampleCount = 0 |
sampleCount | mOutStepCount = 0 |
sometimes negative More... | |
size_t | mInWavePos = 0 |
FloatVector | mFFTBuffer |
These have size mWindowSize: More... | |
FloatVector | mInWaveBuffer |
FloatVector | mOutOverlapBuffer |
FloatVector | mInWindow |
These have size mWindowSize, or 0 for rectangular window: More... | |
FloatVector | mOutWindow |
const bool | mNeedsOutput |
A class that transforms a portion of a wave track (preserving duration) by applying Fourier transform, then modifying coefficients, then inverse Fourier transform and overlap-add to reconstruct.
Definition at line 33 of file SpectrumTransformer.h.
using SpectrumTransformer::FloatVector = std::vector<float> |
Definition at line 37 of file SpectrumTransformer.h.
using SpectrumTransformer::WindowProcessor = std::function< bool(SpectrumTransformer&) > |
Type of function that transforms windows in the queue.
Called repeatedly, with the newest window in the queue taken from input, and the last window of the queue about to be inverse-transformed for output.
Definition at line 43 of file SpectrumTransformer.h.
SpectrumTransformer::SpectrumTransformer | ( | bool | needsOutput, |
eWindowFunctions | inWindowType, | ||
eWindowFunctions | outWindowType, | ||
size_t | windowSize, | ||
unsigned | stepsPerWindow, | ||
bool | leadingPadding, | ||
bool | trailingPadding | ||
) |
!(inWindowType == eWinFuncRectangular && outWindowType eWinFuncRectangular)
windowSize % stepsPerWindow == 0
windowSize
is a power of 2 needsOutput | Whether to do the inverse FFT |
inWindowType | Used in FFT transform |
outWindowType | Used in inverse FFT transform |
windowSize | must be a power of 2 |
stepsPerWindow | determines the overlap |
leadingPadding | Whether to start the queue with windows that partially overlap the first full window of input samples |
trailingPadding | Whether to stop the procedure after the last complete window of input is added to the queue |
Definition at line 16 of file SpectrumTransformer.cpp.
References eWinFuncRectangular, mInWindow, mOutWindow, mStepSize, mStepsPerWindow, mWindowSize, and NewWindowFunc().
|
virtualdefault |
size_t SpectrumTransformer::CurrentQueueSize | ( | ) | const |
How many windows in the queue have been filled?
(Not always the allocated size of the queue)
Definition at line 258 of file SpectrumTransformer.cpp.
References mLeadingPadding, mOutStepCount, mQueue, mStepsPerWindow, and size.
Referenced by NoiseReductionBase::Worker::ReduceNoise().
|
virtual |
Called after the last call to ProcessWindow().
Reimplemented in MyTransformer, TrackSpectrumTransformer, and SpectralDataManager::Worker.
Definition at line 97 of file SpectrumTransformer.cpp.
Referenced by TrackSpectrumTransformer::DoFinish(), and Finish().
|
pure virtual |
Called within ProcessSamples if output was requested.
Implemented in TrackSpectrumTransformer.
Referenced by OutputStep().
|
virtual |
Called before any calls to ProcessWindow.
More queue initializations can be done here.
Reimplemented in MyTransformer, TrackSpectrumTransformer, and SpectralDataManager::Worker.
Definition at line 92 of file SpectrumTransformer.cpp.
Referenced by TrackSpectrumTransformer::DoStart(), and Start().
|
private |
Definition at line 194 of file SpectrumTransformer.cpp.
References hFFT, mFFTBuffer, mInWaveBuffer, mInWindow, mSpectrumSize, mWindowSize, Nth(), and RealFFTf().
Referenced by ProcessSamples().
bool SpectrumTransformer::Finish | ( | const WindowProcessor & | processor | ) |
Call once after a sequence of calls to ProcessSamples; flushes the queue and Invokes DoFinish
Definition at line 236 of file SpectrumTransformer.cpp.
References DoFinish(), mInSampleCount, mOutStepCount, mStepSize, mTrailingPadding, and ProcessSamples().
Referenced by TrackSpectrumTransformer::Process().
|
inline |
Definition at line 144 of file SpectrumTransformer.h.
|
inline |
Definition at line 65 of file SpectrumTransformer.h.
|
inline |
Definition at line 143 of file SpectrumTransformer.h.
|
virtual |
Allocates a window to place in the queue.
Only when initializing – windows are recycled thereafter. You can derive from Window to add fields, and then override this factory function.
Reimplemented in MyTransformer, and SpectralDataManager::Worker.
Definition at line 86 of file SpectrumTransformer.cpp.
Referenced by ResizeQueue().
|
inline |
Access the queue, so you can inspect and modify any window in it.
Newer windows are at earlier indices. You can't modify the length of it
Definition at line 141 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), and SpectralDataManager::Worker::NthWindow().
|
private |
Definition at line 272 of file SpectrumTransformer.cpp.
References DoOutput(), hFFT, InverseRealFFTf(), mFFTBuffer, SpectrumTransformer::Window::mImagFFTs, mNeedsOutput, mOutOverlapBuffer, mOutStepCount, mOutWindow, mQueue, SpectrumTransformer::Window::mRealFFTs, mSpectrumSize, mStepSize, mWindowSize, and QueueIsFull().
Referenced by ProcessSamples().
bool SpectrumTransformer::ProcessSamples | ( | const WindowProcessor & | processor, |
const float * | buffer, | ||
size_t | len | ||
) |
Call multiple times.
buffer | null if flushing the end |
Definition at line 146 of file SpectrumTransformer.cpp.
References FillFirstWindow(), min(), mInSampleCount, mInWaveBuffer, mInWavePos, mOutStepCount, mStepSize, mWindowSize, OutputStep(), and RotateWindows().
Referenced by Finish(), and TrackSpectrumTransformer::Process().
bool SpectrumTransformer::QueueIsFull | ( | ) | const |
Whether the last window in the queue overlapped the input at least partially and its coefficients will affect output.
Definition at line 326 of file SpectrumTransformer.cpp.
References mLeadingPadding, mOutStepCount, and mStepsPerWindow.
Referenced by OutputStep(), and NoiseReductionBase::Worker::ReduceNoise().
|
private |
Definition at line 184 of file SpectrumTransformer.cpp.
References mQueue, mWindowSize, and NewWindow().
Referenced by Start().
|
private |
Definition at line 231 of file SpectrumTransformer.cpp.
References mQueue, and staffpad::vo::rotate().
Referenced by ProcessSamples().
bool SpectrumTransformer::Start | ( | size_t | queueLength | ) |
Call once before a sequence of calls to ProcessSamples; Invokes DoStart.
Definition at line 102 of file SpectrumTransformer.cpp.
References DoStart(), mInSampleCount, mInWaveBuffer, mInWavePos, mLeadingPadding, mOutOverlapBuffer, mOutStepCount, mQueue, mStepSize, mStepsPerWindow, mWindowSize, and ResizeQueue().
Referenced by TrackSpectrumTransformer::Process().
|
inline |
Useful functions to implement WindowProcesser:
How many windows in the queue have been allocated?
Definition at line 129 of file SpectrumTransformer.h.
|
private |
Definition at line 165 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), and OutputStep().
|
private |
These have size mWindowSize:
Definition at line 171 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), and OutputStep().
|
private |
Definition at line 166 of file SpectrumTransformer.h.
Referenced by Finish(), ProcessSamples(), and Start().
|
private |
Definition at line 172 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), ProcessSamples(), and Start().
|
private |
Definition at line 168 of file SpectrumTransformer.h.
Referenced by ProcessSamples(), and Start().
|
private |
These have size mWindowSize, or 0 for rectangular window:
Definition at line 175 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), and SpectrumTransformer().
|
protected |
Definition at line 159 of file SpectrumTransformer.h.
Referenced by CurrentQueueSize(), QueueIsFull(), and Start().
|
private |
Definition at line 178 of file SpectrumTransformer.h.
Referenced by OutputStep().
|
private |
Definition at line 173 of file SpectrumTransformer.h.
Referenced by OutputStep(), and Start().
|
private |
sometimes negative
Definition at line 167 of file SpectrumTransformer.h.
Referenced by CurrentQueueSize(), Finish(), OutputStep(), ProcessSamples(), QueueIsFull(), and Start().
|
private |
Definition at line 176 of file SpectrumTransformer.h.
Referenced by OutputStep(), and SpectrumTransformer().
|
private |
Definition at line 164 of file SpectrumTransformer.h.
Referenced by CurrentQueueSize(), OutputStep(), ResizeQueue(), RotateWindows(), and Start().
|
protected |
Definition at line 154 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), and OutputStep().
|
protected |
Definition at line 157 of file SpectrumTransformer.h.
Referenced by TrackSpectrumTransformer::DoOutput(), Finish(), OutputStep(), ProcessSamples(), SpectrumTransformer(), and Start().
|
protected |
Definition at line 156 of file SpectrumTransformer.h.
Referenced by CurrentQueueSize(), QueueIsFull(), SpectrumTransformer(), and Start().
|
protected |
Definition at line 161 of file SpectrumTransformer.h.
Referenced by Finish().
|
protected |
Definition at line 153 of file SpectrumTransformer.h.
Referenced by FillFirstWindow(), OutputStep(), ProcessSamples(), ResizeQueue(), SpectrumTransformer(), and Start().