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

#include <AudioSegmentFactory.h>

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

Public Member Functions

 AudioSegmentFactory (int sampleRate, int numChannels, ClipConstHolders clips)
 
std::vector< std::shared_ptr< AudioSegment > > CreateAudioSegmentSequence (double playbackStartTime, PlaybackDirection) override
 
- Public Member Functions inherited from AudioSegmentFactoryInterface
virtual ~AudioSegmentFactoryInterface ()
 
virtual std::vector< std::shared_ptr< AudioSegment > > CreateAudioSegmentSequence (double playbackStartTime, PlaybackDirection)=0
 

Private Member Functions

std::vector< std::shared_ptr< AudioSegment > > CreateAudioSegmentSequenceForward (double playbackStartTime)
 
std::vector< std::shared_ptr< AudioSegment > > CreateAudioSegmentSequenceBackward (double playbackStartTime)
 

Private Attributes

const ClipConstHolders mClips
 
const int mSampleRate
 
const int mNumChannels
 

Detailed Description

Definition at line 23 of file AudioSegmentFactory.h.

Constructor & Destructor Documentation

◆ AudioSegmentFactory()

AudioSegmentFactory::AudioSegmentFactory ( int  sampleRate,
int  numChannels,
ClipConstHolders  clips 
)

Definition at line 22 of file AudioSegmentFactory.cpp.

24 : mClips { std::move(clips) }
26 , mNumChannels { numChannels }
27{
28}
const ClipConstHolders mClips

Member Function Documentation

◆ CreateAudioSegmentSequence()

std::vector< std::shared_ptr< AudioSegment > > AudioSegmentFactory::CreateAudioSegmentSequence ( double  playbackStartTime,
PlaybackDirection  direction 
)
overridevirtual

Implements AudioSegmentFactoryInterface.

Definition at line 31 of file AudioSegmentFactory.cpp.

33{
34 return direction == PlaybackDirection::forward ?
35 CreateAudioSegmentSequenceForward(playbackStartTime) :
36 CreateAudioSegmentSequenceBackward(playbackStartTime);
37}
std::vector< std::shared_ptr< AudioSegment > > CreateAudioSegmentSequenceBackward(double playbackStartTime)
std::vector< std::shared_ptr< AudioSegment > > CreateAudioSegmentSequenceForward(double playbackStartTime)

References CreateAudioSegmentSequenceBackward(), CreateAudioSegmentSequenceForward(), and forward.

Here is the call graph for this function:

◆ CreateAudioSegmentSequenceBackward()

std::vector< std::shared_ptr< AudioSegment > > AudioSegmentFactory::CreateAudioSegmentSequenceBackward ( double  playbackStartTime)
private

Definition at line 70 of file AudioSegmentFactory.cpp.

71{
72 auto sortedClips = mClips;
73 std::sort(
74 sortedClips.begin(), sortedClips.end(),
75 [&](
76 const std::shared_ptr<const ClipInterface>& a,
77 const std::shared_ptr<const ClipInterface>& b) {
78 return a->GetPlayEndTime() > b->GetPlayEndTime();
79 });
80 std::vector<std::shared_ptr<AudioSegment>> segments;
81 for (const auto& clip : sortedClips)
82 {
83 if (clip->GetPlayEndTime() < t0)
84 {
85 const auto numSamples =
86 sampleCount { (t0 - clip->GetPlayEndTime()) * mSampleRate + .5 };
87 segments.push_back(
88 std::make_shared<SilenceSegment>(mNumChannels, numSamples));
89 t0 = clip->GetPlayEndTime();
90 }
91 else if (clip->GetPlayStartTime() >= t0)
92 continue;
93 segments.push_back(std::make_shared<ClipSegment>(
94 *clip, clip->GetPlayEndTime() - t0, PlaybackDirection::backward));
95 t0 = clip->GetPlayStartTime();
96 }
97 return segments;
98}
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19

References backward, mClips, mNumChannels, and mSampleRate.

Referenced by CreateAudioSegmentSequence().

Here is the caller graph for this function:

◆ CreateAudioSegmentSequenceForward()

std::vector< std::shared_ptr< AudioSegment > > AudioSegmentFactory::CreateAudioSegmentSequenceForward ( double  playbackStartTime)
private

Definition at line 40 of file AudioSegmentFactory.cpp.

41{
42 auto sortedClips = mClips;
43 std::sort(
44 sortedClips.begin(), sortedClips.end(),
45 [](const std::shared_ptr<const ClipInterface>& a,
46 const std::shared_ptr<const ClipInterface>& b) {
47 return a->GetPlayStartTime() < b->GetPlayStartTime();
48 });
49 std::vector<std::shared_ptr<AudioSegment>> segments;
50 for (const auto& clip : sortedClips)
51 {
52 if (clip->GetPlayStartTime() > t0)
53 {
54 const auto numSamples =
55 sampleCount { (clip->GetPlayStartTime() - t0) * mSampleRate + .5 };
56 segments.push_back(
57 std::make_shared<SilenceSegment>(mNumChannels, numSamples));
58 t0 = clip->GetPlayStartTime();
59 }
60 else if (clip->GetPlayEndTime() <= t0)
61 continue;
62 segments.push_back(std::make_shared<ClipSegment>(
63 *clip, t0 - clip->GetPlayStartTime(), PlaybackDirection::forward));
64 t0 = clip->GetPlayEndTime();
65 }
66 return segments;
67}

References forward, mClips, mNumChannels, and mSampleRate.

Referenced by CreateAudioSegmentSequence().

Here is the caller graph for this function:

Member Data Documentation

◆ mClips

const ClipConstHolders AudioSegmentFactory::mClips
private

◆ mNumChannels

const int AudioSegmentFactory::mNumChannels
private

◆ mSampleRate

const int AudioSegmentFactory::mSampleRate
private

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