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 3227 of file WaveTrack.cpp.

3228{
3229 // This is used only in assertions
3230 using Set = std::unordered_set<WaveClipHolder>;
3231 return clips.size() == Set{ clips.begin(), clips.end() }.size();
3232}

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 76 of file WaveTrack.cpp.

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

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 345 of file WaveTrack.cpp.

346{
347 if (value < 0)
349 else if (value > 3)
351 return static_cast<Track::LinkType>(value);
352}
LinkType
For two tracks describes the type of the linkage.
Definition: Channel.h:515
@ 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 247 of file WaveTrack.cpp.

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