tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_AudioNode.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14AudioNode::AudioNode()
15{
16}
17
18AudioNode::~AudioNode()
19{
20}
21
22void AudioNode::callRenderAdding (const AudioRenderContext& rc)
23{
24 rc.clearAll();
25 renderAdding (rc);
26}
27
28void AudioNode::callRenderOverForMidi (const AudioRenderContext& rc)
29{
30 if (rc.bufferForMidiMessages == nullptr || rc.bufferForMidiMessages->isEmpty())
31 {
32 renderOver (rc);
33 }
34 else
35 {
36 MidiMessageArray temp;
37
38 AudioRenderContext rc2 (rc);
39 rc2.bufferForMidiMessages = &temp;
40
41 renderOver (rc2);
42
43 rc.bufferForMidiMessages->mergeFromAndClear (temp);
44 }
45}
46
47void AudioNode::callRenderOver (const AudioRenderContext& rc)
48{
49 if (rc.destBuffer != nullptr)
50 {
51 AudioScratchBuffer scratch (rc.destBuffer->getNumChannels(), rc.bufferNumSamples);
52
53 AudioRenderContext rc2 (rc);
54 rc2.destBuffer = &scratch.buffer;
55 rc2.bufferStartSample = 0;
56
57 callRenderOverForMidi (rc2);
58
59 for (int i = rc.destBuffer->getNumChannels(); --i >= 0;)
60 rc.destBuffer->addFrom (i, rc.bufferStartSample, *rc2.destBuffer, i, 0, rc.bufferNumSamples);
61 }
62 else
63 {
64 callRenderOverForMidi (rc);
65 }
66}
67
73
75{
76 if (destBuffer != nullptr)
77 tracktion::engine::addAntiDenormalisationNoise (*destBuffer, bufferStartSample, bufferNumSamples);
78}
79
81{
82 if (bufferForMidiMessages != nullptr)
83 bufferForMidiMessages->clear();
84}
85
86void AudioRenderContext::clearAll() const noexcept
87{
90}
91
93{
94 return playhead.streamTimeToEditWindow (streamTime);
95}
96
97//==============================================================================
98SingleInputAudioNode::SingleInputAudioNode (AudioNode* n) : input (n)
99{
100 jassert (input != nullptr);
101}
102
103void SingleInputAudioNode::getAudioNodeProperties (AudioNodeProperties& info)
104{
105 input->getAudioNodeProperties (info);
106}
107
109{
110 input->prepareAudioNodeToPlay (info);
111}
112
113bool SingleInputAudioNode::purgeSubNodes (bool keepAudio, bool keepMidi)
114{
115 return input->purgeSubNodes (keepAudio, keepMidi);
116}
117
119{
120 input->releaseAudioNodeResources();
121}
122
123void SingleInputAudioNode::visitNodes (const VisitorFn& v)
124{
125 v (*this);
126 input->visitNodes (v);
127}
128
129Plugin::Ptr SingleInputAudioNode::getPlugin() const
130{
131 return input->getPlugin();
132}
133
134void SingleInputAudioNode::prepareForNextBlock (const AudioRenderContext& rc)
135{
136 input->prepareForNextBlock (rc);
137}
138
139bool SingleInputAudioNode::isReadyToRender()
140{
141 return input->isReadyToRender();
142}
143
144void SingleInputAudioNode::renderOver (const AudioRenderContext& rc)
145{
146 input->renderOver (rc);
147}
148
149void SingleInputAudioNode::renderAdding (const AudioRenderContext& rc)
150{
151 input->renderAdding (rc);
152}
153
154}} // namespace tracktion { inline namespace engine
void clear() noexcept
Base class for nodes in an audio playback graph.
void prepareAudioNodeToPlay(const PlaybackInitialisationInfo &) override
tells the node to initialise itself ready for playing from the given time.
void releaseAudioNodeResources() override
tells the node that play has stopped, and it can free up anything it no longer needs.
bool purgeSubNodes(bool keepAudio, bool keepMidi) override
Tells the node to delete any sub-nodes that don't produce the required type of output.
#define jassert(expression)
Holds some really basic properties of a node.
Passed into AudioNodes when they are being initialised, to give them useful contextual information th...
int bufferNumSamples
The number of samples to write into the audio buffer.
void addAntiDenormalisationNoise() const noexcept
Applies low-level noise to the audio buffer.
MidiMessageArray * bufferForMidiMessages
A buffer of MIDI events to process.
void clearAll() const noexcept
Clears the active section of all channels in the audio and MIDI buffers.
int bufferStartSample
The index of the start point in the audio buffer from which data must be written.
PlayHead & playhead
The playhead provides information about current time, tempo etc at the block being rendered.
juce::AudioBuffer< float > * destBuffer
The target audio buffer which needs to be filled.
void clearAudioBuffer() const noexcept
Clears the active section of all channels in the audio buffer.
PlayHead::EditTimeWindow getEditTime() const
Returns the section of the edit that needs to be rendered by this block.
void clearMidiBuffer() const noexcept
Clears the active section of the MIDI buffer.
legacy::EditTimeRange streamTime
The time window which needs to be rendered into the current block.