Audacity 3.2.0
Classes | Typedefs | Functions
anonymous_namespace{WaveChannelUtilities.cpp} Namespace Reference

Classes

struct  SampleAccessArgs
 

Typedefs

template<typename FloatType >
using BufferCharType = std::conditional_t< std::is_const_v< std::remove_pointer_t< FloatType > >, constSamplePtr, samplePtr >
 

Functions

void RoundToNearestClipSample (const WaveChannel &channel, double &t)
 
template<typename BufferType >
SampleAccessArgs< BufferType > GetSampleAccessArgs (const Clip &clip, double startOrEndTime, BufferType buffer, size_t totalToRead, size_t alreadyRead, bool forward)
 
template<typename ClipPointer >
auto DoGetNextClip (const std::vector< ClipPointer > &clips, const Clip &clip, PlaybackDirection direction) -> ClipPointer
 
template<typename ClipPointer >
auto DoGetAdjacentClip (const std::vector< ClipPointer > &clips, const Clip &clip, PlaybackDirection direction) -> ClipPointer
 

Typedef Documentation

◆ BufferCharType

template<typename FloatType >
using anonymous_namespace{WaveChannelUtilities.cpp}::BufferCharType = typedef std::conditional_t< std::is_const_v<std::remove_pointer_t<FloatType> >, constSamplePtr, samplePtr>

Definition at line 125 of file WaveChannelUtilities.cpp.

Function Documentation

◆ DoGetAdjacentClip()

template<typename ClipPointer >
auto anonymous_namespace{WaveChannelUtilities.cpp}::DoGetAdjacentClip ( const std::vector< ClipPointer > &  clips,
const Clip clip,
PlaybackDirection  direction 
) -> ClipPointer

Definition at line 329 of file WaveChannelUtilities.cpp.

