Audacity 3.2.0
TrackSpectrumTransformer.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TrackSpectrumTransformer.cpp
6
7Paul Licameli
8
9**********************************************************************/
11
12#include "WaveTrack.h"
13
15 const float* outBuffer, size_t mStepSize)
16{
18}
19
21 const WindowProcessor& processor, const WaveChannel& channel,
22 size_t queueLength, sampleCount start, sampleCount len)
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}
50
52{
54}
55
57 WaveTrack& outputTrack, sampleCount len)
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}
66
68
70{
72}
int min(int a, int b)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
const char * constSamplePtr
Definition: SampleFormat.h:58
std::function< bool(SpectrumTransformer &) > WindowProcessor
Type of function that transforms windows in the queue.
bool Finish(const WindowProcessor &processor)
virtual bool DoStart()
Called before any calls to ProcessWindow.
std::vector< float > FloatVector
bool ProcessSamples(const WindowProcessor &processor, const float *buffer, size_t len)
Call multiple times.
virtual bool DoFinish()
Called after the last call to ProcessWindow().
bool Start(size_t queueLength)
Call once before a sequence of calls to ProcessSamples; Invokes DoStart.
~TrackSpectrumTransformer() override
void DoOutput(const float *outBuffer, size_t mStepSize) override
bool DoFinish() override
Called after the last call to ProcessWindow().
static bool PostProcess(WaveTrack &outputTrack, sampleCount len)
Final flush and trimming of tail samples.
bool DoStart() override
Called before any calls to ProcessWindow.
bool Process(const WindowProcessor &processor, const WaveChannel &channel, size_t queueLength, sampleCount start, sampleCount len)
Invokes Start(), ProcessSamples(), and Finish()
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
Definition: WaveTrack.cpp:2237
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
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
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
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19