Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
TrackSpectrumTransformer Class Reference

Subclass of SpectrumTransformer that rewrites a track. More...

#include <SpectrumTransformer.h>

Inheritance diagram for TrackSpectrumTransformer:
[legend]
Collaboration diagram for TrackSpectrumTransformer:
[legend]

Public Member Functions

 TrackSpectrumTransformer (WaveChannel *pOutputTrack, bool needsOutput, eWindowFunctions inWindowType, eWindowFunctions outWindowType, size_t windowSize, unsigned stepsPerWindow, bool leadingPadding, bool trailingPadding)
 
 ~TrackSpectrumTransformer () override
 
bool Process (const WindowProcessor &processor, const WaveChannel &channel, size_t queueLength, sampleCount start, sampleCount len)
 Invokes Start(), ProcessSamples(), and Finish() More...
 
- Public Member Functions inherited from SpectrumTransformer
 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< WindowNewWindow (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
 
WindowNth (int n)
 Access the queue, so you can inspect and modify any window in it. More...
 
WindowNewest ()
 
WindowLatest ()
 

Static Public Member Functions

static bool PostProcess (WaveTrack &outputTrack, sampleCount len)
 Final flush and trimming of tail samples. More...
 

Protected Member Functions

bool DoStart () override
 Called before any calls to ProcessWindow. More...
 
void DoOutput (const float *outBuffer, size_t mStepSize) override
 Called within ProcessSamples if output was requested. More...
 
bool DoFinish () override
 Called after the last call to ProcessWindow(). More...
 

Private Attributes

WaveChannel *const mOutputTrack
 
const WaveChannelmpChannel = nullptr
 

Additional Inherited Members

- Public Types inherited from SpectrumTransformer
using FloatVector = std::vector< float >
 
using WindowProcessor = std::function< bool(SpectrumTransformer &) >
 Type of function that transforms windows in the queue. More...
 
- Protected Attributes inherited from SpectrumTransformer
const size_t mWindowSize
 
const size_t mSpectrumSize
 
const unsigned mStepsPerWindow
 
const size_t mStepSize
 
const bool mLeadingPadding
 
const bool mTrailingPadding
 

Detailed Description

Subclass of SpectrumTransformer that rewrites a track.

Definition at line 186 of file SpectrumTransformer.h.

Constructor & Destructor Documentation

◆ TrackSpectrumTransformer()

TrackSpectrumTransformer::TrackSpectrumTransformer ( WaveChannel pOutputTrack,
bool  needsOutput,
eWindowFunctions  inWindowType,
eWindowFunctions  outWindowType,
size_t  windowSize,
unsigned  stepsPerWindow,
bool  leadingPadding,
bool  trailingPadding 
)
inline

Precondition
!(inWindowType == eWinFuncRectangular && outWindowType eWinFuncRectangular)
windowSize % stepsPerWindow == 0
windowSize is a power of 2
!needsOutput || pOutputTrack != nullptr

Definition at line 193 of file SpectrumTransformer.h.

197 : SpectrumTransformer{ needsOutput, inWindowType, outWindowType,
198 windowSize, stepsPerWindow, leadingPadding, trailingPadding
199 }
200 , mOutputTrack{ pOutputTrack }
201 {
202 assert(!needsOutput || pOutputTrack != nullptr);
203 }
A class that transforms a portion of a wave track (preserving duration) by applying Fourier transform...
WaveChannel *const mOutputTrack

◆ ~TrackSpectrumTransformer()

TrackSpectrumTransformer::~TrackSpectrumTransformer ( )
overridedefault

Member Function Documentation

◆ DoFinish()

bool TrackSpectrumTransformer::DoFinish ( )
overrideprotectedvirtual

Called after the last call to ProcessWindow().

Returns
false to abort processing. Default implementation just returns true.

Reimplemented from SpectrumTransformer.

Definition at line 373 of file SpectrumTransformer.cpp.

374{
376}
virtual bool DoFinish()
Called after the last call to ProcessWindow().

References SpectrumTransformer::DoFinish().

Referenced by MyTransformer::DoFinish(), and SpectralDataManager::Worker::DoFinish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoOutput()

void TrackSpectrumTransformer::DoOutput ( const float *  outBuffer,
size_t  mStepSize 
)
overrideprotectedvirtual

Called within ProcessSamples if output was requested.

Implements SpectrumTransformer.

Definition at line 104 of file SpectrumTransformer.cpp.

105{
107}
const char * constSamplePtr
Definition: SampleFormat.h:58
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
Definition: WaveTrack.cpp:2698

References WaveChannel::Append(), floatSample, mOutputTrack, and SpectrumTransformer::mStepSize.

Here is the call graph for this function:

◆ DoStart()

bool TrackSpectrumTransformer::DoStart ( )
overrideprotectedvirtual

Called before any calls to ProcessWindow.

More queue initializations can be done here.

Returns
false to abort processing. Default implementation just returns true.

Reimplemented from SpectrumTransformer.

Definition at line 396 of file SpectrumTransformer.cpp.

397{
399}
virtual bool DoStart()
Called before any calls to ProcessWindow.

References SpectrumTransformer::DoStart().

Referenced by MyTransformer::DoStart(), and SpectralDataManager::Worker::DoStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PostProcess()

bool TrackSpectrumTransformer::PostProcess ( WaveTrack outputTrack,
sampleCount  len 
)
static

Final flush and trimming of tail samples.

Precondition
outputTrack.IsLeader()

Definition at line 378 of file SpectrumTransformer.cpp.

380{
381 assert(outputTrack.IsLeader());
382 outputTrack.Flush();
383 auto tLen = outputTrack.LongSamplesToTime(len);
384 // Filtering effects always end up with more data than they started with.
385 // Delete this 'tail'.
386 outputTrack.Clear(tLen, outputTrack.GetEndTime());
387 return true;
388}
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:1479
bool IsLeader() const override
Definition: WaveTrack.cpp:2820
void Flush() override
Definition: WaveTrack.cpp:2776
double GetEndTime() const override
Implement WideSampleSequence.
Definition: WaveTrack.cpp:3092
double LongSamplesToTime(sampleCount pos) const

References WaveTrack::Clear(), WaveTrack::Flush(), WaveTrack::GetEndTime(), WaveTrack::IsLeader(), and WideSampleSequence::LongSamplesToTime().

Referenced by EffectNoiseReduction::Worker::Process(), and SpectralDataManager::ProcessTracks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Process()

bool TrackSpectrumTransformer::Process ( const WindowProcessor processor,
const WaveChannel channel,
size_t  queueLength,
sampleCount  start,
sampleCount  len 
)

Invokes Start(), ProcessSamples(), and Finish()

Definition at line 341 of file SpectrumTransformer.cpp.

344{
345 mpChannel = &channel;
346
347 if (!Start(queueLength))
348 return false;
349
350 auto bufferSize = channel.GetMaxBlockSize();
351 FloatVector buffer(bufferSize);
352
353 bool bLoopSuccess = true;
354 auto samplePos = start;
355 while (bLoopSuccess && samplePos < start + len) {
356 //Get a blockSize of samples (smaller than the size of the buffer)
357 const auto blockSize = limitSampleBufferSize(
358 std::min(bufferSize, channel.GetBestBlockSize(samplePos)),
359 start + len - samplePos);
360
361 //Get the samples from the track and put them in the buffer
362 channel.GetFloats(buffer.data(), samplePos, blockSize);
363 samplePos += blockSize;
364 bLoopSuccess = ProcessSamples(processor, buffer.data(), blockSize);
365 }
366
367 if (!Finish(processor))
368 return false;
369
370 return bLoopSuccess;
371}
int min(int a, int b)
std::vector< float > FloatVector
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
bool Finish(const WindowProcessor &processor)
bool ProcessSamples(const WindowProcessor &processor, const float *buffer, size_t len)
Call multiple times.
bool Start(size_t queueLength)
Call once before a sequence of calls to ProcessSamples; Invokes DoStart.
const WaveChannel * mpChannel
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:159
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:1244
size_t GetMaxBlockSize() const
Definition: WaveTrack.h:1252

References SpectrumTransformer::Finish(), WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), WaveChannel::GetMaxBlockSize(), limitSampleBufferSize(), min(), mpChannel, SpectrumTransformer::ProcessSamples(), and SpectrumTransformer::Start().

Referenced by SpectralDataManager::Worker::Process(), SpectralDataManager::Worker::ProcessOvertones(), and SpectralDataManager::Worker::ProcessSnapping().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mOutputTrack

WaveChannel* const TrackSpectrumTransformer::mOutputTrack
private

Definition at line 222 of file SpectrumTransformer.h.

Referenced by DoOutput().

◆ mpChannel

const WaveChannel* TrackSpectrumTransformer::mpChannel = nullptr
private

Definition at line 223 of file SpectrumTransformer.h.

Referenced by Process().


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