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#include "EffectOutputTracks.h"
25
26#include "WaveTrack.h"
27
28#include <math.h>
29
31{
32 //Iterate over each track
33 EffectOutputTracks outputs{ *mTracks };
34 bool bGoodResult = true;
35
36 mCurTrackNum = 0;
37 for (auto pOutWaveTrack : outputs.Get().Selected<WaveTrack>())
38 {
39 //Get start and end times from track
40 double trackStart = pOutWaveTrack->GetStartTime();
41 double trackEnd = pOutWaveTrack->GetEndTime();
42
43 //Set the current bounds to whichever left marker is
44 //greater and whichever right marker is less:
45 mCurT0 = mT0 < trackStart? trackStart: mT0;
46 mCurT1 = mT1 > trackEnd? trackEnd: mT1;
47
48 // Process only if the right marker is to the right of the left marker
49 if (mCurT1 > mCurT0) {
50
51 //Transform the marker timepoints to samples
52 auto start = pOutWaveTrack->TimeToLongSamples(mCurT0);
53 auto end = pOutWaveTrack->TimeToLongSamples(mCurT1);
54
55 //Get the track rate and samples
56 mCurRate = pOutWaveTrack->GetRate();
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 if (bGoodResult)
71 outputs.Commit();
72 return bGoodResult;
73}
74
75
76//ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
77//and executes ProcessSimpleMono on these blocks
80{
81 //Get the length of the buffer (as double). len is
82 //used simple to calculate a progress meter, so it is easier
83 //to make it a double now than it is to do it later
84 auto len = (end - start).as_double();
85
86 //Initiate a processing buffer. This buffer will (most likely)
87 //be shorter than the length of the track being processed.
88 Floats buffer{ track->GetMaxBlockSize() };
89
90 //Go through the track one buffer at a time. s counts which
91 //sample the current buffer starts at.
92 auto s = start;
93 while (s < end) {
94 //Get a block of samples (smaller than the size of the buffer)
95 //Adjust the block size if it is the final block in the track
96 const auto block =
98
99 //Get the samples from the track and put them in the buffer
100 track->GetFloats(buffer.get(), s, block);
101
102 //Process the buffer. If it fails, clean up and exit.
103 if (!ProcessSimpleMono(buffer.get(), block))
104 //Return false because the effect failed.
105 return false;
106
107 //Processing succeeded. copy the newly-changed samples back
108 //onto the track.
109 track->Set((samplePtr) buffer.get(), floatSample, s, block);
110
111 //Increment s one blockfull of samples
112 s += block;
113
114 //Update the Progress meter
116 (s - start).as_double() /
117 len))
118 return false;
119 }
120
121 //Return true because the effect processing succeeded.
122 return true;
123}
124
125//null implementation of NewTrackSimpleMono
127{
128 return true;
129}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
char * samplePtr
Definition: SampleFormat.h:55
double mT1
Definition: EffectBase.h:116
TrackList * mTracks
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:115
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:349
Performs effect computation.
Use this object to copy the input tracks to tentative outputTracks.
virtual bool NewTrackSimpleMono()=0
Definition: SimpleMono.cpp:126
bool ProcessOne(WaveTrack *t, sampleCount start, sampleCount end)
Definition: SimpleMono.cpp:78
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: SimpleMono.cpp:30
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
"narrow" overload fetches first channel only
Definition: SampleTrack.h:55
A Track that contains audio waveform data.
Definition: WaveTrack.h:59
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1839
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Definition: WaveTrack.cpp:2396
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:1819
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
Externalized state of a plug-in.