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

#include <WaveTrackSink.h>

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

Public Member Functions

 WaveTrackSink (WaveTrack &left, WaveTrack *pRight, sampleCount start, bool isGenerator, bool isProcessor, sampleFormat effectiveFormat)
 
 ~WaveTrackSink () override
 
bool AcceptsBuffers (const Buffers &buffers) const override
 Accepts buffers only if there is at least one channel. More...
 
bool Acquire (Buffers &data) override
 Guarantee empty space in Buffers before they are written. More...
 
bool Release (const Buffers &data, size_t curBlockSize) override
 Acknowledge receipt of data in Buffers, which caller may then Advance() More...
 
void Flush (Buffers &data, double t0, double t1)
 
- Public Member Functions inherited from AudioGraph::Sink
virtual ~Sink ()
 
virtual bool AcceptsBuffers (const Buffers &buffers) const =0
 
virtual bool Acquire (Buffers &data)=0
 Guarantee empty space in Buffers before they are written. More...
 
virtual bool Release (const Buffers &data, size_t curBlockSize)=0
 Acknowledge receipt of data in Buffers, which caller may then Advance() More...
 

Private Member Functions

void DoConsume (Buffers &data)
 

Private Attributes

WaveTrackmLeft
 
WaveTrack *const mpRight
 
const std::shared_ptr< WaveTrackmGenLeft
 
const std::shared_ptr< WaveTrackmGenRight
 
const bool mIsProcessor
 
const sampleFormat mEffectiveFormat
 
sampleCount mOutPos
 

Additional Inherited Members

- Public Types inherited from AudioGraph::Sink
using Buffers = AudioGraph::Buffers
 

Detailed Description

Definition at line 25 of file WaveTrackSink.h.

Constructor & Destructor Documentation

◆ WaveTrackSink()

WaveTrackSink::WaveTrackSink ( WaveTrack left,
WaveTrack pRight,
sampleCount  start,
bool  isGenerator,
bool  isProcessor,
sampleFormat  effectiveFormat 
)
Parameters
effectiveFormatThis argument affects processors only, not generators

Definition at line 21 of file WaveTrackSink.cpp.

24 : mLeft{ left }, mpRight{ pRight }
25 , mGenLeft{ isGenerator ? left.EmptyCopy() : nullptr }
26 , mGenRight{ pRight && isGenerator ? pRight->EmptyCopy() : nullptr }
27 , mIsProcessor{ isProcessor }
28 , mEffectiveFormat{ effectiveFormat }
29 , mOutPos{ start }
30{
31}
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}, bool keepLink=true) const
Definition: WaveTrack.cpp:574
const sampleFormat mEffectiveFormat
Definition: WaveTrackSink.h:55
WaveTrack & mLeft
Definition: WaveTrackSink.h:51
const bool mIsProcessor
Definition: WaveTrackSink.h:54
sampleCount mOutPos
Definition: WaveTrackSink.h:57
const std::shared_ptr< WaveTrack > mGenLeft
Definition: WaveTrackSink.h:53
WaveTrack *const mpRight
Definition: WaveTrackSink.h:52
const std::shared_ptr< WaveTrack > mGenRight
Definition: WaveTrackSink.h:53

◆ ~WaveTrackSink()

WaveTrackSink::~WaveTrackSink ( )
overridedefault

Member Function Documentation

◆ AcceptsBuffers()

bool WaveTrackSink::AcceptsBuffers ( const Buffers buffers) const
overridevirtual

Accepts buffers only if there is at least one channel.

Implements AudioGraph::Sink.

Definition at line 35 of file WaveTrackSink.cpp.

36{
37 return buffers.Channels() > 0;
38}

References AudioGraph::Buffers::Channels().

Here is the call graph for this function:

◆ Acquire()

bool WaveTrackSink::Acquire ( Buffers data)
overridevirtual

Guarantee empty space in Buffers before they are written.

Returns
success
Postcondition
result: !result || data.BlockSize() <= data.Remaining()

Implements AudioGraph::Sink.

Definition at line 40 of file WaveTrackSink.cpp.

41{
42 if (data.BlockSize() <= data.Remaining()) {
43 // post is satisfied
44 }
45 else
46 // Output buffers have (mostly) filled
47 // (less than one block remains; maybe nonzero because of samples
48 // discarded for initial latency correction)
49 DoConsume(data);
50 return true;
51}
void DoConsume(Buffers &data)

References AudioGraph::Buffers::BlockSize(), DoConsume(), and AudioGraph::Buffers::Remaining().

Here is the call graph for this function:

◆ DoConsume()

