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 <TrackSpectrumTransformer.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
 
bool DoFinish () override
 Called after the last call to ProcessWindow(). More...
 

Private Attributes

WaveChannel *const mOutputTrack
 

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 18 of file TrackSpectrumTransformer.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 27 of file TrackSpectrumTransformer.h.

32 : SpectrumTransformer { needsOutput, inWindowType, outWindowType,
33 windowSize, stepsPerWindow, leadingPadding,
34 trailingPadding }
35 , mOutputTrack { pOutputTrack }
36 {
37 assert(!needsOutput || pOutputTrack != nullptr);
38 }
A class that transforms a portion of a wave track (preserving duration) by applying Fourier transform...

◆ ~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 51 of file TrackSpectrumTransformer.cpp.

52{
54}
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

Audacity: A Digital Audio Editor

TrackSpectrumTransformer.cpp

Paul Licameli

Implements SpectrumTransformer.

Definition at line 14 of file TrackSpectrumTransformer.cpp.

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

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 69 of file TrackSpectrumTransformer.cpp.

70{
72}
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.

Definition at line 56 of file TrackSpectrumTransformer.cpp.

58{
59 outputTrack.Flush();
60 auto tLen = outputTrack.LongSamplesToTime(len);
61 // Filtering effects always end up with more data than they started with.
62 // Delete this 'tail'.
63 outputTrack.Clear(tLen, outputTrack.GetEndTime());
64 return true;
65}
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:1161
void Flush() override
Definition: WaveTrack.cpp:2315
double GetEndTime() const override
Implement WideSampleSequence.
Definition: WaveTrack.cpp:2613
double LongSamplesToTime(sampleCount pos) const

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

Referenced by NoiseReductionBase::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 20 of file TrackSpectrumTransformer.cpp.

23{
24 if (!Start(queueLength))
25 return false;
26
27 auto bufferSize = channel.GetMaxBlockSize();
28 FloatVector buffer(bufferSize);
29
30 bool bLoopSuccess = true;
31 auto samplePos = start;
32 while (bLoopSuccess && samplePos < start + len)
33 {
34 // Get a blockSize of samples (smaller than the size of the buffer)
35 const auto blockSize = limitSampleBufferSize(
36 std::min(bufferSize, channel.GetBestBlockSize(samplePos)),
37 start + len - samplePos);
38
39 // Get the samples from the track and put them in the buffer
40 channel.GetFloats(buffer.data(), samplePos, blockSize);
41 samplePos += blockSize;
42 bLoopSuccess = ProcessSamples(processor, buffer.data(), blockSize);
43 }
44
45 if (!Finish(processor))
46 return false;
47
48 return bLoopSuccess;
49}
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.
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:129
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:851
size_t GetMaxBlockSize() const
Definition: WaveTrack.h:859

References SpectrumTransformer::Finish(), WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), WaveChannel::GetMaxBlockSize(), limitSampleBufferSize(), min(), 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 55 of file TrackSpectrumTransformer.h.

Referenced by DoOutput().


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