Audacity 3.2.0
WaveTrackSink.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file WaveTrackSink.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson
9 Martyn Shaw
10
11 Paul Licameli split from PerTrackEffect.cpp
12
13**********************************************************************/
14#include "WaveTrackSink.h"
15
16#include "AudioGraphBuffers.h"
17#include "WaveTrack.h"
18#include <cassert>
19
21 WaveTrack *pGenerated,
22 sampleCount start, bool isProcessor,
23 sampleFormat effectiveFormat
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}
34
36
37bool WaveTrackSink::AcceptsBuffers(const Buffers &buffers) const
38{
39 return buffers.Channels() > 0;
40}
41
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}
54
55bool WaveTrackSink::Release(const Buffers &, size_t)
56{
57 // May become non-trivial later
58 return true;
59}
60
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 &&
71 floatSample, mOutPos, inputBufferCnt, mEffectiveFormat);
72 if (mpRight)
73 mOk = mOk &&
75 floatSample, mOutPos, inputBufferCnt, mEffectiveFormat);
76 }
77 else if (mGenLeft) {
79 floatSample, inputBufferCnt );
80 if (mGenRight)
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}
96
98{
99 DoConsume(data);
100 if (mpGenerated)
102}
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
Accumulates (non-interleaved) data during effect processing.
size_t BlockSize() const
size_t Position() const
size_t Remaining() const
void Rewind()
Reset positions to starts of buffers.
unsigned Channels() const
constSamplePtr GetReadPosition(unsigned iChannel) const
Get accumulated data for one channel.
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
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
void Flush() override
Definition: WaveTrack.cpp:2315
WaveChannel & mLeft
Definition: WaveTrackSink.h:56
const sampleFormat mEffectiveFormat
Definition: WaveTrackSink.h:62
~WaveTrackSink() override
WaveTrackSink(WaveChannel &left, WaveChannel *pRight, WaveTrack *pGenerated, sampleCount start, bool isProcessor, sampleFormat effectiveFormat)
void DoConsume(Buffers &data)
bool Acquire(Buffers &data) override
Guarantee empty space in Buffers before they are written.
bool Release(const Buffers &data, size_t curBlockSize) override
Acknowledge receipt of data in Buffers, which caller may then Advance()
bool IsOk() const
Whether any errors have occurred in writing data.
Definition: WaveTrackSink.h:47
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
bool AcceptsBuffers(const Buffers &buffers) const override
Accepts buffers only if there is at least one channel.
WaveChannel *const mpRight
Definition: WaveTrackSink.h:57
void Flush(Buffers &data)
WaveChannel *const mGenLeft
Definition: WaveTrackSink.h:59
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101