Audacity 3.2.0
Typedefs | Functions
WaveChannelUtilities Namespace Reference

Typedefs

using Clip = WaveClipChannel
 
using ClipPointer = std::shared_ptr< Clip >
 
using ClipPointers = std::vector< ClipPointer >
 
using ClipConstPointer = std::shared_ptr< const Clip >
 
using ClipConstPointers = std::vector< ClipConstPointer >
 

Functions

WAVE_TRACK_API bool CompareClipsByPlayStartTime (const Clip &x, const Clip &y)
 
bool CompareClipPointersByPlayStartTime (const ClipConstPointer x, const ClipConstPointer y)
 
bool IsSortedByPlayStartTime (const ClipPointers &clips)
 
bool IsSortedByPlayStartTime (const ClipConstPointers &clips)
 
WAVE_TRACK_API ClipPointers SortedClipArray (WaveChannel &channel)
 Get clips sorted by play start time. More...
 
WAVE_TRACK_API ClipConstPointers SortedClipArray (const WaveChannel &channel)
 Get clips sorted by play start time. More...
 
WAVE_TRACK_API ClipPointer GetClipAtTime (WaveChannel &channel, double time)
 
WAVE_TRACK_API ClipConstPointer GetClipAtTime (const WaveChannel &channel, double time)
 
WAVE_TRACK_API EnvelopeGetEnvelopeAtTime (WaveChannel &channel, double time)
 
