Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
ClipSegment Class Referencefinal

#include <ClipSegment.h>

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

Public Member Functions

 ClipSegment (const ClipInterface &, double durationToDiscard, PlaybackDirection)
 
 ~ClipSegment () override
 
size_t GetFloats (float *const *buffers, size_t numSamples) override
 Fills buffers with as many as numSamples or the number of remaining samples, whichever is smaller. More...
 
bool Empty () const override
 Whether the segment has no more samples to provide. More...
 
size_t NChannels () const override
 The number of channels in the segment. More...
 
- Public Member Functions inherited from AudioSegment
virtual ~AudioSegment ()
 
virtual size_t GetFloats (float *const *buffers, size_t numSamples)=0
 Fills buffers with as many as numSamples or the number of remaining samples, whichever is smaller. More...
 
virtual size_t NChannels () const =0
 The number of channels in the segment. More...
 
virtual bool Empty () const =0
 Whether the segment has no more samples to provide. More...
 

Private Attributes

const sampleCount mTotalNumSamplesToProduce
 
sampleCount mTotalNumSamplesProduced = 0
 
ClipTimeAndPitchSource mSource
 
bool mPreserveFormants
 
int mCentShift
 
std::atomic< bool > mUpdateFormantPreservation = false
 
std::atomic< bool > mUpdateCentShift = false
 
std::unique_ptr< TimeAndPitchInterfacemStretcher
 
Observer::Subscription mOnSemitoneShiftChangeSubscription
 
Observer::Subscription mOnFormantPreservationChangeSubscription
 

Detailed Description

It is important that objects of this class are instantiated and destroyed on the same thread, due to the owned Observer::Subscription.

Definition at line 30 of file ClipSegment.h.

Constructor & Destructor Documentation

◆ ClipSegment()

ClipSegment::ClipSegment ( const ClipInterface clip,
double  durationToDiscard,
PlaybackDirection  direction 
)

Definition at line 41 of file ClipSegment.cpp.

45 clip, durationToDiscard) }
46 , mSource { clip, durationToDiscard, direction }
49 , mCentShift { clip.GetCentShift() }
50 , mStretcher { std::make_unique<StaffPadTimeAndPitch>(
51 clip.GetRate(), clip.NChannels(), mSource,
54 [this](int cents) {
55 mCentShift = cents;
56 mUpdateCentShift = true;
57 }) }
64 })
65 }
66{
67}
PitchAndSpeedPreset
Definition: ClipInterface.h:40
ReverbSettings preset
Definition: ReverbBase.cpp:25
virtual int GetCentShift() const =0
virtual PitchAndSpeedPreset GetPitchAndSpeedPreset() const =0
virtual size_t NChannels() const =0
virtual Observer::Subscription SubscribeToPitchAndSpeedPresetChange(std::function< void(PitchAndSpeedPreset)> cb) const =0
virtual Observer::Subscription SubscribeToCentShiftChange(std::function< void(int)> cb) const =0
int mCentShift
Definition: ClipSegment.h:47
Observer::Subscription mOnSemitoneShiftChangeSubscription
Definition: ClipSegment.h:54
ClipTimeAndPitchSource mSource
Definition: ClipSegment.h:45
std::unique_ptr< TimeAndPitchInterface > mStretcher
Definition: ClipSegment.h:53
Observer::Subscription mOnFormantPreservationChangeSubscription
Definition: ClipSegment.h:55
bool mPreserveFormants
Definition: ClipSegment.h:46
std::atomic< bool > mUpdateCentShift
Definition: ClipSegment.h:49
std::atomic< bool > mUpdateFormantPreservation
Definition: ClipSegment.h:48
const sampleCount mTotalNumSamplesToProduce
Definition: ClipSegment.h:43
virtual int GetRate() const =0
TimeAndPitchInterface::Parameters GetStretchingParameters(const ClipInterface &clip)
Definition: ClipSegment.cpp:22
sampleCount GetTotalNumSamplesToProduce(const ClipInterface &clip, double durationToDiscard)
Definition: ClipSegment.cpp:33

References mCentShift, mUpdateCentShift, and OptimizeForVoice.

◆ ~ClipSegment()

ClipSegment::~ClipSegment ( )
override

Definition at line 69 of file ClipSegment.cpp.

70{
73}
void Reset() noexcept
Breaks the connection (constant time)
Definition: Observer.cpp:101

References mOnFormantPreservationChangeSubscription, mOnSemitoneShiftChangeSubscription, and Observer::Subscription::Reset().