331{
332 const auto neighbour = GetNextClip(clips, clip, direction);
333 if (!neighbour)
334 return nullptr;
335 else if (direction == PlaybackDirection::forward)
336 return std::abs(clip.GetPlayEndTime() - neighbour->GetPlayStartTime()) <
337 1e-9 ?
338 neighbour :
339 nullptr;
340 else
341 return std::abs(clip.GetPlayStartTime() - neighbour->GetPlayEndTime()) <
342 1e-9 ?
343 neighbour :
344 nullptr;
345}
double GetPlayEndTime() const override
Definition: WaveClip.cpp:203
double GetPlayStartTime() const override
Definition: WaveClip.cpp:198
WAVE_TRACK_API ClipConstPointer GetNextClip(const ClipConstPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
Returns clips next to clip in the given direction, or nullptr if there is none.

References forward, and WaveChannelUtilities::GetNextClip().

Referenced by WaveChannelUtilities::GetAdjacentClip().

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

◆ DoGetNextClip()

template<typename ClipPointer >
auto anonymous_namespace{WaveChannelUtilities.cpp}::DoGetNextClip ( const std::vector< ClipPointer > &  clips,
const Clip clip,
PlaybackDirection  direction 
) -> ClipPointer
Precondition
IsSortedByPlayStartTime(clips)

Definition at line 310 of file WaveChannelUtilities.cpp.

312{
313 assert(IsSortedByPlayStartTime(clips));
314 // Find first place greater than or equal to given clip
315 const auto p = lower_bound(clips.begin(), clips.end(), clip,
316 [](const ClipPointer &pClip, const Clip &clip){
317 return CompareClipsByPlayStartTime(*pClip, clip); });
318 // Fail if given clip is strictly less than that
319 if (p == clips.end() || !*p ||
321 return nullptr;
322 else if (direction == PlaybackDirection::forward)
323 return p == clips.end() - 1 ? nullptr : *(p + 1);
324 else
325 return p == clips.begin() ? nullptr : *(p - 1);
326}
bool IsSortedByPlayStartTime(const ClipPointers &clips)
WAVE_TRACK_API bool CompareClipsByPlayStartTime(const Clip &x, const Clip &y)
std::shared_ptr< Clip > ClipPointer

References WaveChannelUtilities::CompareClipsByPlayStartTime(), forward, and WaveChannelUtilities::IsSortedByPlayStartTime().

Referenced by WaveChannelUtilities::GetNextClip().

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

◆ GetSampleAccessArgs()

template<typename BufferType >
SampleAccessArgs< BufferType > anonymous_namespace{WaveChannelUtilities.cpp}::GetSampleAccessArgs ( const Clip clip,
double  startOrEndTime,
BufferType  buffer,
size_t  totalToRead,
size_t  alreadyRead,
bool  forward 
)

Definition at line 137 of file WaveChannelUtilities.cpp.

141{
142 assert(totalToRead >= alreadyRead);
143 const auto remainingToRead = totalToRead - alreadyRead;
144 const auto sampsInClip = clip.GetVisibleSampleCount();
145 const auto sampsPerSec = clip.GetRate() / clip.GetStretchRatio();
146 if (forward)
147 {
148 const auto startTime =
149 std::max(startOrEndTime - clip.GetPlayStartTime(), 0.);
150 const sampleCount startSamp { std::round(startTime * sampsPerSec) };
151 if (startSamp >= sampsInClip)
152 return { nullptr, sampleCount { 0u }, 0u };
153 const auto len =
154 limitSampleBufferSize(remainingToRead, sampsInClip - startSamp);
155 return { reinterpret_cast<BufferCharType<BufferType>>(
156 buffer + alreadyRead),
157 startSamp, len };
158 }
159 else
160 {
161 const auto endTime = std::min(
162 startOrEndTime - clip.GetPlayStartTime(), clip.GetPlayDuration());
163 const sampleCount endSamp { std::round(endTime * sampsPerSec) };
164 const auto startSamp =
165 std::max(endSamp - remainingToRead, sampleCount { 0 });
166 // `len` cannot be greater than `remainingToRead`, itself a `size_t` ->
167 // safe cast.
168 const auto len = (endSamp - startSamp).as_size_t();
169 if (len == 0 || startSamp >= sampsInClip)
170 return { nullptr, sampleCount { 0u }, 0u };
171 const auto bufferEnd = buffer + remainingToRead;
172 return { reinterpret_cast<BufferCharType<BufferType>>(bufferEnd - len),
173 startSamp, len };
174 }
175}
int min(int a, int b)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
sampleCount GetVisibleSampleCount() const override
Definition: WaveClip.cpp:188
int GetRate() const override
Definition: WaveClip.cpp:193
double GetStretchRatio() const override
Definition: WaveClip.cpp:218
double GetPlayDuration() const
Definition: WaveClip.cpp:208
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References forward, WaveClipChannel::GetPlayDuration(), WaveClipChannel::GetPlayStartTime(), WaveClipChannel::GetRate(), WaveClipChannel::GetStretchRatio(), WaveClipChannel::GetVisibleSampleCount(), limitSampleBufferSize(), min(), and fast_float::round().

Referenced by WaveChannelUtilities::GetFloatsFromTime(), and WaveChannelUtilities::SetFloatsFromTime().

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

◆ RoundToNearestClipSample()

void anonymous_namespace{WaveChannelUtilities.cpp}::RoundToNearestClipSample ( const WaveChannel channel,
double &  t 
)

Definition at line 98 of file WaveChannelUtilities.cpp.

99{
100 const auto clip = GetClipAtTime(channel, t);
101 if (!clip)
102 return;
103 t = clip->SamplesToTime(clip->TimeToSamples(t - clip->GetPlayStartTime())) +
104 clip->GetPlayStartTime();
105}
WAVE_TRACK_API ClipPointer GetClipAtTime(WaveChannel &channel, double time)

References WaveChannelUtilities::GetClipAtTime().

Referenced by WaveChannelUtilities::GetFloatsFromTime(), and WaveChannelUtilities::SetFloatsFromTime().

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