70 bool bGoodResult =
true;
73 auto &myInstance =
dynamic_cast<Instance&
>(instance);
74 bGoodResult = pThis->ProcessPass(myInstance,
settings);
77 bGoodResult = pThis->ProcessPass(myInstance,
settings);
79 pThis->ReplaceProcessedTracks(bGoodResult);
85 const auto duration =
settings.extra.GetDuration();
86 bool bGoodResult =
true;
92 size_t prevBufferSize = 0;
104 std::vector<std::shared_ptr<EffectInstance>> recycledInstances{
107 std::dynamic_pointer_cast<EffectInstanceEx>(instance.shared_from_this())
110 const bool multichannel = numAudioIn > 1;
111 auto range = multichannel
114 range.VisitWhile( bGoodResult,
118 if (!left.GetSelected())
119 return fallthrough();
125 const auto numChannels =
128 assert(numAudioIn > 1);
129 if (numChannels == 2) {
139 if (len > 0 && numAudioIn < 1) {
145 mSampleCnt = left.TimeToLongSamples(duration);
147 const auto sampleRate = left.GetRate();
150 auto max = left.GetMaxBlockSize() * 2;
152 if (blockSize == 0) {
159 const auto bufferSize =
160 ((max + (blockSize - 1)) / blockSize) * blockSize;
161 if (bufferSize == 0) {
172 assert(numAudioIn > 0);
177 std::max(1u, numAudioIn),
179 std::max<size_t>(1, bufferSize / blockSize));
184 if (prevBufferSize != bufferSize) {
188 for (
size_t i = 2; i < numAudioIn; i++)
191 prevBufferSize = bufferSize;
198 assert(numAudioOut > 0);
199 outBuffers.
Reinit(numAudioOut, blockSize,
200 (bufferSize / blockSize) + 1);
208 if (!pRight && !clear && numAudioIn > 1) {
213 const auto genLength = [
this, &
settings, &left, isGenerator](
214 ) -> std::optional<sampleCount> {
217 const auto duration =
settings.extra.GetDuration();
219 gPrefs->Read(
wxT(
"/AudioIO/EffectsPreviewLen"), &genDur, 6.0);
225 return sampleCount{ (left.GetRate() * genDur) + 0.5 };
231 const auto pollUser = [
this, numChannels, count, start,
232 length = (genLength ? *genLength : len).as_double()
234 if (numChannels > 1) {
236 count, (inPos - start).as_double() / length)
241 if (
TrackProgress(count, (inPos - start).as_double() / length))
248 assert(len == 0 || inBuffers.
Channels() > 0);
251 if (len == 0 && genLength)
255 assert(source.AcceptsBuffers(inBuffers));
256 assert(source.AcceptsBlockSize(inBuffers.
BlockSize()));
258 WaveTrackSink sink{ left, pRight, start, isGenerator, isProcessor,
261 assert(sink.AcceptsBuffers(outBuffers));
265 [
this, &recycledInstances, counter = 0]()
mutable {
266 auto index = counter++;
267 if (index < recycledInstances.size())
268 return recycledInstances[index];
273 genLength, sampleRate, left,
274 inBuffers, outBuffers);
276 sink.Flush(outBuffers,
284 t->SyncLockAdjust(
mT1,
mT0 + duration);
297 std::optional<sampleCount> genLength,
298 const double sampleRate,
const Track &track,
304 const auto blockSize = inBuffers.
BlockSize();
306 assert(blockSize == outBuffers.
BlockSize());
312 assert(pSource->AcceptsBlockSize(blockSize));
313 assert(pSource->AcceptsBuffers(outBuffers));
316 return task.RunLoop();
static Settings & settings()
Accumulates (non-interleaved) data during effect processing.
void Rewind()
Reset positions to starts of buffers.
void Reinit(unsigned nChannels, size_t blockSize, size_t nBlocks, size_t padding=0)
unsigned Channels() const
void ClearBuffer(unsigned iChannel, size_t n)
static std::unique_ptr< EffectStage > Create(bool multi, Source &upstream, Buffers &inBuffers, const Factory &factory, EffectSettings &settings, double sampleRate, std::optional< sampleCount > genLength, const Track &track)
Satisfies postcondition of constructor or returns null.
Downstream receiver of sample streams, taking Buffers as external context.
virtual bool AcceptsBuffers(const Buffers &buffers) const =0
Upstream producer of sample streams, taking Buffers as external context.
virtual bool AcceptsBlockSize(size_t blockSize) const =0
virtual bool AcceptsBuffers(const Buffers &buffers) const =0
std::shared_ptr< TrackList > mOutputTracks
bool IsPreviewing() const
const AudacityProject * FindProject() const
bool TrackGroupProgress(int whichGroup, double frac, const TranslatableString &={}) const
void CopyInputTracks(bool allSyncLockSelected=false)
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
Default implementation returns previewLength
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
EffectType GetType() const override
Type determines how it behaves.
void GetBounds(const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
virtual std::shared_ptr< EffectInstance > MakeInstance() const =0
Make an object maintaining short-term state of an Effect.
Performs effect computation.
virtual unsigned GetAudioInCount() const =0
How many input buffers to allocate at once.
virtual size_t SetBlockSize(size_t maxBlockSize)=0
virtual bool NeedsDither() const
virtual unsigned GetAudioOutCount() const =0
How many output buffers to allocate at once.
bool ProcessFinalize() noexcept override
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
bool Process(EffectSettings &settings) final
Uses the other virtual functions of this class.
const PerTrackEffect & mProcessor
Base class for many of the effects in Audacity.
bool ProcessPass(Instance &instance, EffectSettings &settings)
bool Process(EffectInstance &instance, EffectSettings &settings) const
~PerTrackEffect() override
std::function< std::shared_ptr< EffectInstance >()> Factory
static bool ProcessTrack(bool multi, const Factory &factory, EffectSettings &settings, AudioGraph::Source &source, AudioGraph::Sink &sink, std::optional< sampleCount > genLength, double sampleRate, const Track &track, Buffers &inBuffers, Buffers &outBuffers)
Adapts SampleTrack to the interface AudioGraph::Source.
static bool IsSyncLockSelected(const Track *pTrack)
Abstract base class for an object holding data associated with points on a time axis.
Continuation<> Fallthrough
Type of arguments passed as optional second parameter to TypeSwitch<void>() cases.
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
static ViewInfo & Get(AudacityProject &project)
A Track that contains audio waveform data.
Positions or offsets within audio files need a wide type.
AUDIO_GRAPH_API unsigned MakeChannelMap(const Track &track, bool multichannel, ChannelName map[3])
static RegisteredToolbarFactory factory
Copies from a Source to a Sink, mediated by Buffers.
Externalized state of a plug-in.