Here is the call graph for this function:

Member Function Documentation

◆ Empty()

bool ClipSegment::Empty ( ) const
overridevirtual

Whether the segment has no more samples to provide.

Implements AudioSegment.

Definition at line 95 of file ClipSegment.cpp.

96{
98}
sampleCount mTotalNumSamplesProduced
Definition: ClipSegment.h:44

References mTotalNumSamplesProduced, and mTotalNumSamplesToProduce.

◆ GetFloats()

size_t ClipSegment::GetFloats ( float *const *  buffers,
size_t  numSamples 
)
overridevirtual

Fills buffers with as many as numSamples or the number of remaining samples, whichever is smaller.

Parameters
buffersPointers to buffers, one for each channel.
numSamplesThe max. number of samples to write to each buffer.
Returns
The number of samples actually provided in each buffer.

Implements AudioSegment.

Definition at line 75 of file ClipSegment.cpp.

76{
77 // Check if formant preservation of pitch shift needs to be updated.
78 // This approach is not immune to a race condition, but it is unlikely and
79 // not critical, as it would only affect one playback pass, during which the
80 // user could easily correct the mistake if needed. On the other hand, we
81 // cannot trust that the observer subscriptions do not get called after
82 // destruction of this object, so better not do anything too sophisticated
83 // there.
84 if (mUpdateFormantPreservation.exchange(false))
85 mStretcher->OnFormantPreservationChange(mPreserveFormants);
86 if (mUpdateCentShift.exchange(false))
87 mStretcher->OnCentShiftChange(mCentShift);
88 const auto numSamplesToProduce = limitSampleBufferSize(
90 mStretcher->GetSamples(buffers, numSamplesToProduce);
91 mTotalNumSamplesProduced += numSamplesToProduce;
92 return numSamplesToProduce;
93}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22

References limitSampleBufferSize(), mCentShift, mPreserveFormants, mStretcher, mTotalNumSamplesProduced, mTotalNumSamplesToProduce, mUpdateCentShift, and mUpdateFormantPreservation.

Here is the call graph for this function:

◆ NChannels()

size_t ClipSegment::NChannels ( ) const
overridevirtual

The number of channels in the segment.

Implements AudioSegment.

Definition at line 100 of file ClipSegment.cpp.

101{
102 return mSource.NChannels();
103}

References mSource, and ClipTimeAndPitchSource::NChannels().

Here is the call graph for this function:

Member Data Documentation

◆ mCentShift

int ClipSegment::mCentShift
private

Definition at line 47 of file ClipSegment.h.

Referenced by ClipSegment(), and GetFloats().

◆ mOnFormantPreservationChangeSubscription

Observer::Subscription ClipSegment::mOnFormantPreservationChangeSubscription
private

Definition at line 55 of file ClipSegment.h.

Referenced by ~ClipSegment().

◆ mOnSemitoneShiftChangeSubscription

Observer::Subscription ClipSegment::mOnSemitoneShiftChangeSubscription
private

Definition at line 54 of file ClipSegment.h.

Referenced by ~ClipSegment().

◆ mPreserveFormants

bool ClipSegment::mPreserveFormants
private

Definition at line 46 of file ClipSegment.h.

Referenced by GetFloats().

◆ mSource

ClipTimeAndPitchSource ClipSegment::mSource
private

Definition at line 45 of file ClipSegment.h.

Referenced by NChannels().

◆ mStretcher

std::unique_ptr<TimeAndPitchInterface> ClipSegment::mStretcher
private

Definition at line 53 of file ClipSegment.h.

Referenced by GetFloats().

◆ mTotalNumSamplesProduced

sampleCount ClipSegment::mTotalNumSamplesProduced = 0
private

Definition at line 44 of file ClipSegment.h.

Referenced by Empty(), and GetFloats().

◆ mTotalNumSamplesToProduce

const sampleCount ClipSegment::mTotalNumSamplesToProduce
private

Definition at line 43 of file ClipSegment.h.

Referenced by Empty(), and GetFloats().

◆ mUpdateCentShift

std::atomic<bool> ClipSegment::mUpdateCentShift = false
private

Definition at line 49 of file ClipSegment.h.

Referenced by ClipSegment(), and GetFloats().

◆ mUpdateFormantPreservation

std::atomic<bool> ClipSegment::mUpdateFormantPreservation = false
private

Definition at line 48 of file ClipSegment.h.

Referenced by GetFloats().


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