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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TrackWaveInputDeviceNode.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
11
12namespace tracktion { inline namespace engine
13{
14
15TrackWaveInputDeviceNode::TrackWaveInputDeviceNode (ProcessState& processState_, WaveInputDevice& owner, std::unique_ptr<Node> inputNode,
16 bool copyInputsToOutputs_)
17 : TracktionEngineNode (processState_),
18 waveInputDevice (owner), input (std::move (inputNode)), copyInputsToOutputs (copyInputsToOutputs_)
19{
20 jassert (waveInputDevice.isTrackDevice());
21
22 if (copyInputsToOutputs)
23 setOptimisations ({ tracktion::graph::ClearBuffers::no,
24 tracktion::graph::AllocateAudioBuffer::no });
25}
26
27std::vector<tracktion::graph::Node*> TrackWaveInputDeviceNode::getDirectInputNodes()
28{
29 return { input.get() };
30}
31
32tracktion::graph::NodeProperties TrackWaveInputDeviceNode::getNodeProperties()
33{
34 return input->getNodeProperties();
35}
36
37void TrackWaveInputDeviceNode::prepareToPlay (const tracktion::graph::PlaybackInitialisationInfo& info)
38{
39 sampleRate = info.sampleRate;
40
41 auto latencyUpToThisPoint = getNodeProperties().latencyNumSamples;
42 const auto latencyUpToThisPointS = TimeDuration::fromSamples (latencyUpToThisPoint, sampleRate);
43 offset = -latencyUpToThisPointS;
44}
45
46bool TrackWaveInputDeviceNode::isReadyToProcess()
47{
48 return input->hasProcessed();
49}
50
51void TrackWaveInputDeviceNode::process (ProcessContext& pc)
52{
53 SCOPED_REALTIME_CHECK
54
55 // Pass on input to output
56 auto sourceBuffers = input->getProcessedOutput();
57
58 if (copyInputsToOutputs)
59 {
60 setAudioOutput (input.get(), sourceBuffers.audio);
61 pc.buffers.midi.copyFrom (sourceBuffers.midi);
62 }
63
64 // And pass audio to device
65 if (auto numChans = juce::jmin (2u, sourceBuffers.audio.getNumChannels()))
66 {
67 const float* chans[3] = { sourceBuffers.audio.getChannel(0).data.data,
68 numChans > 1 ? sourceBuffers.audio.getChannel(1).data.data
69 : nullptr,
70 nullptr };
71
72 const auto streamPos = TimePosition::fromSamples (getReferenceSampleRange().getStart(), sampleRate);
73 waveInputDevice.consumeNextAudioBlock (chans, (int) numChans, (int) sourceBuffers.audio.getNumFrames(),
74 (streamPos + offset).inSeconds());
75 }
76}
77
78}} // namespace tracktion { inline namespace engine
Struct to describe a single iteration of a process call.
#define jassert(expression)
T move(T... args)
constexpr Type jmin(Type a, Type b)
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...