Audacity 3.2.0
Public Member Functions | List of all members
WaveChannel Class Reference

#include <WaveTrack.h>

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

Public Member Functions

 ~WaveChannel () override
 
WaveTrackGetTrack ()
 
const WaveTrackGetTrack () const
 
auto GetInterval (size_t iInterval)
 
auto GetInterval (size_t iInterval) const
 
auto Intervals ()
 
auto Intervals () const
 
bool GetFloats (float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
 "narrow" overload fetches from the unique channel More...
 
ChannelSampleView GetSampleView (double t0, double t1, bool mayThrow) const
 Request channel samples within [t0, t1), not knowing in advance how many this will be. More...
 
bool Set (constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
 Random-access assignment of a range of samples. More...
 
bool AppendBuffer (constSamplePtr buffer, sampleFormat format, size_t len, unsigned stride, sampleFormat effectiveFormat)
 
bool Append (constSamplePtr buffer, sampleFormat format, size_t len)
 
std::pair< float, float > GetMinMax (double t0, double t1, bool mayThrow=true) const
 
float GetRMS (double t0, double t1, bool mayThrow=true) const
 Get root-mean-square. More...
 
size_t GetBestBlockSize (sampleCount t) const
 A hint for sizing of well aligned fetches. More...
 
size_t GetIdealBlockSize ()
 A hint for sizing of well aligned fetches. More...
 
size_t GetMaxBlockSize () const
 
bool GetFloats (size_t iChannel, size_t nBuffers, float *const buffers[], sampleCount start, size_t len, bool backwards=false, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
 
- Public Member Functions inherited from Channel
virtual ~Channel ()
 
ChannelGroupGetChannelGroup ()
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
const ChannelGroupGetChannelGroup () const
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
size_t GetChannelIndex () const
 
size_t ReallyGetChannelIndex () const
 
size_t NIntervals () const
 Report the number of intervals. More...
 
template<typename IntervalType = Interval>
std::shared_ptr< IntervalType > GetInterval (size_t iInterval)
 Retrieve an interval, cast to the given type. More...
 
template<typename IntervalType = const Interval>
auto GetInterval (size_t iInterval) const -> std::enable_if_t< std::is_const_v< IntervalType >, std::shared_ptr< IntervalType > >
 
template<typename IntervalType = Interval>
IteratorRange< IntervalIterator< IntervalType > > Intervals ()
 Get range of intervals with mutative access. More...
 
template<typename IntervalType = const Interval>
auto Intervals () const -> std::enable_if_t< std::is_const_v< IntervalType >, IteratorRange< IntervalIterator< IntervalType > > >
 Get range of intervals with read-only access. More...
 
- Public Member Functions inherited from WideSampleSequence
virtual ~WideSampleSequence ()
 
virtual size_t NChannels () const =0
 A constant property. More...
 
virtual float GetChannelGain (int channel) const =0
 
bool GetFloats (size_t iChannel, size_t nBuffers, float *const buffers[], sampleCount start, size_t len, bool backwards=false, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
 
virtual bool DoGet (size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backward, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const =0
 
virtual double GetStartTime () const =0
 
virtual double GetEndTime () const =0
 
virtual double GetRate () const =0
 
sampleCount TimeToLongSamples (double t0) const
 
double LongSamplesToTime (sampleCount pos) const
 
double SnapToSample (double t) const
 
virtual sampleFormat WidestEffectiveFormat () const =0
 
virtual bool HasTrivialEnvelope () const =0
 
virtual void GetEnvelopeValues (double *buffer, size_t bufferLen, double t0, bool backwards) const =0
 
- Public Member Functions inherited from AudioGraph::Channel
virtual ~Channel ()
 
virtual ChannelType GetChannelType () const =0
 Classify this channel. More...
 

Additional Inherited Members

- Public Types inherited from Channel
using Interval = ChannelInterval
 
- Protected Member Functions inherited from Channel
virtual ChannelGroupDoGetChannelGroup () const =0
 Subclass must override. More...
 
virtual ChannelGroupReallyDoGetChannelGroup () const
 This is temporary! It defaults to call the above. More...
 

Detailed Description

Definition at line 131 of file WaveTrack.h.

Constructor & Destructor Documentation

◆ ~WaveChannel()

WaveChannel::~WaveChannel ( )
overridedefault

Member Function Documentation

◆ Append()

bool WaveChannel::Append ( constSamplePtr  buffer,
sampleFormat  format,
size_t  len 
)

If there is an existing WaveClip in the WaveTrack that owns the channel, then the data are appended to that clip. If there are no WaveClips in the track, then a new one is created.

Returns
true if at least one complete block was created
Exception safety guarantee:
Partial – Some prefix (maybe none) of the buffer is appended, and no content already flushed to disk is lost.

Definition at line 2656 of file WaveTrack.cpp.

2658{
2659 return GetTrack().Append(buffer, format, len, 1, widestSampleFormat);
2660}
WaveTrack & GetTrack()
Definition: WaveTrack.h:1202
bool Append(constSamplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1, sampleFormat effectiveFormat=widestSampleFormat, size_t iChannel=0) override
Definition: WaveTrack.cpp:2665

References WaveTrack::Append(), anonymous_namespace{ExportPCM.cpp}::format, GetTrack(), and widestSampleFormat.

Referenced by EffectEqualization::Task::AccumulateSamples(), WaveTrackSink::DoConsume(), TrackSpectrumTransformer::DoOutput(), EffectSBSMS::Process(), EffectPaulstretch::ProcessOne(), EffectChangeSpeed::ProcessOne(), and EffectTwoPassSimpleMono::ProcessOne().

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

◆ AppendBuffer()

bool WaveChannel::AppendBuffer ( constSamplePtr  buffer,
sampleFormat  format,
size_t  len,
unsigned  stride,
sampleFormat  effectiveFormat 
)
Exception safety guarantee:
Partial – Some prefix (maybe none) of the buffer is appended, and no content already flushed to disk is lost.

Definition at line 2647 of file WaveTrack.cpp.

2649{
2650 return GetTrack().Append(buffer, format, len, stride, effectiveFormat);
2651}

References WaveTrack::Append(), anonymous_namespace{ExportPCM.cpp}::format, and GetTrack().

Here is the call graph for this function:

◆ GetBestBlockSize()

size_t WaveChannel::GetBestBlockSize ( sampleCount  t) const
inline

A hint for sizing of well aligned fetches.

Definition at line 1216 of file WaveTrack.h.

1216 {
1217 return GetTrack().GetBestBlockSize(t);
1218}
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:2679

References WaveTrack::GetBestBlockSize(), and GetTrack().

Referenced by EffectNormalize::AnalyseTrackData(), TrackSpectrumTransformer::Process(), EffectChangeSpeed::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectNormalize::ProcessOne(), EffectLoudness::ProcessOne(), and resampleCB().

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

◆ GetFloats() [1/2]

bool WaveChannel::GetFloats ( float *  buffer,
sampleCount  start,
size_t  len,
fillFormat  fill = FillFormat::fillZero,
bool  mayThrow = true,
sampleCount pNumWithinClips = nullptr 
) const
inline

"narrow" overload fetches from the unique channel

Definition at line 154 of file WaveTrack.h.

157 {
158 constexpr auto backwards = false;
159 return GetFloats(
160 0, 1, &buffer, start, len, backwards, fill, mayThrow, pNumWithinClips);
161 }
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:154

Referenced by EffectNormalize::AnalyseTrackData(), EffectAutoDuck::ApplyDuckFade(), TrackSpectrumTransformer::Process(), EffectPaulstretch::ProcessOne(), EffectChangeSpeed::ProcessOne(), EffectClickRemoval::ProcessOne(), EffectRepair::ProcessOne(), EffectFindClipping::ProcessOne(), EffectEqualization::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectNormalize::ProcessOne(), and resampleCB().

Here is the caller graph for this function:

◆ GetFloats() [2/2]

bool WideSampleSequence::GetFloats ( size_t  iChannel,
size_t  nBuffers,
float *const  buffers[],
sampleCount  start,
size_t  len,
bool  backwards = false,
fillFormat  fill = FillFormat::fillZero,
bool  mayThrow = true,
sampleCount pNumWithinClips = nullptr 
) const

Retrieve samples from a sequence in floating-point format, regardless of the storage format

Parameters
iChannelindex of first channel to fetch
nBufferscounts buffers
buffersreceive the samples
startstarting sample, relative to absolute time zero
lenhow many samples to get. buffers are assumed sufficiently large
fillhow to assign values for sample positions between clips
mayThrowif false, fill buffer with zeros when there is failure to retrieve samples; else throw
[out]pNumWithinClipsReport how many samples were copied from within clips, rather than filled according to fillFormat; but these were not necessarily one contiguous range.
Precondition
iChannel + nBuffers <= NChannels()
Returns
false when mayThrow is false and not all samples could be retrieved
Postcondition
if return value is false, buffers are zero-filled

Definition at line 58 of file WideSampleSequence.cpp.

34{
35 // Cast the pointers to pass them to DoGet() which handles multiple
36 // destination formats
37 const auto castBuffers = reinterpret_cast<const samplePtr*>(buffers);
38 const auto result = DoGet(
39 iChannel, nBuffers, castBuffers,
40 floatSample, start, len, backwards, fill, mayThrow, pNumWithinClips);
41 if (!result)
42 while (nBuffers--)
43 ClearSamples(castBuffers[nBuffers], floatSample, 0, len);
44 return result;
45}
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
char * samplePtr
Definition: SampleFormat.h:57
virtual bool DoGet(size_t iChannel, size_t nBuffers, const samplePtr buffers[], sampleFormat format, sampleCount start, size_t len, bool backward, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const =0

◆ GetIdealBlockSize()

size_t WaveChannel::GetIdealBlockSize ( )
inline

A hint for sizing of well aligned fetches.

Definition at line 1220 of file WaveTrack.h.

1220 {
1221 return GetTrack().GetIdealBlockSize();
1222}
size_t GetIdealBlockSize()
Definition: WaveTrack.cpp:2721

References WaveTrack::GetIdealBlockSize(), and GetTrack().

Here is the call graph for this function:

◆ GetInterval() [1/2]

auto WaveChannel::GetInterval ( size_t  iInterval)
inline

Definition at line 142 of file WaveTrack.h.

142 { return
143 ::Channel::GetInterval<WaveChannelInterval>(iInterval); }

◆ GetInterval() [2/2]

auto WaveChannel::GetInterval ( size_t  iInterval) const
inline

Definition at line 144 of file WaveTrack.h.

144 { return
145 ::Channel::GetInterval<const WaveChannelInterval>(iInterval); }

◆ GetMaxBlockSize()

size_t WaveChannel::GetMaxBlockSize ( ) const
inline

A hint for maximum returned by either of GetBestBlockSize, GetIdealBlockSize

Definition at line 1224 of file WaveTrack.h.

1224 {
1225 return GetTrack().GetMaxBlockSize();
1226}
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:2699

References WaveTrack::GetMaxBlockSize(), and GetTrack().

Referenced by EffectNormalize::AnalyseTrackData(), TrackSpectrumTransformer::Process(), EffectChangeSpeed::ProcessOne(), EffectClickRemoval::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), and EffectNormalize::ProcessOne().

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

◆ GetMinMax()

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

Definition at line 3060 of file WaveTrack.cpp.

3062{
3063 std::pair<float, float> results {
3064 // we need these at extremes to make sure we find true min and max
3065 FLT_MAX, -FLT_MAX
3066 };
3067 bool clipFound = false;
3068
3069 if (t0 > t1) {
3070 if (mayThrow)
3072 return results;
3073 }
3074
3075 if (t0 == t1)
3076 return results;
3077
3078 for (const auto &clip: GetTrack().mClips)
3079 {
3080 if (t1 >= clip->GetPlayStartTime() && t0 <= clip->GetPlayEndTime())
3081 {
3082 clipFound = true;
3083 // TODO wide wave tracks -- choose correct channel
3084 auto clipResults = clip->GetMinMax(0, t0, t1, mayThrow);
3085 if (clipResults.first < results.first)
3086 results.first = clipResults.first;
3087 if (clipResults.second > results.second)
3088 results.second = clipResults.second;
3089 }
3090 }
3091
3092 if(!clipFound)
3093 {
3094 results = { 0.f, 0.f }; // sensible defaults if no clips found
3095 }
3096
3097 return results;
3098}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.

References GetTrack(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by EffectNormalize::AnalyseTrack().

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

◆ GetRMS()

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

Get root-mean-square.

Precondition
t0 <= t1

Definition at line 3100 of file WaveTrack.cpp.

3101{
3102 if (t0 > t1) {
3103 if (mayThrow)
3105 return 0.f;
3106 }
3107
3108 if (t0 == t1)
3109 return 0.f;
3110
3111 double sumsq = 0.0;
3112 double duration = 0;
3113
3114 for (const auto &clip: GetTrack().mClips)
3115 {
3116 // If t1 == clip->GetStartTime() or t0 == clip->GetEndTime(), then the clip
3117 // is not inside the selection, so we don't want it.
3118 // if (t1 >= clip->GetStartTime() && t0 <= clip->GetEndTime())
3119 if (t1 >= clip->GetPlayStartTime() && t0 <= clip->GetPlayEndTime())
3120 {
3121 const auto clipStart = std::max(t0, clip->GetPlayStartTime());
3122 const auto clipEnd = std::min(t1, clip->GetPlayEndTime());
3123
3124 // TODO wide wave tracks -- choose correct channel
3125 float cliprms = clip->GetRMS(0, t0, t1, mayThrow);
3126
3127 sumsq += cliprms * cliprms * (clipEnd - clipStart);
3128 duration += (clipEnd - clipStart);
3129 }
3130 }
3131 return duration > 0 ? sqrt(sumsq / duration) : 0.0;
3132}
int min(int a, int b)
__finl float_x4 __vecc sqrt(const float_x4 &a)

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

Referenced by EffectLoudness::GetTrackRMS().

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

◆ GetSampleView()

ChannelSampleView WaveChannel::GetSampleView ( double  t0,
double  t1,
bool  mayThrow 
) const

Request channel samples within [t0, t1), not knowing in advance how many this will be.

The stretching of intersecting intervals influences the number of samples fitting into [t0, t1), i.e., half as many for twice as large a stretch ratio, due to a larger spacing of the raw samples.

Precondition
samples in [t0, t1) can be counted with size_t

Definition at line 3462 of file WaveTrack.cpp.

3463{
3464 std::vector<std::shared_ptr<const WaveChannelInterval>>
3465 intersectingIntervals;
3466 for (const auto& interval : Intervals())
3467 if (interval->Intersects(t0, t1))
3468 intersectingIntervals.push_back(interval);
3469 if (intersectingIntervals.empty())
3470 return { AudioSegmentSampleView {
3471 (TimeToLongSamples(t1) - TimeToLongSamples(t0)).as_size_t() } };
3472 std::sort(
3473 intersectingIntervals.begin(), intersectingIntervals.end(),
3474 [](const auto& a, const auto& b) { return a->Start() < b->Start(); });
3475 std::vector<AudioSegmentSampleView> segments;
3476 segments.reserve(2 * intersectingIntervals.size() + 1);
3477 for (auto i = 0u; i < intersectingIntervals.size();++i)
3478 {
3479 const auto& interval = intersectingIntervals[i];
3480 const auto intervalStartTime = interval->Start();
3481 if (t0 < intervalStartTime)
3482 {
3483 const auto numSamples = TimeToLongSamples(intervalStartTime - t0);
3484 segments.push_back(AudioSegmentSampleView{numSamples.as_size_t()});
3485 t0 = intervalStartTime;
3486 }
3487 const auto intervalT0 = t0 - intervalStartTime;
3488 const auto intervalT1 = std::min(t1, interval->End()) - intervalStartTime;
3489 if(intervalT1 > intervalT0)
3490 {
3491 auto newSegment =
3492 interval->GetSampleView(intervalT0, intervalT1, mayThrow);
3493 t0 += intervalT1 - intervalT0;
3494 segments.push_back(std::move(newSegment));
3495 }
3496 if (t0 == t1)
3497 break;
3498 }
3499 if (t0 < t1)
3500 segments.push_back(AudioSegmentSampleView {
3501 (TimeToLongSamples(t1) - TimeToLongSamples(t0)).as_size_t() });
3502 return segments;
3503}
auto Intervals()
Definition: WaveTrack.h:147
sampleCount TimeToLongSamples(double t0) const

References Intervals(), min(), and WideSampleSequence::TimeToLongSamples().

Here is the call graph for this function:

◆ GetTrack() [1/2]

WaveTrack & WaveChannel::GetTrack ( )
inline

Definition at line 1202 of file WaveTrack.h.

1202 {
1203 auto &result = static_cast<WaveTrack&>(DoGetChannelGroup());
1204 // TODO wide wave tracks -- remove assertion
1205 assert(&result == this);
1206 return result;
1207}
virtual ChannelGroup & DoGetChannelGroup() const =0
Subclass must override.
A Track that contains audio waveform data.
Definition: WaveTrack.h:222

References Channel::DoGetChannelGroup().

Referenced by Append(), AppendBuffer(), GetBestBlockSize(), GetIdealBlockSize(), GetMaxBlockSize(), GetMinMax(), GetRMS(), EffectLoudness::LoadBufferBlock(), EffectPaulstretch::ProcessOne(), SpectralDataManager::Worker::ProcessOvertones(), SpectralDataManager::Worker::ProcessSnapping(), Set(), and EffectLoudness::StoreBufferBlock().

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

◆ GetTrack() [2/2]

const WaveTrack & WaveChannel::GetTrack ( ) const
inline

Definition at line 1209 of file WaveTrack.h.

1209 {
1210 auto &result = static_cast<const WaveTrack&>(DoGetChannelGroup());
1211 // TODO wide wave tracks -- remove assertion
1212 assert(&result == this);
1213 return result;
1214}

References Channel::DoGetChannelGroup().

Here is the call graph for this function:

◆ Intervals() [1/2]

auto WaveChannel::Intervals ( )
inline

Definition at line 147 of file WaveTrack.h.

147{ return ::Channel::Intervals<WaveChannelInterval>(); }

Referenced by GetSampleView().

Here is the caller graph for this function:

◆ Intervals() [2/2]

auto WaveChannel::Intervals ( ) const
inline

Definition at line 148 of file WaveTrack.h.

148 {
149 return ::Channel::Intervals<const WaveChannelInterval>(); }

◆ Set()

bool WaveChannel::Set ( constSamplePtr  buffer,
sampleFormat  format,
sampleCount  start,
size_t  len,
sampleFormat  effectiveFormat = widestSampleFormat 
)

Random-access assignment of a range of samples.

Exception safety guarantee:
Weak
Parameters
effectiveFormatMake the effective format of the data at least the minumum of this value and `format`. (Maybe wider, if merging with preexistent data.) If the data are later narrowed from stored format, but not narrower than the effective, then no dithering will occur.

Definition at line 3506 of file WaveTrack.cpp.

3508{
3509 for (const auto &clip: GetTrack().mClips)
3510 {
3511 auto clipStart = clip->GetPlayStartSample();
3512 auto clipEnd = clip->GetPlayEndSample();
3513
3514 if (clipEnd > start && clipStart < start+len)
3515 {
3516 // Test as also in WaveTrack::GetOne()
3517 if (clip->GetStretchRatio() != 1.0)
3518 return false;
3519
3520 // Clip sample region and Get/Put sample region overlap
3521 auto samplesToCopy =
3522 std::min( start+len - clipStart, clip->GetVisibleSampleCount() );
3523 auto startDelta = clipStart - start;
3524 decltype(startDelta) inclipDelta = 0;
3525 if (startDelta < 0)
3526 {
3527 inclipDelta = -startDelta; // make positive value
3528 samplesToCopy -= inclipDelta;
3529 // samplesToCopy is now either len or
3530 // (clipEnd - clipStart) - (start - clipStart)
3531 // == clipEnd - start > 0
3532 // samplesToCopy is not more than len
3533 //
3534 startDelta = 0;
3535 // startDelta is zero
3536 }
3537 else {
3538 // startDelta is nonnegative and less than len
3539 // samplesToCopy is positive and not more than len
3540 }
3541
3542 clip->SetSamples(0,
3543 buffer + startDelta.as_size_t() * SAMPLE_SIZE(format),
3544 format, inclipDelta, samplesToCopy.as_size_t(), effectiveFormat );
3545 clip->MarkChanged();
3546 }
3547 }
3548 return true;
3549}
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:52

References anonymous_namespace{ExportPCM.cpp}::format, GetTrack(), min(), and SAMPLE_SIZE.

Referenced by EffectAutoDuck::ApplyDuckFade(), WaveTrackSink::DoConsume(), WaveTrackMenuTable::OnSwapChannels(), EffectClickRemoval::ProcessOne(), EffectRepair::ProcessOne(), EffectTwoPassSimpleMono::ProcessOne(), EffectNormalize::ProcessOne(), and WaveTrack::ReverseOneClip().

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

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