Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
StretchingSequence Class Referencefinal

#include <StretchingSequence.h>

Inheritance diagram for StretchingSequence:
[legend]
Collaboration diagram for StretchingSequence:
[legend]

Public Member Functions

 StretchingSequence (const PlayableSequence &, int sampleRate, size_t numChannels, std::unique_ptr< AudioSegmentFactoryInterface >)
 
size_t NChannels () const override
 A constant property. More...
 
float GetChannelGain (int channel) const override
 
double GetStartTime () const override
 
double GetEndTime () const override
 
double GetRate () const override
 
sampleFormat WidestEffectiveFormat () const override
 
bool HasTrivialEnvelope () const override
 
void GetEnvelopeValues (double *buffer, size_t bufferLen, double t0, bool backwards) const override
 
bool DoGet (size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backwards, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const override
 
const ChannelGroupFindChannelGroup () const override
 Find associated ChannelGroup if any. More...
 
bool GetSolo () const override
 May vary asynchronously. More...
 
bool GetMute () const override
 May vary asynchronously. More...
 
AudioGraph::ChannelType GetChannelType () const override
 Classify this channel. More...
 
bool GetFloats (float *buffers[], sampleCount start, size_t len, bool backwards) const
 
- Public Member Functions inherited from PlayableSequence
 ~PlayableSequence () override
 
virtual const ChannelGroupFindChannelGroup () const =0
 Find associated ChannelGroup if any. More...
 
virtual bool GetSolo () const =0
 May vary asynchronously. More...
 
virtual bool GetMute () const =0
 May vary asynchronously. More...
 
- Public Member Functions inherited from WideSampleSequence
virtual ~WideSampleSequence ()
 
virtual size_t NChannels () const =0
 A constant property. More...
 
virtual float GetChannelGain (int channel) const =0
 
bool GetFloats (size_t iChannel, size_t nBuffers, float *const buffers[], sampleCount start, size_t len, bool backwards=false, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
 
virtual bool DoGet (size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backward, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const =0
 
virtual double GetStartTime () const =0
 
virtual double GetEndTime () const =0
 
virtual double GetRate () const =0
 
sampleCount TimeToLongSamples (double t0) const
 
double LongSamplesToTime (sampleCount pos) const
 
double SnapToSample (double t) const
 
virtual sampleFormat WidestEffectiveFormat () const =0
 
virtual bool HasTrivialEnvelope () const =0
 
virtual void GetEnvelopeValues (double *buffer, size_t bufferLen, double t0, bool backwards) const =0
 
- Public Member Functions inherited from AudioGraph::Channel
virtual ~Channel ()
 
virtual ChannelType GetChannelType () const =0
 Classify this channel. More...
 

Static Public Member Functions

static std::shared_ptr< StretchingSequenceCreate (const PlayableSequence &, const ClipConstHolders &clips)
 

Private Types

using AudioSegments = std::vector< std::shared_ptr< AudioSegment > >
 

Private Member Functions

void ResetCursor (double t, PlaybackDirection)
 
bool GetNext (float *const buffers[], size_t numChannels, size_t numSamples)
 
bool MutableGet (size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backwards)
 

Private Attributes

const PlayableSequencemSequence
 
const std::unique_ptr< AudioSegmentFactoryInterfacemAudioSegmentFactory
 
AudioSegments mAudioSegments
 
AudioSegments::const_iterator mActiveAudioSegmentIt = mAudioSegments.end()
 
std::optional< sampleCountmExpectedStart
 
PlaybackDirection mPlaybackDirection = PlaybackDirection::forward
 

Detailed Description

Definition at line 27 of file StretchingSequence.h.

Member Typedef Documentation

◆ AudioSegments

using StretchingSequence::AudioSegments = std::vector<std::shared_ptr<AudioSegment> >
private

Definition at line 67 of file StretchingSequence.h.

Constructor & Destructor Documentation

◆ StretchingSequence()

StretchingSequence::StretchingSequence ( const PlayableSequence sequence,
int  sampleRate,
size_t  numChannels,
std::unique_ptr< AudioSegmentFactoryInterface factory 
)

Definition at line 29 of file StretchingSequence.cpp.

32 : mSequence { sequence }
33 , mAudioSegmentFactory { std::move(factory) }
34{
35}
static RegisteredToolbarFactory factory
const PlayableSequence & mSequence
const std::unique_ptr< AudioSegmentFactoryInterface > mAudioSegmentFactory

Member Function Documentation

◆ Create()

std::shared_ptr< StretchingSequence > StretchingSequence::Create ( const PlayableSequence sequence,
const ClipConstHolders clips 
)
static

Definition at line 189 of file StretchingSequence.cpp.

191{
192 const int sampleRate = sequence.GetRate();
193 return std::make_shared<StretchingSequence>(
194 sequence, sampleRate, sequence.NChannels(),
195 std::make_unique<AudioSegmentFactory>(
196 sampleRate, sequence.NChannels(), clips));
197}
virtual size_t NChannels() const =0
A constant property.
virtual double GetRate() const =0

References WideSampleSequence::GetRate(), WideSampleSequence::NChannels(), and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by ExportPluginHelpers::CreateMixer(), MakeTransportTracks(), MixAndRender(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoGet()

bool StretchingSequence::DoGet ( size_t  iChannel,
size_t  nBuffers,
const samplePtr  buffers[],
sampleFormat  format,
sampleCount  start,
size_t  len,
bool  backward,
fillFormat  fill = FillFormat::fillZero,
bool  mayThrow = true,
sampleCount pNumWithinClips = nullptr 
) const
overridevirtual

Retrieve samples of one of the channels from a sequence in a specified format

Parameters
formatsample format of the destination buffer
backwardretrieves samples from start (inclusive) to start + len if false, else from start (exclusive) to start - len in reverse order.
Returns
whether successful; if not, assume nothing about buffer contents

Implements WideSampleSequence.

Definition at line 97 of file StretchingSequence.cpp.

101{
102 return const_cast<StretchingSequence&>(*this).MutableGet(
103 iChannel, nBuffers, buffers, format, start, len, backwards);
104}
bool MutableGet(size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backwards)

References anonymous_namespace{ExportPCM.cpp}::format, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, and MutableGet().

Referenced by GetFloats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindChannelGroup()

const ChannelGroup * StretchingSequence::FindChannelGroup ( ) const
overridevirtual

Find associated ChannelGroup if any.

Implements PlayableSequence.

Definition at line 106 of file StretchingSequence.cpp.

107{
109}
virtual const ChannelGroup * FindChannelGroup() const =0
Find associated ChannelGroup if any.

References PlayableSequence::FindChannelGroup(), and mSequence.

Here is the call graph for this function:

◆ GetChannelGain()

float StretchingSequence::GetChannelGain ( int  channel) const
overridevirtual

Extra gain factor to apply to a channel when mixing, may change asynchronously

Implements WideSampleSequence.

Definition at line 92 of file StretchingSequence.cpp.

93{
94 return mSequence.GetChannelGain(channel);
95}
virtual float GetChannelGain(int channel) const =0

References WideSampleSequence::GetChannelGain(), and mSequence.

Here is the call graph for this function:

◆ GetChannelType()

AudioGraph::ChannelType StretchingSequence::GetChannelType ( ) const
overridevirtual

Classify this channel.

Implements AudioGraph::Channel.

Definition at line 152 of file StretchingSequence.cpp.

153{
154 return mSequence.GetChannelType();
155}
virtual ChannelType GetChannelType() const =0
Classify this channel.

References AudioGraph::Channel::GetChannelType(), and mSequence.

Here is the call graph for this function:

◆ GetEndTime()

double StretchingSequence::GetEndTime ( ) const
overridevirtual

Implements WideSampleSequence.

Definition at line 126 of file StretchingSequence.cpp.

127{
128 return mSequence.GetEndTime();
129}
virtual double GetEndTime() const =0

References WideSampleSequence::GetEndTime(), and mSequence.

Here is the call graph for this function:

◆ GetEnvelopeValues()

void StretchingSequence::GetEnvelopeValues ( double *  buffer,
size_t  bufferLen,
double  t0,
bool  backwards 
) const
overridevirtual

Fetch envelope values corresponding to uniformly separated sample times starting at the given time

Parameters
backwardsif true, fetch values in reverse order, from t0 to t0 - bufferLen / rate

Implements WideSampleSequence.

Definition at line 146 of file StretchingSequence.cpp.

148{
149 mSequence.GetEnvelopeValues(buffer, bufferLen, t0, backwards);
150}
virtual void GetEnvelopeValues(double *buffer, size_t bufferLen, double t0, bool backwards) const =0

References WideSampleSequence::GetEnvelopeValues(), and mSequence.

Here is the call graph for this function:

◆ GetFloats()

bool StretchingSequence::GetFloats ( float *  buffers[],
sampleCount  start,
size_t  len,
bool  backwards 
) const

Definition at line 157 of file StretchingSequence.cpp.

159{
160 std::vector<samplePtr> charBuffers;
161 const auto nChannels = NChannels();
162 charBuffers.reserve(nChannels);
163 for (auto i = 0u; i < nChannels; ++i)
164 charBuffers.push_back(reinterpret_cast<samplePtr>(buffers[i]));
165 constexpr auto iChannel = 0u;
166 return DoGet(
167 iChannel, nChannels, charBuffers.data(), sampleFormat::floatSample, start,
168 len, backwards);
169}
char * samplePtr
Definition: SampleFormat.h:57
size_t NChannels() const override
A constant property.
bool DoGet(size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backwards, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const override

References DoGet(), floatSample, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, and NChannels().

Here is the call graph for this function:

◆ GetMute()

bool StretchingSequence::GetMute ( ) const
overridevirtual

May vary asynchronously.

Implements PlayableSequence.

Definition at line 116 of file StretchingSequence.cpp.

117{
118 return mSequence.GetMute();
119}
virtual bool GetMute() const =0
May vary asynchronously.

References PlayableSequence::GetMute(), and mSequence.

Here is the call graph for this function:

◆ GetNext()

bool StretchingSequence::GetNext ( float *const  buffers[],
size_t  numChannels,
size_t  numSamples 
)
private

Definition at line 46 of file StretchingSequence.cpp.

48{
49 if (!mExpectedStart.has_value())
51 auto numProcessedSamples = 0u;
52 while (numProcessedSamples < numSamples &&
54 {
55 const auto& segment = *mActiveAudioSegmentIt;
56 // More-than-stereo isn't supported
57 assert(mSequence.NChannels() <= 2);
58 float* offsetBuffers[2] {};
60 offsetBuffers, buffers, mSequence.NChannels(), numProcessedSamples);
61 numProcessedSamples += segment->GetFloats(
62 offsetBuffers,
63 numSamples - numProcessedSamples); // No need to reverse, we feed the
64 // time-stretching algorithm with
65 // reversed samples already.
66 if (segment->Empty())
68 }
69 const auto remaining = numSamples - numProcessedSamples;
70 if (remaining > 0u)
71 {
72 // More-than-stereo isn't supported
73 assert(mSequence.NChannels() <= 2);
74 float* offsetBuffers[2] {};
76 offsetBuffers, buffers, mSequence.NChannels(), numProcessedSamples);
77 for (auto i = 0u; i < mSequence.NChannels(); ++i)
78 std::fill(offsetBuffers[i], offsetBuffers[i] + remaining, 0.f);
79 }
82 *mExpectedStart + numSamples :
83 *mExpectedStart - static_cast<sampleCount::type>(numSamples);
84 return true;
85}
AudioSegments mAudioSegments
PlaybackDirection mPlaybackDirection
std::optional< sampleCount > mExpectedStart
AudioSegments::const_iterator mActiveAudioSegmentIt
void ResetCursor(double t, PlaybackDirection)
long long type
Definition: SampleCount.h:21
void GetOffsetBuffer(float **offsetBuffer, float *const *buffer, size_t numChannels, size_t offset)

References forward, anonymous_namespace{StretchingSequence.cpp}::GetOffsetBuffer(), mActiveAudioSegmentIt, mAudioSegments, mExpectedStart, mPlaybackDirection, mSequence, WideSampleSequence::NChannels(), and ResetCursor().

Referenced by MutableGet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRate()

double StretchingSequence::GetRate ( ) const
overridevirtual

Implements WideSampleSequence.

Definition at line 131 of file StretchingSequence.cpp.

132{
133 return mSequence.GetRate();
134}

References WideSampleSequence::GetRate(), and mSequence.

Here is the call graph for this function:

◆ GetSolo()

bool StretchingSequence::GetSolo ( ) const
overridevirtual

May vary asynchronously.

Implements PlayableSequence.

Definition at line 111 of file StretchingSequence.cpp.

112{
113 return mSequence.GetSolo();
114}
virtual bool GetSolo() const =0
May vary asynchronously.

References PlayableSequence::GetSolo(), and mSequence.

Here is the call graph for this function:

◆ GetStartTime()

double StretchingSequence::GetStartTime ( ) const
overridevirtual

Implements WideSampleSequence.

Definition at line 121 of file StretchingSequence.cpp.

122{
123 return mSequence.GetStartTime();
124}
virtual double GetStartTime() const =0

References WideSampleSequence::GetStartTime(), and mSequence.

Here is the call graph for this function:

◆ HasTrivialEnvelope()

bool StretchingSequence::HasTrivialEnvelope ( ) const
overridevirtual
Returns
whether envelope values are all unit

Implements WideSampleSequence.

Definition at line 141 of file StretchingSequence.cpp.

142{
144}
virtual bool HasTrivialEnvelope() const =0

References WideSampleSequence::HasTrivialEnvelope(), and mSequence.

Here is the call graph for this function:

◆ MutableGet()

bool StretchingSequence::MutableGet ( size_t  iChannel,
size_t  nBuffers,
const samplePtr  buffers[],
sampleFormat  format,
sampleCount  start,
size_t  len,
bool  backwards 
)
private

Definition at line 171 of file StretchingSequence.cpp.

174{
175 // StretchingSequence is not expected to be used for any other case.
176 assert(iChannel == 0u);
177 if (
178 !mExpectedStart.has_value() || *mExpectedStart != start ||
180 {
181 const auto t = start.as_double() / mSequence.GetRate();
183 t,
185 }
186 return GetNext(reinterpret_cast<float* const*>(buffers), nBuffers, len);
187}
bool GetNext(float *const buffers[], size_t numChannels, size_t numSamples)
double as_double() const
Definition: SampleCount.h:46

References sampleCount::as_double(), backward, forward, GetNext(), WideSampleSequence::GetRate(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, mExpectedStart, mPlaybackDirection, mSequence, and ResetCursor().

Referenced by DoGet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NChannels()

size_t StretchingSequence::NChannels ( ) const
overridevirtual

A constant property.

Postcondition
result: result > 0

Implements WideSampleSequence.

Definition at line 87 of file StretchingSequence.cpp.

88{
89 return mSequence.NChannels();
90}

References mSequence, and WideSampleSequence::NChannels().

Referenced by GetFloats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetCursor()

void StretchingSequence::ResetCursor ( double  t,
PlaybackDirection  direction 
)
private

Definition at line 37 of file StretchingSequence.cpp.

38{
40 mAudioSegmentFactory->CreateAudioSegmentSequence(t, direction);
42 mPlaybackDirection = direction;
44}
sampleCount TimeToLongSamples(double t0) const

References mActiveAudioSegmentIt, mAudioSegmentFactory, mAudioSegments, mExpectedStart, mPlaybackDirection, and WideSampleSequence::TimeToLongSamples().

Referenced by GetNext(), and MutableGet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WidestEffectiveFormat()

sampleFormat StretchingSequence::WidestEffectiveFormat ( ) const
overridevirtual
Returns
widest effective SampleFormat in any part of the track

Implements WideSampleSequence.

Definition at line 136 of file StretchingSequence.cpp.

137{
139}
virtual sampleFormat WidestEffectiveFormat() const =0

References mSequence, and WideSampleSequence::WidestEffectiveFormat().

Here is the call graph for this function:

Member Data Documentation

◆ mActiveAudioSegmentIt

AudioSegments::const_iterator StretchingSequence::mActiveAudioSegmentIt = mAudioSegments.end()
private

Definition at line 78 of file StretchingSequence.h.

Referenced by GetNext(), and ResetCursor().

◆ mAudioSegmentFactory

const std::unique_ptr<AudioSegmentFactoryInterface> StretchingSequence::mAudioSegmentFactory
private

Definition at line 76 of file StretchingSequence.h.

Referenced by ResetCursor().

◆ mAudioSegments

AudioSegments StretchingSequence::mAudioSegments
private

Definition at line 77 of file StretchingSequence.h.

Referenced by GetNext(), and ResetCursor().

◆ mExpectedStart

std::optional<sampleCount> StretchingSequence::mExpectedStart
private

Definition at line 79 of file StretchingSequence.h.

Referenced by GetNext(), MutableGet(), and ResetCursor().

◆ mPlaybackDirection

PlaybackDirection StretchingSequence::mPlaybackDirection = PlaybackDirection::forward
private

Definition at line 80 of file StretchingSequence.h.

Referenced by GetNext(), MutableGet(), and ResetCursor().

◆ mSequence

const PlayableSequence& StretchingSequence::mSequence
private

The documentation for this class was generated from the following files: