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

#include <ClipTimeAndPitchSource.h>

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

Public Member Functions

 ClipTimeAndPitchSource (const ClipInterface &, double durationToDiscard, PlaybackDirection)
 
void Pull (float *const *, size_t samplesPerChannel) override
 
size_t NChannels () const
 
- Public Member Functions inherited from TimeAndPitchSource
virtual ~TimeAndPitchSource ()
 
virtual void Pull (float *const *, size_t samplesPerChannel)=0
 

Private Attributes

const ClipInterfacemClip
 
sampleCount mLastReadSample = 0
 
const PlaybackDirection mPlaybackDirection
 
ChannelSampleViews mChannelSampleViews
 

Detailed Description

Definition at line 23 of file ClipTimeAndPitchSource.h.

Constructor & Destructor Documentation

◆ ClipTimeAndPitchSource()

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

Definition at line 35 of file ClipTimeAndPitchSource.cpp.

38 : mClip { clip }
39 , mLastReadSample { GetLastReadSample(clip, durationToDiscard, direction) }
40 , mPlaybackDirection { direction }
41{
42}
const PlaybackDirection mPlaybackDirection
const ClipInterface & mClip
sampleCount GetLastReadSample(const ClipInterface &clip, double durationToDiscard, PlaybackDirection direction)

Member Function Documentation

◆ NChannels()

size_t ClipTimeAndPitchSource::NChannels ( ) const

Definition at line 90 of file ClipTimeAndPitchSource.cpp.

91{
92 return mClip.NChannels();
93}
virtual size_t NChannels() const =0

References mClip, and ClipInterface::NChannels().

Referenced by ClipSegment::NChannels().

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

◆ Pull()

void ClipTimeAndPitchSource::Pull ( float *const *  buffers,
size_t  samplesPerChannel 
)
overridevirtual

Implements TimeAndPitchSource.

Definition at line 44 of file ClipTimeAndPitchSource.cpp.

46{
48 const auto remainingSamplesInClip =
51 const auto numSamplesToRead =
52 limitSampleBufferSize(samplesPerChannel, remainingSamplesInClip);
53 if (numSamplesToRead > 0u)
54 {
55 constexpr auto mayThrow = false;
56 const auto start =
57 forward ? mLastReadSample : mLastReadSample - numSamplesToRead;
58 const auto nChannels = mClip.NChannels();
59 ChannelSampleViews newViews;
60 for (auto i = 0u; i < nChannels; ++i)
61 {
62 auto channelView = mClip.GetSampleView(i, start, numSamplesToRead);
63 // Query `samplesPerChannel` samples ; `AudioSegmentSampleView::Copy`
64 // will zero from `numSamplesToRead` to `samplesPerChannel` if needed.
65 channelView.Copy(buffers[i], samplesPerChannel);
66 newViews.push_back(std::move(channelView));
67 if (!forward)
69 reinterpret_cast<samplePtr>(buffers[i]), floatSample, 0,
70 numSamplesToRead);
71 }
72 mChannelSampleViews = std::move(newViews);
74 forward ?
75 sampleCount { numSamplesToRead } :
76 // Cast to `sampleCount` before negating ;
77 // on x86, size_t is 32 bits, but sampleCount will store it as 64
78 // bits. Result : -1 becomes 2^32-1 and adding it to mLastReadSample
79 // will not overflow, which is actually wanted in that case to
80 // become a reasonably small value again :)
81 -sampleCount { numSamplesToRead };
82 }
83 else
84 {
85 for (auto i = 0u; i < mClip.NChannels(); ++i)
86 std::fill(buffers[i], buffers[i] + samplesPerChannel, 0.f);
87 }
88}
std::vector< AudioSegmentSampleView > ChannelSampleViews
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
void ReverseSamples(samplePtr dst, sampleFormat format, int start, int len)
char * samplePtr
Definition: SampleFormat.h:57
void Copy(float *buffer, size_t bufferSize) const
Copies up to GetSampleCount() or bufferSize samples, whichever is less, into buffer....
virtual AudioSegmentSampleView GetSampleView(size_t iChannel, sampleCount start, size_t length, bool mayThrow=true) const =0
ChannelSampleViews mChannelSampleViews
virtual sampleCount GetVisibleSampleCount() const =0
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19

References AudioSegmentSampleView::Copy(), floatSample, forward, ClipInterface::GetSampleView(), ClipTimes::GetVisibleSampleCount(), limitSampleBufferSize(), mChannelSampleViews, mClip, mLastReadSample, mPlaybackDirection, ClipInterface::NChannels(), and ReverseSamples().

Here is the call graph for this function:

Member Data Documentation

◆ mChannelSampleViews

ChannelSampleViews ClipTimeAndPitchSource::mChannelSampleViews
private

Definition at line 39 of file ClipTimeAndPitchSource.h.

Referenced by Pull().

◆ mClip

const ClipInterface& ClipTimeAndPitchSource::mClip
private

Definition at line 36 of file ClipTimeAndPitchSource.h.

Referenced by NChannels(), and Pull().

◆ mLastReadSample

sampleCount ClipTimeAndPitchSource::mLastReadSample = 0
private

Definition at line 37 of file ClipTimeAndPitchSource.h.

Referenced by Pull().

◆ mPlaybackDirection

const PlaybackDirection ClipTimeAndPitchSource::mPlaybackDirection
private

Definition at line 38 of file ClipTimeAndPitchSource.h.

Referenced by Pull().


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