WAVE_TRACK_API std::pair< float, float > GetMinMax (const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
 
WAVE_TRACK_API float GetRMS (const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
 
WAVE_TRACK_API std::pair< size_t, size_t > GetFloatsCenteredAroundTime (const WaveChannel &channel, double t, float *buffer, size_t numSideSamples, bool mayThrow)
 Gets as many samples as it can, but no more than 2 * numSideSamples + 1, centered around t. Reads nothing if GetClipAtTime(t) == nullptr. Useful to access samples across clip boundaries, as it spreads the read to adjacent clips, i.e., not separated by silence from clip at t. More...
 
WAVE_TRACK_API bool GetFloatAtTime (const WaveChannel &channel, double t, float &value, bool mayThrow)
 
WAVE_TRACK_API bool GetFloatAtTime (const Clip &clip, double t, float &value, bool mayThrow)
 
WAVE_TRACK_API void SetFloatsCenteredAroundTime (WaveChannel &channel, double t, const float *buffer, size_t numSideSamples, sampleFormat effectiveFormat)
 Similar to GetFloatsCenteredAroundTime, but for writing. Sets as many samples as it can according to the same rules as GetFloatsCenteredAroundTime. Leaves the other samples untouched. More...
 
WAVE_TRACK_API void SetFloatAtTime (WaveChannel &channel, double t, float value, sampleFormat effectiveFormat)
 Sets sample nearest to t to value. Silently fails if GetClipAtTime(t) == nullptr. More...
 
WAVE_TRACK_API void SetFloatsWithinTimeRange (WaveChannel &channel, double t0, double t1, const std::function< float(double sampleTime)> &producer, sampleFormat effectiveFormat)
 Provides a means of setting clip values as a function of time. Included are closest sample to t0 up to closest sample to t1, exclusively. If the given interval is empty, i.e., t0 >= t1, no action is taken. More...
 
WAVE_TRACK_API size_t GetFloatsFromTime (const WaveChannel &channel, double t, float *buffer, size_t numSamples, bool mayThrow, PlaybackDirection direction)
 Helper for GetFloatsCenteredAroundTime. If direction == PlaybackDirection::Backward, fetches samples to the left of t, excluding t, without reversing. More...
 
WAVE_TRACK_API void SetFloatsFromTime (WaveChannel &channel, double t, const float *buffer, size_t numSamples, sampleFormat effectiveFormat, PlaybackDirection direction)
 Similar to GetFloatsFromTime, but for writing. Sets as many samples as it can according to the same rules as GetFloatsFromTime. Leaves the other samples untouched. More...
 
WAVE_TRACK_API void SetFloatsFromTime (Clip &channel, double t, const float *buffer, size_t numSamples, sampleFormat effectiveFormat, PlaybackDirection direction)
 Similar to GetFloatsFromTime, but for writing. Sets as many samples as it can according to the same rules as GetFloatsFromTime. Leaves the other samples untouched. More...
 
WAVE_TRACK_API ClipConstPointer GetAdjacentClip (const ClipConstPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
 Similar to GetNextClip, but returns nullptr if the neighbour clip is not adjacent. More...
 
WAVE_TRACK_API ClipPointer GetAdjacentClip (const ClipPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
 
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. More...
 
WAVE_TRACK_API ClipPointer GetNextClip (const ClipPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
 
WAVE_TRACK_API ClipPointer GetIntervalAtTime (WaveChannel &channel, double t)
 

Typedef Documentation

◆ Clip

Definition at line 30 of file WaveChannelUtilities.h.

◆ ClipConstPointer

using WaveChannelUtilities::ClipConstPointer = typedef std::shared_ptr<const Clip>

Definition at line 33 of file WaveChannelUtilities.h.

◆ ClipConstPointers

Definition at line 34 of file WaveChannelUtilities.h.

◆ ClipPointer

using WaveChannelUtilities::ClipPointer = typedef std::shared_ptr<Clip>

Definition at line 31 of file WaveChannelUtilities.h.

◆ ClipPointers

using WaveChannelUtilities::ClipPointers = typedef std::vector<ClipPointer>

Definition at line 32 of file WaveChannelUtilities.h.

Function Documentation

◆ CompareClipPointersByPlayStartTime()

bool WaveChannelUtilities::CompareClipPointersByPlayStartTime ( const ClipConstPointer  x,
const ClipConstPointer  y 
)
inline

Definition at line 39 of file WaveChannelUtilities.h.

41{
42 return CompareClipsByPlayStartTime(*x, *y);
43}
WAVE_TRACK_API bool CompareClipsByPlayStartTime(const Clip &x, const Clip &y)

References CompareClipsByPlayStartTime().

Referenced by IsSortedByPlayStartTime(), and SortedClipArray().

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

◆ CompareClipsByPlayStartTime()

bool WaveChannelUtilities::CompareClipsByPlayStartTime ( const Clip x,
const Clip y 
)

Definition at line 389 of file WaveChannelUtilities.cpp.

391{
392 return x.GetPlayStartTime() < y.GetPlayStartTime();
393}
double GetPlayStartTime() const override
Definition: WaveClip.cpp:198

References WaveClipChannel::GetPlayStartTime().

Referenced by CompareClipPointersByPlayStartTime(), and anonymous_namespace{WaveChannelUtilities.cpp}::DoGetNextClip().

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

◆ GetAdjacentClip() [1/2]

auto WaveChannelUtilities::GetAdjacentClip ( const ClipConstPointers clips,
const Clip clip,
PlaybackDirection  searchDirection 
)

Similar to GetNextClip, but returns nullptr if the neighbour clip is not adjacent.

Precondition
IsSortedByPlayStartTime(clips)

Definition at line 349 of file WaveChannelUtilities.cpp.

351{
352 assert(IsSortedByPlayStartTime(clips));
353 return DoGetAdjacentClip(clips, clip, direction);
354}
bool IsSortedByPlayStartTime(const ClipPointers &clips)
auto DoGetAdjacentClip(const std::vector< ClipPointer > &clips, const Clip &clip, PlaybackDirection direction) -> ClipPointer

References anonymous_namespace{WaveChannelUtilities.cpp}::DoGetAdjacentClip(), and IsSortedByPlayStartTime().

Referenced by GetFloatsFromTime(), and SetFloatsFromTime().

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

◆ GetAdjacentClip() [2/2]

auto WaveChannelUtilities::GetAdjacentClip ( const ClipPointers clips,
const Clip clip,
PlaybackDirection  searchDirection 
)

Definition at line 356 of file WaveChannelUtilities.cpp.

358{
359 assert(IsSortedByPlayStartTime(clips));
360 return DoGetAdjacentClip(clips, clip, direction);
361}

References anonymous_namespace{WaveChannelUtilities.cpp}::DoGetAdjacentClip(), and IsSortedByPlayStartTime().

Here is the call graph for this function:

◆ GetClipAtTime() [1/2]

auto WaveChannelUtilities::GetClipAtTime ( const WaveChannel channel,
double  time 
)

When the time is both the end of a clip and the start of the next clip, the latter clip is returned.

Definition at line 424 of file WaveChannelUtilities.cpp.

426{
427 return GetClipAtTime(const_cast<WaveChannel&>(channel), time);
428}
WAVE_TRACK_API ClipPointer GetClipAtTime(WaveChannel &channel, double time)

References GetClipAtTime().

Here is the call graph for this function:

◆ GetClipAtTime() [2/2]

auto WaveChannelUtilities::GetClipAtTime ( WaveChannel channel,
double  time 
)

When the time is both the end of a clip and the start of the next clip, the latter clip is returned.

Definition at line 412 of file WaveChannelUtilities.cpp.

414{
415 const auto clips = SortedClipArray(channel);
416 auto p = std::find_if(
417 clips.rbegin(), clips.rend(), [&](const auto& clip) {
418 return clip->WithinPlayRegion(time);
419 });
420 return p != clips.rend() ? *p : nullptr;
421}
WAVE_TRACK_API ClipPointers SortedClipArray(WaveChannel &channel)
Get clips sorted by play start time.

References SortedClipArray().

Referenced by anonymous_namespace{SampleHandle.cpp}::adjustTime(), SampleHandle::Click(), GetClipAtTime(), GetEnvelopeAtTime(), GetFloatAtTime(), GetFloatsFromTime(), WaveChannelSubView::GetMenuItems(), SampleHandle::HitTest(), anonymous_namespace{WaveChannelUtilities.cpp}::RoundToNearestClipSample(), SetFloatsFromTime(), and SetFloatsWithinTimeRange().

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

◆ GetEnvelopeAtTime()

Envelope * WaveChannelUtilities::GetEnvelopeAtTime ( WaveChannel channel,
double  time 
)

Definition at line 378 of file WaveChannelUtilities.cpp.

380{
381 // Substitute the first channel
382 auto &first = **channel.GetTrack().Channels().begin();
383 if (const auto clip = GetClipAtTime(first, time))
384 return &clip->GetEnvelope();
385 else
386 return nullptr;
387}
WaveTrack & GetTrack()
Definition: WaveTrack.h:841
auto Channels()
Definition: WaveTrack.h:263

References WaveTrack::Channels(), GetClipAtTime(), and WaveChannel::GetTrack().

Referenced by WaveformView::DetailedHitTest(), SampleHandle::FindSampleEditingLevel(), SampleHandle::HitTest(), and EnvelopeHandle::WaveChannelHitTest().

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

◆ GetFloatAtTime() [1/2]

bool WaveChannelUtilities::GetFloatAtTime ( const Clip clip,
double  t,
float &  value,
bool  mayThrow 
)

Definition at line 212 of file WaveChannelUtilities.cpp.

214{
215 const size_t iChannel = clip.GetChannelIndex();
217 t - clip.GetPlayStartTime(), iChannel, value, mayThrow);
218 return true;
219}
WaveClip & GetClip()
Definition: WaveClip.h:96
size_t GetChannelIndex() const
Definition: WaveClip.h:99
WAVE_TRACK_API bool GetFloatAtTime(const WaveClip &clip, double t, size_t iChannel, float &value, bool mayThrow)

References WaveClipChannel::GetChannelIndex(), WaveClipChannel::GetClip(), WaveClipUtilities::GetFloatAtTime(), WaveClipChannel::GetPlayStartTime(), and anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel.

Here is the call graph for this function:

◆ GetFloatAtTime() [2/2]

bool WaveChannelUtilities::GetFloatAtTime ( const WaveChannel channel,
double  t,
float &  value,
bool  mayThrow 
)
Returns
true if GetClipAtTime(t) != nullptr, false otherwise.

Definition at line 203 of file WaveChannelUtilities.cpp.

205{
206 const auto clip = GetClipAtTime(channel, t);
207 if (!clip)
208 return false;
209 return GetFloatAtTime(*clip, t, value, mayThrow);
210}
WAVE_TRACK_API bool GetFloatAtTime(const WaveChannel &channel, double t, float &value, bool mayThrow)

References GetClipAtTime(), and GetFloatAtTime().

Referenced by GetFloatAtTime(), and SampleHandle::HitTest().

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

◆ GetFloatsCenteredAroundTime()

std::pair< size_t, size_t > WaveChannelUtilities::GetFloatsCenteredAroundTime ( const WaveChannel channel,
double  t,
float *  buffer,
size_t  numSideSamples,
bool  mayThrow 
)

Gets as many samples as it can, but no more than 2 * numSideSamples + 1, centered around t. Reads nothing if GetClipAtTime(t) == nullptr. Useful to access samples across clip boundaries, as it spreads the read to adjacent clips, i.e., not separated by silence from clip at t.

Returns
The begin and end indices of the samples in the buffer where samples could actually be copied.

Definition at line 109 of file WaveChannelUtilities.cpp.

112{
113 const auto numSamplesReadLeft = GetFloatsFromTime(channel,
114 t, buffer, numSideSamples, mayThrow, PlaybackDirection::backward);
115 const auto numSamplesReadRight = GetFloatsFromTime(channel,
116 t, buffer + numSideSamples, numSideSamples + 1, mayThrow,
118 return { numSideSamples - numSamplesReadLeft,
119 numSideSamples + numSamplesReadRight };
120}
WAVE_TRACK_API size_t GetFloatsFromTime(const WaveChannel &channel, double t, float *buffer, size_t numSamples, bool mayThrow, PlaybackDirection direction)
Helper for GetFloatsCenteredAroundTime. If direction == PlaybackDirection::Backward,...

References backward, forward, and GetFloatsFromTime().

Referenced by SampleHandle::Click().

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

◆ GetFloatsFromTime()

size_t WaveChannelUtilities::GetFloatsFromTime ( const WaveChannel channel,
double  t,
float *  buffer,
size_t  numSamples,
bool  mayThrow,
PlaybackDirection  direction 
)

Helper for GetFloatsCenteredAroundTime. If direction == PlaybackDirection::Backward, fetches samples to the left of t, excluding t, without reversing.

See also
GetFloatsCenteredAroundTime
Returns
The number of samples actually copied.

Definition at line 178 of file WaveChannelUtilities.cpp.

181{
182 RoundToNearestClipSample(channel, t);
183 auto clip = GetClipAtTime(channel, t);
184 auto numSamplesRead = 0u;
185 const auto forward = direction == PlaybackDirection::forward;
186 const auto clips = SortedClipArray(channel);
187 while (clip)
188 {
189 const auto args = GetSampleAccessArgs(
190 *clip, t, buffer, numSamples, numSamplesRead, forward);
191 if (!clip->GetSamples(
192 args.offsetBuffer, floatSample, args.start, args.len,
193 mayThrow))
194 return 0u;
195 numSamplesRead += args.len;
196 if (numSamplesRead >= numSamples)
197 break;
198 clip = GetAdjacentClip(clips, *clip, direction);
199 }
200 return numSamplesRead;
201}
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
WAVE_TRACK_API ClipConstPointer GetAdjacentClip(const ClipConstPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
Similar to GetNextClip, but returns nullptr if the neighbour clip is not adjacent.
SampleAccessArgs< BufferType > GetSampleAccessArgs(const Clip &clip, double startOrEndTime, BufferType buffer, size_t totalToRead, size_t alreadyRead, bool forward)
void RoundToNearestClipSample(const WaveChannel &channel, double &t)

References floatSample, forward, GetAdjacentClip(), GetClipAtTime(), anonymous_namespace{WaveChannelUtilities.cpp}::GetSampleAccessArgs(), anonymous_namespace{WaveChannelUtilities.cpp}::RoundToNearestClipSample(), and SortedClipArray().

Referenced by GetFloatsCenteredAroundTime().

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

◆ GetIntervalAtTime()

auto WaveChannelUtilities::GetIntervalAtTime ( WaveChannel channel,
double  t 
)

Definition at line 430 of file WaveChannelUtilities.cpp.

432{
433 ClipPointer result;
434 for (const auto &interval : channel.Intervals())
435 if (interval->WithinPlayRegion(t))
436 return interval;
437 return nullptr;
438}
IteratorRange< IntervalIterator< WaveClipChannel > > Intervals()
Definition: WaveTrack.cpp:762
std::shared_ptr< Clip > ClipPointer

References WaveChannel::Intervals().

Referenced by SelectHandle::Click().

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

◆ GetMinMax()

std::pair< float, float > WaveChannelUtilities::GetMinMax ( const WaveChannel channel,
double  t0,
double  t1,
bool  mayThrow = true 
)

Getting high-level data for one channel for screen display and clipping calculations and Contrast


Audacity: A Digital Audio Editor

WaveChannelUtilities.cpp

Paul Licameli

Definition at line 21 of file WaveChannelUtilities.cpp.

23{
24 std::pair<float, float> results {
25 // we need these at extremes to make sure we find true min and max
26 std::numeric_limits<float>::max(),
27 std::numeric_limits<float>::lowest(),
28 };
29 bool clipFound = false;
30
31 if (t0 > t1) {
32 if (mayThrow)
34 return results;
35 }
36
37 if (t0 == t1)
38 return results;
39
40 for (const auto &clip: channel.Intervals())
41 {
42 if (t1 >= clip->GetPlayStartTime() && t0 <= clip->GetPlayEndTime())
43 {
44 clipFound = true;
45 auto clipResults = clip->GetMinMax(t0, t1, mayThrow);
46 if (clipResults.first < results.first)
47 results.first = clipResults.first;
48 if (clipResults.second > results.second)
49 results.second = clipResults.second;
50 }
51 }
52
53 if(!clipFound)
54 {
55 results = { 0.f, 0.f }; // sensible defaults if no clips found
56 }
57
58 return results;
59}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.

References WaveChannel::Intervals(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by NormalizeBase::AnalyseTrack(), AmplifyBase::Init(), and NyquistBase::ProcessOne().

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

◆ GetNextClip() [1/2]

auto WaveChannelUtilities::GetNextClip ( const ClipConstPointers clips,
const Clip clip,
PlaybackDirection  searchDirection 
)

Returns clips next to clip in the given direction, or nullptr if there is none.

Definition at line 363 of file WaveChannelUtilities.cpp.

366{
367 assert(IsSortedByPlayStartTime(clips));
368 return DoGetNextClip(clips, clip, direction);
369}
auto DoGetNextClip(const std::vector< ClipPointer > &clips, const Clip &clip, PlaybackDirection direction) -> ClipPointer

References anonymous_namespace{WaveChannelUtilities.cpp}::DoGetNextClip(), and IsSortedByPlayStartTime().

Referenced by anonymous_namespace{WaveChannelUtilities.cpp}::DoGetAdjacentClip(), and SetFloatsWithinTimeRange().

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

◆ GetNextClip() [2/2]

auto WaveChannelUtilities::GetNextClip ( const ClipPointers clips,
const Clip clip,
PlaybackDirection  searchDirection 
)

Definition at line 371 of file WaveChannelUtilities.cpp.

373{
374 assert(IsSortedByPlayStartTime(clips));
375 return DoGetNextClip(clips, clip, direction);
376}

References anonymous_namespace{WaveChannelUtilities.cpp}::DoGetNextClip(), and IsSortedByPlayStartTime().

Here is the call graph for this function:

◆ GetRMS()

float WaveChannelUtilities::GetRMS ( const WaveChannel channel,
double  t0,
double  t1,
bool  mayThrow = true 
)

Getting high-level data for one channel for screen display and clipping calculations and Contrast


Audacity: A Digital Audio Editor

WaveChannelUtilities.cpp

Paul Licameli

Definition at line 61 of file WaveChannelUtilities.cpp.

63{
64 if (t0 > t1) {
65 if (mayThrow)
67 return 0.f;
68 }
69
70 if (t0 == t1)
71 return 0.f;
72
73 double sumsq = 0.0;
74 double duration = 0;
75
76 for (const auto &clip: channel.Intervals())
77 {
78 // If t1 == clip->GetStartTime() or t0 == clip->GetEndTime(), then the clip
79 // is not inside the selection, so we don't want it.
80 // if (t1 >= clip->GetStartTime() && t0 <= clip->GetEndTime())
81 if (t1 >= clip->GetPlayStartTime() && t0 <= clip->GetPlayEndTime())
82 {
83 const auto clipStart = std::max(t0, clip->GetPlayStartTime());
84 const auto clipEnd = std::min(t1, clip->GetPlayEndTime());
85
86 float cliprms = clip->GetRMS(t0, t1, mayThrow);
87
88 sumsq += cliprms * cliprms * (clipEnd - clipStart);
89 duration += (clipEnd - clipStart);
90 }
91 }
92 return duration > 0 ? sqrt(sumsq / duration) : 0.0;
93}
int min(int a, int b)
__finl float_x4 __vecc sqrt(const float_x4 &a)

References WaveChannel::Intervals(), min(), staffpad::audio::simd::sqrt(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by ContrastBase::GetDB(), LoudnessBase::GetTrackRMS(), and NyquistBase::ProcessOne().

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

◆ IsSortedByPlayStartTime() [1/2]

bool WaveChannelUtilities::IsSortedByPlayStartTime ( const ClipConstPointers clips)
inline

Definition at line 51 of file WaveChannelUtilities.h.

52{
53 return is_sorted(
54 clips.begin(), clips.end(), CompareClipPointersByPlayStartTime);
55}
bool CompareClipPointersByPlayStartTime(const ClipConstPointer x, const ClipConstPointer y)

References CompareClipPointersByPlayStartTime().

Here is the call graph for this function:

◆ IsSortedByPlayStartTime() [2/2]

bool WaveChannelUtilities::IsSortedByPlayStartTime ( const ClipPointers clips)
inline

Definition at line 45 of file WaveChannelUtilities.h.

46{
47 return is_sorted(
48 clips.begin(), clips.end(), CompareClipPointersByPlayStartTime);
49}

References CompareClipPointersByPlayStartTime().

Referenced by anonymous_namespace{WaveChannelUtilities.cpp}::DoGetNextClip(), GetAdjacentClip(), and GetNextClip().

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

◆ SetFloatAtTime()

void WaveChannelUtilities::SetFloatAtTime ( WaveChannel channel,
double  t,
float  value,
sampleFormat  effectiveFormat 
)

Sets sample nearest to t to value. Silently fails if GetClipAtTime(t) == nullptr.

Definition at line 259 of file WaveChannelUtilities.cpp.

261{
262 SetFloatsCenteredAroundTime(channel, t, &value, 0u, effectiveFormat);
263}
WAVE_TRACK_API void SetFloatsCenteredAroundTime(WaveChannel &channel, double t, const float *buffer, size_t numSideSamples, sampleFormat effectiveFormat)
Similar to GetFloatsCenteredAroundTime, but for writing. Sets as many samples as it can according to ...

References SetFloatsCenteredAroundTime().

Referenced by SampleHandle::Click().

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

◆ SetFloatsCenteredAroundTime()

void WaveChannelUtilities::SetFloatsCenteredAroundTime ( WaveChannel channel,
double  t,
const float *  buffer,
size_t  numSideSamples,
sampleFormat  effectiveFormat 
)

Similar to GetFloatsCenteredAroundTime, but for writing. Sets as many samples as it can according to the same rules as GetFloatsCenteredAroundTime. Leaves the other samples untouched.

See also
GetFloatsCenteredAroundTime

Definition at line 221 of file WaveChannelUtilities.cpp.

224{
225 SetFloatsFromTime(channel,
226 t, buffer, numSideSamples, effectiveFormat,
228 SetFloatsFromTime(channel,
229 t, buffer + numSideSamples, numSideSamples + 1, effectiveFormat,
231}
WAVE_TRACK_API void SetFloatsFromTime(WaveChannel &channel, double t, const float *buffer, size_t numSamples, sampleFormat effectiveFormat, PlaybackDirection direction)
Similar to GetFloatsFromTime, but for writing. Sets as many samples as it can according to the same r...

References backward, forward, and SetFloatsFromTime().

Referenced by SampleHandle::Click(), and SetFloatAtTime().

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

◆ SetFloatsFromTime() [1/2]

WAVE_TRACK_API void WaveChannelUtilities::SetFloatsFromTime ( Clip channel,
double  t,
const float *  buffer,
size_t  numSamples,
sampleFormat  effectiveFormat,
PlaybackDirection  direction 
)

Similar to GetFloatsFromTime, but for writing. Sets as many samples as it can according to the same rules as GetFloatsFromTime. Leaves the other samples untouched.

See also
GetFloatsFromTime

◆ SetFloatsFromTime() [2/2]

void WaveChannelUtilities::SetFloatsFromTime ( WaveChannel channel,
double  t,
const float *  buffer,
size_t  numSamples,
sampleFormat  effectiveFormat,
PlaybackDirection  direction 
)

Similar to GetFloatsFromTime, but for writing. Sets as many samples as it can according to the same rules as GetFloatsFromTime. Leaves the other samples untouched.

See also
GetFloatsFromTime

Definition at line 233 of file WaveChannelUtilities.cpp.

236{
237 RoundToNearestClipSample(channel, t);
238 auto clip = GetClipAtTime(channel, t);
239 auto numSamplesWritten = 0u;
240 const auto forward = direction == PlaybackDirection::forward;
241 const auto clips = SortedClipArray(channel);
242 while (clip)
243 {
244 const auto args = GetSampleAccessArgs(
245 *clip, t, buffer, numSamples, numSamplesWritten, forward);
246 if (args.len > 0u)
247 {
248 clip->SetSamples(
249 args.offsetBuffer, floatSample, args.start, args.len,
250 effectiveFormat);
251 numSamplesWritten += args.len;
252 if (numSamplesWritten >= numSamples)
253 break;
254 }
255 clip = GetAdjacentClip(clips, *clip, direction);
256 }
257}

References floatSample, forward, GetAdjacentClip(), GetClipAtTime(), anonymous_namespace{WaveChannelUtilities.cpp}::GetSampleAccessArgs(), anonymous_namespace{WaveChannelUtilities.cpp}::RoundToNearestClipSample(), and SortedClipArray().

Referenced by SetFloatsCenteredAroundTime().

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

◆ SetFloatsWithinTimeRange()

void WaveChannelUtilities::SetFloatsWithinTimeRange ( WaveChannel channel,
double  t0,
double  t1,
const std::function< float(double sampleTime)> &  producer,
sampleFormat  effectiveFormat 
)

Provides a means of setting clip values as a function of time. Included are closest sample to t0 up to closest sample to t1, exclusively. If the given interval is empty, i.e., t0 >= t1, no action is taken.

Parameters
producera function taking sample (absolute, not clip-relative) time and returning the desired value for the sample at that time.

Definition at line 265 of file WaveChannelUtilities.cpp.

269{
270 if (t0 >= t1)
271 return;
272 const auto sortedClips = SortedClipArray(channel);
273 if (sortedClips.empty())
274 return;
275 t0 = std::max(t0, (*sortedClips.begin())->GetPlayStartTime());
276 t1 = std::min(t1, (*sortedClips.rbegin())->GetPlayEndTime());
277 auto clip = GetClipAtTime(channel, t0);
278 const auto clips = SortedClipArray(channel);
279 while (clip) {
280 const auto clipStartTime = clip->GetPlayStartTime();
281 const auto clipEndTime = clip->GetPlayEndTime();
282 const auto sampsPerSec = clip->GetRate() / clip->GetStretchRatio();
283 const auto roundedT0 =
284 std::round((t0 - clipStartTime) * sampsPerSec) / sampsPerSec +
285 clipStartTime;
286 const auto roundedT1 =
287 std::round((t1 - clipStartTime) * sampsPerSec) / sampsPerSec +
288 clipStartTime;
289 if (clipStartTime > roundedT1)
290 break;
291 const auto tt0 = std::max(clipStartTime, roundedT0);
292 const auto tt1 = std::min(clipEndTime, roundedT1);
293 const size_t numSamples = (tt1 - tt0) * sampsPerSec + .5;
294 std::vector<float> values(numSamples);
295 for (auto i = 0u; i < numSamples; ++i)
296 values[i] = producer(tt0 + clip->SamplesToTime(i));
297 const size_t iChannel = clip->GetChannelIndex();
299 tt0 - clipStartTime, iChannel, values.data(), numSamples,
300 effectiveFormat);
301 clip = GetNextClip(clips, *clip, PlaybackDirection::forward);
302 }
303}
const wxChar * values
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.
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 eq...
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References forward, GetClipAtTime(), GetNextClip(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, min(), fast_float::round(), WaveClipUtilities::SetFloatsFromTime(), SortedClipArray(), and values.

Referenced by SampleHandle::Drag().

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

◆ SortedClipArray() [1/2]

auto WaveChannelUtilities::SortedClipArray ( const WaveChannel channel)

Get clips sorted by play start time.

Definition at line 405 of file WaveChannelUtilities.cpp.

407{
408 auto pointers = SortedClipArray(const_cast<WaveChannel &>(channel));
409 return { pointers.begin(), pointers.end() };
410}

References SortedClipArray().

Here is the call graph for this function:

◆ SortedClipArray() [2/2]

auto WaveChannelUtilities::SortedClipArray ( WaveChannel channel)

Get clips sorted by play start time.

Definition at line 395 of file WaveChannelUtilities.cpp.

397{
398 auto &&clips = channel.Intervals();
399 ClipPointers result{ clips.begin(), clips.end() };
400 sort(result.begin(), result.end(), CompareClipPointersByPlayStartTime);
401 return result;
402}
std::vector< ClipPointer > ClipPointers

References CompareClipPointersByPlayStartTime(), and WaveChannel::Intervals().

Referenced by SampleHandle::Drag(), WaveTrack::GetClipAtTime(), GetClipAtTime(), GetFloatsFromTime(), WaveChannelView::SelectNextClip(), SetFloatsFromTime(), SetFloatsWithinTimeRange(), and SortedClipArray().

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