Audacity 3.2.0
Namespaces | Classes | Functions | Variables
anonymous_namespace{WaveTrack.cpp} Namespace Reference

Namespaces

namespace  anonymous_namespace{WaveTrack.cpp}
 

Classes

struct  SplitInfo
 
struct  WaveTrackData
 

Functions

WaveTrack::IntervalHolder GetRenderedCopy (const WaveTrack::IntervalHolder &pInterval, const std::function< void(double)> &reportProgress, const SampleBlockFactoryPtr &factory, sampleFormat format)
 
Track::LinkType ToLinkType (int value)
 
bool ClipsAreUnique (const WaveClipHolders &clips)
 

Variables

static const ChannelGroup::Attachments::RegisteredFactory waveTrackDataFactory
 

Detailed Description

Postcondition
result: result->GetStretchRatio() == 1

Function Documentation

◆ ClipsAreUnique()

bool anonymous_namespace{WaveTrack.cpp}::ClipsAreUnique ( const WaveClipHolders clips)

Definition at line 3200 of file WaveTrack.cpp.

3201{
3202 // This is used only in assertions
3203 using Set = std::unordered_set<WaveClipHolder>;
3204 return clips.size() == Set{ clips.begin(), clips.end() }.size();
3205}

Referenced by WaveTrack::InsertInterval().

Here is the caller graph for this function:

◆ GetRenderedCopy()

WaveTrack::IntervalHolder anonymous_namespace{WaveTrack.cpp}::GetRenderedCopy ( const WaveTrack::IntervalHolder pInterval,
const std::function< void(double)> &  reportProgress,
const SampleBlockFactoryPtr factory,
sampleFormat  format 
)

Definition at line 78 of file WaveTrack.cpp.

82{
83 auto &interval = *pInterval;
84 using Interval = WaveTrack::Interval;
85 if (!interval.HasPitchOrSpeed())
86 return pInterval;
87
88 const auto dst = std::make_shared<Interval>(
89 interval.NChannels(), factory, format, interval.GetRate());
90
91 const auto originalPlayStartTime = interval.GetPlayStartTime();
92 const auto originalPlayEndTime = interval.GetPlayEndTime();
93 const auto stretchRatio = interval.GetStretchRatio();
94
95 auto success = false;
96 Finally Do { [&] {
97 if (!success)
98 {
99 interval.TrimLeftTo(originalPlayStartTime);
100 interval.TrimRightTo(originalPlayEndTime);
101 }
102 } };
103
104 // Leave 1 second of raw, unstretched audio before and after visible region
105 // to give the algorithm a chance to be in a steady state when reaching the
106 // play boundaries.
107 const auto tmpPlayStartTime =
108 std::max(interval.GetSequenceStartTime(), originalPlayStartTime - stretchRatio);
109 const auto tmpPlayEndTime =
110 std::min(interval.GetSequenceEndTime(), originalPlayEndTime + stretchRatio);
111 interval.TrimLeftTo(tmpPlayStartTime);
112 interval.TrimRightTo(tmpPlayEndTime);
113
114 constexpr auto sourceDurationToDiscard = 0.;
115 constexpr auto blockSize = 1024;
116 const auto numChannels = interval.NChannels();
117 ClipTimeAndPitchSource stretcherSource { interval, sourceDurationToDiscard,
120 params.timeRatio = stretchRatio;
121 params.pitchRatio = std::pow(2., interval.GetCentShift() / 1200.);
122 params.preserveFormants =
123 interval.GetPitchAndSpeedPreset() == PitchAndSpeedPreset::OptimizeForVoice;
124 StaffPadTimeAndPitch stretcher { interval.GetRate(), numChannels,
125 stretcherSource, std::move(params) };
126
127 // Post-rendering sample counts, i.e., stretched units
128 const auto totalNumOutSamples =
129 sampleCount { interval.GetVisibleSampleCount().as_double() *
130 stretchRatio };
131
132 sampleCount numOutSamples { 0 };
133 AudioContainer container(blockSize, numChannels);
134
135 while (numOutSamples < totalNumOutSamples)
136 {
137 const auto numSamplesToGet =
138 limitSampleBufferSize(blockSize, totalNumOutSamples - numOutSamples);
139 stretcher.GetSamples(container.Get(), numSamplesToGet);
140 constSamplePtr data[2];
141 data[0] = reinterpret_cast<constSamplePtr>(container.Get()[0]);
142 if (interval.NChannels() == 2)
143 data[1] = reinterpret_cast<constSamplePtr>(container.Get()[1]);
144 dst->Append(data, floatSample, numSamplesToGet, 1, widestSampleFormat);
145 numOutSamples += numSamplesToGet;
146 if (reportProgress)
147 reportProgress(
148 numOutSamples.as_double() / totalNumOutSamples.as_double());
149 }
150 dst->Flush();
151
152 // Now we're all like `this` except unstretched. We can clear leading and
153 // trailing, stretching transient parts.
154 dst->SetPlayStartTime(tmpPlayStartTime);
155 dst->ClearLeft(originalPlayStartTime);
156 dst->ClearRight(originalPlayEndTime);
157
158 // We don't preserve cutlines but the relevant part of the envelope.
159 auto dstEnvelope = std::make_unique<Envelope>(interval.GetEnvelope());
160 const auto samplePeriod = 1. / interval.GetRate();
161 dstEnvelope->CollapseRegion(
162 originalPlayEndTime, interval.GetSequenceEndTime() + samplePeriod, samplePeriod);
163 dstEnvelope->CollapseRegion(0, originalPlayStartTime, samplePeriod);
164 dstEnvelope->SetOffset(originalPlayStartTime);
165 dst->SetEnvelope(move(dstEnvelope));
166
167 success = true;
168
169 assert(!dst->HasPitchOrSpeed());
170 return dst;
171}
static RegisteredToolbarFactory factory
int min(int a, int b)
EffectDistortionSettings params
Definition: Distortion.cpp:77
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
const char * constSamplePtr
Definition: SampleFormat.h:58
constexpr sampleFormat widestSampleFormat
Definition: SampleFormat.h:47
WaveClip Interval
Definition: WaveTrack.h:208
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
Definition: MemoryX.h:174

References sampleCount::as_double(), factory, floatSample, anonymous_namespace{ExportPCM.cpp}::format, forward, AudioContainer::Get(), limitSampleBufferSize(), min(), OptimizeForVoice, params, and widestSampleFormat.

Here is the call graph for this function:

◆ ToLinkType()

Track::LinkType anonymous_namespace{WaveTrack.cpp}::ToLinkType ( int  value)

Definition at line 347 of file WaveTrack.cpp.

348{
349 if (value < 0)
351 else if (value > 3)
353 return static_cast<Track::LinkType>(value);
354}
LinkType
For two tracks describes the type of the linkage.
Definition: Channel.h:512
@ Group
compatibility with projects that were generated by older versions of Audacity

References ChannelGroup::Group, and ChannelGroup::None.

Referenced by WaveTrack::HandleXMLTag().

Here is the caller graph for this function:

Variable Documentation

◆ waveTrackDataFactory

const ChannelGroup::Attachments::RegisteredFactory anonymous_namespace{WaveTrack.cpp}::waveTrackDataFactory
static
Initial value:
{
[](auto &) { return std::make_unique<WaveTrackData>(); } }

Definition at line 249 of file WaveTrack.cpp.

Referenced by anonymous_namespace{WaveTrack.cpp}::WaveTrackData::Get().