Audacity 3.2.0
Functions
WaveClipUtilities Namespace Reference

Functions

WAVE_TRACK_API bool GetFloatAtTime (const WaveClip &clip, double t, size_t iChannel, float &value, bool mayThrow)
 
WAVE_TRACK_API void SetFloatsFromTime (WaveClip &clip, double t, size_t iChannel, const float *buffer, size_t numSamples, sampleFormat effectiveFormat)
 Considers buffer as audio starting at TimeToSamples(t) (relative to clip play start time) and with equal stretch ratio. Samples at intersecting indices are then copied, leaving non-intersecting clip samples untouched. E.g., buffer: [a b c d e] clip : [x y z] result: [d e z]. More...
 
WAVE_TRACK_API bool SharesBoundaryWithNextClip (const WaveTrack::Interval &prev, const WaveTrack::Interval &next)
 used by commands which interact with clips using the keyboard More...
 

Function Documentation

◆ GetFloatAtTime()

bool WaveClipUtilities::GetFloatAtTime ( const WaveClip clip,
double  t,
size_t  iChannel,
float &  value,
bool  mayThrow 
)
Parameters
trelative to clip start sample

Audacity: A Digital Audio Editor

WaveClipUtilities.cpp

Paul Licameli split from WaveClip.cpp

Definition at line 15 of file WaveClipUtilities.cpp.

17{
18 if (!clip.WithinPlayRegion(t))
19 return false;
20 const auto start = clip.TimeToSamples(t);
21 return clip.GetSamples(
22 iChannel, reinterpret_cast<samplePtr>(&value), floatSample, start, 1u,
23 mayThrow);
24}
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
char * samplePtr
Definition: SampleFormat.h:57
bool WithinPlayRegion(double t) const
t ∈ [...)
Definition: WaveClip.cpp:1909
sampleCount TimeToSamples(double time) const override
Definition: WaveClip.cpp:1731
bool GetSamples(size_t ii, samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow=true) const
Get samples from one channel.
Definition: WaveClip.cpp:378

References floatSample, WaveClip::GetSamples(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, WaveClip::TimeToSamples(), and WaveClip::WithinPlayRegion().

Referenced by WaveChannelUtilities::GetFloatAtTime().

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

◆ SetFloatsFromTime()

void WaveClipUtilities::SetFloatsFromTime ( WaveClip clip,
double  t,
size_t  iChannel,
const float *  buffer,
size_t  numSamples,
sampleFormat  effectiveFormat 
)

Considers buffer as audio starting at TimeToSamples(t) (relative to clip play start time) and with equal stretch ratio. Samples at intersecting indices are then copied, leaving non-intersecting clip samples untouched. E.g., buffer: [a b c d e] clip : [x y z] result: [d e z].

Succeed with out-of-bounds requests, only changing what is in bounds.

Definition at line 26 of file WaveClipUtilities.cpp.

29{
30 const auto maybeNegativeStart = clip.TimeToSamples(t);
31 const auto maybeOutOfBoundEnd = maybeNegativeStart + numFloats;
32 const auto effectiveStart = std::max(sampleCount { 0 }, maybeNegativeStart);
33 const auto effectiveEnd =
34 std::min(clip.GetVisibleSampleCount(), maybeOutOfBoundEnd);
35 if (effectiveStart >= effectiveEnd)
36 return;
37 // Cannot be greater than `numFloats` -> safe cast
38 const auto effectiveLen = (effectiveEnd - effectiveStart).as_size_t();
39 // Cannot be greater than `numFloats` -> safe cast
40 const auto numLeadingZeros =
41 (effectiveStart - maybeNegativeStart).as_size_t();
42 const auto offsetBuffer =
43 reinterpret_cast<const char*>(buffer + numLeadingZeros);
44 clip.SetSamples(
45 iChannel, offsetBuffer, floatSample, effectiveStart, effectiveLen,
46 effectiveFormat);
47}
int min(int a, int b)
sampleCount GetVisibleSampleCount() const override
Definition: WaveClip.cpp:1804
void SetSamples(size_t ii, constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat)
Definition: WaveClip.cpp:397
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19

References floatSample, WaveClip::GetVisibleSampleCount(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, min(), WaveClip::SetSamples(), and WaveClip::TimeToSamples().

Referenced by WaveChannelUtilities::SetFloatsWithinTimeRange().

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

◆ SharesBoundaryWithNextClip()

bool WaveClipUtilities::SharesBoundaryWithNextClip ( const WaveTrack::Interval prev,
const WaveTrack::Interval next 
)

used by commands which interact with clips using the keyboard

When two clips are immediately next to each other, the GetPlayEndTime() of the first clip and the GetPlayStartTime() of the second clip may not be exactly equal due to rounding errors.

Definition at line 49 of file WaveClipUtilities.cpp.

51{
52 double endThis = prev.GetRate() * prev.GetPlayStartTime() +
54 double startNext = next.GetRate() * next.GetPlayStartTime();
55
56 // given that a double has about 15 significant digits, using a criterion
57 // of half a sample should be safe in all normal usage.
58 return fabs(startNext - endThis) < 0.5;
59}
double GetStretchRatio() const override
Definition: WaveClip.cpp:625
double GetPlayStartTime() const noexcept override
Definition: WaveClip.cpp:1762
int GetRate() const override
Definition: WaveClip.h:337
double as_double() const
Definition: SampleCount.h:46

References sampleCount::as_double(), WaveClip::GetPlayStartTime(), WaveClip::GetRate(), WaveClip::GetStretchRatio(), and WaveClip::GetVisibleSampleCount().

Referenced by anonymous_namespace{ClipMenus.cpp}::AdjustForFindingEndTimes(), anonymous_namespace{ClipMenus.cpp}::AdjustForFindingStartTimes(), anonymous_namespace{ClipMenus.cpp}::FindNextClipBoundary(), and anonymous_namespace{ClipMenus.cpp}::FindPrevClipBoundary().

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