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 (WaveChannel &left, WaveChannel *pRight, WaveTrack *pGenerated, sampleCount start, 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)
 
bool IsOk () const
 Whether any errors have occurred in writing data. More...
 
- 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

WaveChannelmLeft
 
WaveChannel *const mpRight
 
WaveTrack *const mpGenerated
 
WaveChannel *const mGenLeft
 
WaveChannel *const mGenRight
 
const bool mIsProcessor
 
const sampleFormat mEffectiveFormat
 
sampleCount mOutPos
 
bool mOk { true }
 

Additional Inherited Members

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

Detailed Description

Definition at line 27 of file WaveTrackSink.h.

Constructor & Destructor Documentation

◆ WaveTrackSink()

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

Definition at line 20 of file WaveTrackSink.cpp.

24 : mLeft{ left }, mpRight{ pRight }
25 , mpGenerated{ pGenerated }
26 , mGenLeft{ pGenerated ? (*pGenerated->Channels().begin()).get() : nullptr }
27 , mGenRight{ pRight && pGenerated
28 ? (*pGenerated->Channels().rbegin()).get() : nullptr }
29 , mIsProcessor{ isProcessor }
30 , mEffectiveFormat{ effectiveFormat }
31 , mOutPos{ start }
32{
33}
auto Channels()
Definition: WaveTrack.h:263
WaveChannel & mLeft
Definition: WaveTrackSink.h:56
const sampleFormat mEffectiveFormat
Definition: WaveTrackSink.h:62
const bool mIsProcessor
Definition: WaveTrackSink.h:61
sampleCount mOutPos
Definition: WaveTrackSink.h:64
WaveChannel *const mGenRight
Definition: WaveTrackSink.h:60
WaveTrack *const mpGenerated
Definition: WaveTrackSink.h:58
WaveChannel *const mpRight
Definition: WaveTrackSink.h:57
WaveChannel *const mGenLeft
Definition: WaveTrackSink.h:59

◆ ~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 37 of file WaveTrackSink.cpp.

38{
39 return buffers.Channels() > 0;
40}

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 42 of file WaveTrackSink.cpp.

43{
44 if (data.BlockSize() <= data.Remaining()) {
45 // post is satisfied
46 }
47 else
48 // Output buffers have (mostly) filled
49 // (less than one block remains; maybe nonzero because of samples
50 // discarded for initial latency correction)
51 DoConsume(data);
52 return IsOk();
53}
void DoConsume(Buffers &data)
bool IsOk() const
Whether any errors have occurred in writing data.
Definition: WaveTrackSink.h:47

References AudioGraph::Buffers::BlockSize(), DoConsume(), IsOk(), 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 61 of file WaveTrackSink.cpp.

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

References WaveChannel::Append(), AudioGraph::Buffers::BlockSize(), AudioGraph::Buffers::Channels(), floatSample, AudioGraph::Buffers::GetReadPosition(), mEffectiveFormat, mGenLeft, mGenRight, mIsProcessor, mLeft, mOk, mOutPos, mpRight, AudioGraph::Buffers::Position(), AudioGraph::Buffers::Remaining(), AudioGraph::Buffers::Rewind(), and WaveChannel::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)

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

Definition at line 97 of file WaveTrackSink.cpp.

98{
99 DoConsume(data);
100 if (mpGenerated)
102}
void Flush() override
Definition: WaveTrack.cpp:2315

References DoConsume(), WaveTrack::Flush(), and mpGenerated.

Here is the call graph for this function:

◆ IsOk()

bool WaveTrackSink::IsOk ( ) const
inline

Whether any errors have occurred in writing data.

Definition at line 47 of file WaveTrackSink.h.

47{ return mOk; }

Referenced by Acquire().

Here is the caller 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 55 of file WaveTrackSink.cpp.

56{
57 // May become non-trivial later
58 return true;
59}

Member Data Documentation

◆ mEffectiveFormat

const sampleFormat WaveTrackSink::mEffectiveFormat
private

Definition at line 62 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mGenLeft

WaveChannel* const WaveTrackSink::mGenLeft
private

Definition at line 59 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mGenRight

WaveChannel* const WaveTrackSink::mGenRight
private

Definition at line 60 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mIsProcessor

const bool WaveTrackSink::mIsProcessor
private

Definition at line 61 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mLeft

WaveChannel& WaveTrackSink::mLeft
private

Definition at line 56 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mOk

bool WaveTrackSink::mOk { true }
private

Definition at line 65 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mOutPos

sampleCount WaveTrackSink::mOutPos
private

Definition at line 64 of file WaveTrackSink.h.

Referenced by DoConsume().

◆ mpGenerated

WaveTrack* const WaveTrackSink::mpGenerated
private

Definition at line 58 of file WaveTrackSink.h.

Referenced by Flush().

◆ mpRight

WaveChannel* const WaveTrackSink::mpRight
private

Definition at line 57 of file WaveTrackSink.h.

Referenced by DoConsume().


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