void WaveTrackSink::DoConsume ( Buffers data)
private
Precondition
data.Channels() > 0
Postcondition
data.BlockSize() <= data.Remaining()

Definition at line 59 of file WaveTrackSink.cpp.

60{
61 // Satisfy pre of GetReadPosition()
62 assert(data.Channels() > 0);
63 const auto inputBufferCnt = data.Position();
64 if (inputBufferCnt > 0) {
65 // Some data still unwritten
66 if (mIsProcessor) {
67 mLeft.Set(data.GetReadPosition(0),
68 floatSample, mOutPos, inputBufferCnt, mEffectiveFormat);
69 if (mpRight)
70 mpRight->Set(data.GetReadPosition(1),
71 floatSample, mOutPos, inputBufferCnt, mEffectiveFormat);
72 }
73 else if (mGenLeft) {
74 mGenLeft->Append(data.GetReadPosition(0),
75 floatSample, inputBufferCnt);
76 if (mGenRight)
77 mGenRight->Append(data.GetReadPosition(1),
78 floatSample, inputBufferCnt);
79 }
80 // Satisfy post
81 data.Rewind();
82 // Bump to the next track position
83 mOutPos += inputBufferCnt;
84 }
85 else {
86 // Position is zero, therefore Remaining() is a positive multiple of
87 // block size
88 }
89 // assert the post
90 assert(data.BlockSize() <= data.Remaining());
91}
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Definition: WaveTrack.cpp:2002

References AudioGraph::Buffers::BlockSize(), AudioGraph::Buffers::Channels(), floatSample, AudioGraph::Buffers::GetReadPosition(), mEffectiveFormat, mGenLeft, mGenRight, mIsProcessor, mLeft, mOutPos, mpRight, AudioGraph::Buffers::Position(), AudioGraph::Buffers::Remaining(), AudioGraph::Buffers::Rewind(), and WaveTrack::Set().

Referenced by Acquire(), and Flush().

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

◆ Flush()

void WaveTrackSink::Flush ( Buffers data,
double  t0,
double  t1 
)

Precondition
data.Channels() > 0
Postcondition
data.BlockSize() <= data.Remaining()

Definition at line 93 of file WaveTrackSink.cpp.

94{
95 DoConsume(data);
96 if (mGenLeft) {
97 // Transfer the data from the temporary tracks to the actual ones
98 mGenLeft->Flush();
99 // mT1 gives us the NEW selection. We want to replace up to GetSel1().
100 PasteTimeWarper warper{ t1, t0 + mGenLeft->GetEndTime() };
101 mLeft.ClearAndPaste(t0, t1, mGenLeft.get(), true, true, &warper);
102 if (mGenRight) {
103 mGenRight->Flush();
104 mpRight->ClearAndPaste(t0, t1, mGenRight.get(), true, true, &warper);
105 }
106 }
107}
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
void ClearAndPaste(double t0, double t1, const Track *src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=NULL)
Definition: WaveTrack.cpp:710

References WaveTrack::ClearAndPaste(), DoConsume(), mGenLeft, mGenRight, mLeft, and mpRight.

Here is the call graph for this function:

◆ Release()

bool WaveTrackSink::Release ( const Buffers data,
size_t  curBlockSize 
)
overridevirtual

Acknowledge receipt of data in Buffers, which caller may then Advance()

Returns
success
Precondition
AcceptsBuffers(data)
curBlockSize <= data.BlockSize()

Implements AudioGraph::Sink.

Definition at line 53 of file WaveTrackSink.cpp.

54{
55 // May become non-trivial later
56 return true;
57}

Member Data Documentation

◆ mEffectiveFormat

const sampleFormat WaveTrackSink::mEffectiveFormat
private

Definition at line 55 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mGenLeft

const std::shared_ptr<WaveTrack> WaveTrackSink::mGenLeft
private

Definition at line 53 of file WaveTrackSink.h.

Referenced by DoConsume(), and Flush().

◆ mGenRight

const std::shared_ptr<WaveTrack> WaveTrackSink::mGenRight
private

Definition at line 53 of file WaveTrackSink.h.

Referenced by DoConsume(), and Flush().

◆ mIsProcessor

const bool WaveTrackSink::mIsProcessor
private

Definition at line 54 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mLeft

WaveTrack& WaveTrackSink::mLeft
private

Definition at line 51 of file WaveTrackSink.h.

Referenced by DoConsume(), and Flush().

◆ mOutPos

sampleCount WaveTrackSink::mOutPos
private

Definition at line 57 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mpRight

WaveTrack* const WaveTrackSink::mpRight
private

Definition at line 52 of file WaveTrackSink.h.

Referenced by DoConsume(), and Flush().


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