Audacity 3.2.0
Public Types | Public Member Functions | Private Attributes | List of all members
AudioGraph::Task Struct Reference

Copies from a Source to a Sink, mediated by Buffers. More...

#include <AudioGraphTask.h>

Collaboration diagram for AudioGraph::Task:
[legend]

Public Types

enum class  Status { More , Done , Fail }
 

Public Member Functions

 Task (Source &source, Buffers &buffers, Sink &sink)
 
Status RunOnce ()
 Do an increment of the copy. More...
 
bool RunLoop ()
 Do the complete copy. More...
 

Private Attributes

SourcemSource
 
BuffersmBuffers
 
SinkmSink
 
bool mRanOnce { false }
 

Detailed Description

Copies from a Source to a Sink, mediated by Buffers.

Definition at line 24 of file AudioGraphTask.h.

Member Enumeration Documentation

◆ Status

enum class AudioGraph::Task::Status
strong
Enumerator
More 
Done 
Fail 

Definition at line 32 of file AudioGraphTask.h.

32{ More, Done, Fail };

Constructor & Destructor Documentation

◆ Task()

AudioGraph::Task::Task ( Source source,
Buffers buffers,
Sink sink 
)
Precondition
source.AcceptsBlockSize(buffers.BlockSize())
source.AcceptsBuffers(buffers)
sink.AcceptsBuffers(buffers)

Definition at line 21 of file AudioGraphTask.cpp.

22 : mSource{ source }, mBuffers{ buffers }, mSink{ sink }
23{
24 assert(source.AcceptsBlockSize(buffers.BlockSize()));
25 assert(source.AcceptsBuffers(buffers));
26 assert(sink.AcceptsBuffers(buffers));
27}
Buffers & mBuffers

References AudioGraph::Source::AcceptsBlockSize(), AudioGraph::Sink::AcceptsBuffers(), AudioGraph::Source::AcceptsBuffers(), and AudioGraph::Buffers::BlockSize().

Here is the call graph for this function:

Member Function Documentation

◆ RunLoop()

bool AudioGraph::Task::RunLoop ( )

Do the complete copy.

Returns
success
Precondition
mBuffers.Remaining() >= mBuffers.BlockSize()
Postcondition
result: result == Status::Fail || mBuffers.Remaining() >= mBuffers.BlockSize()

Definition at line 29 of file AudioGraphTask.cpp.

30{
31 // Satisfy invariant initially
33 Status status{};
34 do {
35 assert(mBuffers.Remaining() >= mBuffers.BlockSize());
36 status = RunOnce();
37 } while (status == Status::More);
38 return status == Status::Done;
39}
size_t BlockSize() const
size_t Remaining() const
void Rewind()
Reset positions to starts of buffers.
Status RunOnce()
Do an increment of the copy.

◆ RunOnce()

auto AudioGraph::Task::RunOnce ( )

Do an increment of the copy.

Definition at line 41 of file AudioGraphTask.cpp.

42{
43 const auto blockSize = mBuffers.BlockSize();
44 assert(mBuffers.Remaining() >= blockSize); // pre
45
46#ifndef NDEBUG
47 // Variable used only for a loop termination sanity check
48 std::optional<sampleCount> oldRemaining;
49 if (mRanOnce)
50 oldRemaining.emplace(mSource.Remaining());
51 // else Remaining() may not be meaningful
52#endif
53
54 if (auto oCurBlockSize = mSource.Acquire(mBuffers, blockSize)) {
55 const auto curBlockSize = *oCurBlockSize;
56#ifndef NDEBUG
57 mRanOnce = true;
58 const auto remaining = mSource.Remaining();
59 // Assert a post of Acquire which is part of proof of termination
60 assert(!mSource.Terminates() || !oldRemaining ||
61 *oldRemaining == remaining);
62 oldRemaining.emplace(remaining);
63 // Assert another post that guarantees progress (even if not terminating)
64 assert(blockSize == 0 || remaining == 0 || curBlockSize > 0);
65#endif
66 if (curBlockSize == 0)
67 // post (same as pre) obviously preserved
68 return Status::Done;
69
70 // post of source.Acquire() satisfies pre of sink.Release()
71 assert(curBlockSize <= blockSize);
72 if (!mSink.Release(mBuffers, curBlockSize))
73 return Status::Fail;
74
75 // This may break the post
76 mBuffers.Advance(curBlockSize);
77
78 // posts of source.Acquire() and source.Release()
79 // give termination guarantee
80 assert(mSource.Remaining() == 0 || curBlockSize > 0);
81 if (!mSource.Release())
82 return Status::Fail;
83#ifndef NDEBUG
84 // Assert a post of Release
85 assert(!mSource.Terminates() ||
86 mSource.Remaining() == remaining - curBlockSize);
87#endif
88
89 // Reestablish the post
91 return Status::Fail;
92 assert(mBuffers.Remaining() >= blockSize);
93
94 return Status::More;
95 }
96 else
97 return Status::Fail;
98}
void Advance(size_t count)
Move the positions.
virtual bool Acquire(Buffers &data)=0
Guarantee empty space in Buffers before they are written.
virtual bool Release(const Buffers &data, size_t curBlockSize)=0
Acknowledge receipt of data in Buffers, which caller may then Advance()
virtual sampleCount Remaining() const =0
Result includes any amount Acquired and not yet Released.
virtual bool Terminates() const
Needed only to make some postconditions assertable; defaults true.
virtual std::optional< size_t > Acquire(Buffers &data, size_t bound)=0
Occupy vacant space in Buffers with some data.
virtual bool Release()=0
Caller is done examining last Acquire()d positions.

Member Data Documentation

◆ mBuffers

Buffers& AudioGraph::Task::mBuffers
private

Definition at line 45 of file AudioGraphTask.h.

◆ mRanOnce

bool AudioGraph::Task::mRanOnce { false }
private

Definition at line 49 of file AudioGraphTask.h.

◆ mSink

Sink& AudioGraph::Task::mSink
private

Definition at line 46 of file AudioGraphTask.h.

◆ mSource

Source& AudioGraph::Task::mSource
private

Definition at line 44 of file AudioGraphTask.h.


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