Audacity 3.2.0
SimpleMono.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 SimpleMono.cpp
6
7 Dominic Mazzoni
8
9*******************************************************************//*******************************************************************/
20
21
22
23#include "SimpleMono.h"
24
25#include "../WaveTrack.h"
26
27#include <math.h>
28
30{
31 //Iterate over each track
32 this->CopyInputTracks(); // Set up mOutputTracks.
33 bool bGoodResult = true;
34
35 mCurTrackNum = 0;
36 for( auto pOutWaveTrack : mOutputTracks->Selected< WaveTrack >() )
37 {
38 //Get start and end times from track
39 double trackStart = pOutWaveTrack->GetStartTime();
40 double trackEnd = pOutWaveTrack->GetEndTime();
41
42 //Set the current bounds to whichever left marker is
43 //greater and whichever right marker is less:
44 mCurT0 = mT0 < trackStart? trackStart: mT0;
45 mCurT1 = mT1 > trackEnd? trackEnd: mT1;
46
47 // Process only if the right marker is to the right of the left marker
48 if (mCurT1 > mCurT0) {
49
50 //Transform the marker timepoints to samples
51 auto start = pOutWaveTrack->TimeToLongSamples(mCurT0);
52 auto end = pOutWaveTrack->TimeToLongSamples(mCurT1);
53
54 //Get the track rate and samples
55 mCurRate = pOutWaveTrack->GetRate();
56 mCurChannel = pOutWaveTrack->GetChannel();
57
58 //NewTrackSimpleMono() will returns true by default
59 //ProcessOne() processes a single track
60 if (!NewTrackSimpleMono() || !ProcessOne(pOutWaveTrack, start, end))
61 {
62 bGoodResult = false;
63 break;
64 }
65 }
66
68 }
69
70 this->ReplaceProcessedTracks(bGoodResult);
71 return bGoodResult;
72}
73
74
75//ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
76//and executes ProcessSimpleMono on these blocks
79{
80 //Get the length of the buffer (as double). len is
81 //used simple to calculate a progress meter, so it is easier
82 //to make it a double now than it is to do it later
83 auto len = (end - start).as_double();
84
85 //Initiate a processing buffer. This buffer will (most likely)
86 //be shorter than the length of the track being processed.
87 Floats buffer{ track->GetMaxBlockSize() };
88
89 //Go through the track one buffer at a time. s counts which
90 //sample the current buffer starts at.
91 auto s = start;
92 while (s < end) {
93 //Get a block of samples (smaller than the size of the buffer)
94 //Adjust the block size if it is the final block in the track
95 const auto block =
97
98 //Get the samples from the track and put them in the buffer
99 track->GetFloats(buffer.get(), s, block);
100
101 //Process the buffer. If it fails, clean up and exit.
102 if (!ProcessSimpleMono(buffer.get(), block))
103 //Return false because the effect failed.
104 return false;
105
106 //Processing succeeded. copy the newly-changed samples back
107 //onto the track.
108 track->Set((samplePtr) buffer.get(), floatSample, s, block);
109
110 //Increment s one blockfull of samples
111 s += block;
112
113 //Update the Progress meter
115 (s - start).as_double() /
116 len))
117 return false;
118 }
119
120 //Return true because the effect processing succeeded.
121 return true;
122}
123
124//null implementation of NewTrackSimpleMono
126{
127 return true;
128}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
double mT1
Definition: EffectBase.h:107
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:105
double mT0
Definition: EffectBase.h:106
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:236
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:741
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:693
Performs effect computation.
virtual bool NewTrackSimpleMono()=0
Definition: SimpleMono.cpp:125
bool ProcessOne(WaveTrack *t, sampleCount start, sampleCount end)
Definition: SimpleMono.cpp:77
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
Definition: SimpleMono.cpp:29
virtual bool ProcessSimpleMono(float *buffer, size_t len)=0
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:67
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1806
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1788
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2195
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
Externalized state of a plug-in.