Skip to content

Commit 1f5cb7d

Browse files
committed
Fix audio node inconsistencies and allow playback of one channel
1 parent d6e4da5 commit 1f5cb7d

4 files changed

Lines changed: 29 additions & 26 deletions

File tree

Source/Processors/AudioNode/AudioNode.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ AudioNode::AudioNode()
3131

3232
settings.numInputs = 4096;
3333
settings.numOutputs = 2;
34+
nextAvailableChannel = 2;
3435

35-
// 128 inputs, 2 outputs (left and right channel)
36-
setPlayConfigDetails(getNumInputs(), getNumOutputs(), 44100.0, 128);
37-
38-
nextAvailableChannel = 2; // keep first two channels empty
36+
updatePlaybackBuffer();
3937

4038
tempBuffer = new AudioSampleBuffer(16, 1024);
4139

@@ -57,12 +55,18 @@ AudioProcessorEditor* AudioNode::createEditor()
5755

5856
void AudioNode::resetConnections()
5957
{
60-
61-
nextAvailableChannel = 2; // start connections at channel 2
62-
wasConnected = false;
58+
settings.numInputs = 2; // "dummy" inputs that are actually just outputs
59+
nextAvailableChannel = 2;
6360

6461
dataChannelArray.clear();
6562

63+
updatePlaybackBuffer();
64+
}
65+
66+
void AudioNode::registerProcessor(const GenericProcessor* sourceNode)
67+
{
68+
settings.numInputs += sourceNode->getNumOutputs();
69+
updatePlaybackBuffer();
6670
}
6771

6872
void AudioNode::updateBufferSize()
@@ -94,7 +98,7 @@ void AudioNode::setChannel(const DataChannel* ch)
9498
void AudioNode::setChannelStatus(const DataChannel* chan, bool status)
9599
{
96100

97-
setChannel(chan); // add 2 to account for 2 output channels
101+
setChannel(chan);
98102

99103
enableCurrentChannel(status);
100104

@@ -116,12 +120,8 @@ void AudioNode::enableCurrentChannel(bool state)
116120

117121
void AudioNode::addInputChannel(GenericProcessor* sourceNode, int chan)
118122
{
119-
120-
121123
int channelIndex = getNextChannel(false);
122124

123-
//setPlayConfigDetails(channelIndex+1,0,44100.0,128);
124-
125125
auto dataChannel = sourceNode->getDataChannel(chan);
126126
auto dataChannelCopy = new DataChannel(*dataChannel);
127127
dataChannelCopy->setMonitored(dataChannel->isMonitored());
@@ -132,7 +132,7 @@ void AudioNode::addInputChannel(GenericProcessor* sourceNode, int chan)
132132

133133
void AudioNode::updatePlaybackBuffer()
134134
{
135-
setPlayConfigDetails(dataChannelArray.size(), 0, 44100.0, 128);
135+
setPlayConfigDetails(getNumInputs(), 2, 44100.0, 128);
136136
}
137137

138138
void AudioNode::setParameter(int parameterIndex, float newValue)
@@ -256,12 +256,13 @@ void AudioNode::process(AudioSampleBuffer& buffer)
256256
AudioSampleBuffer* overflowBuffer;
257257
AudioSampleBuffer* backupBuffer;
258258

259-
if (dataChannelArray.size() > 0) // we have some channels
259+
int nInputs = dataChannelArray.size();
260+
if (nInputs > 0) // we have some channels
260261
{
261262

262263
// tempBuffer->clear();
263264

264-
for (int i = 0; i < buffer.getNumChannels()-2; i++) // cycle through them all
265+
for (int i = 0; i < nInputs; i++) // cycle through them all
265266
{
266267

267268
if (dataChannelArray[i]->isMonitored())

Source/Processors/AudioNode/AudioNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class AudioNode : public GenericProcessor
129129
//Called by ProcessorGraph
130130
void updateRecordChannelIndexes();
131131

132+
// expand # of inputs for each connected processor
133+
void registerProcessor(const GenericProcessor* sourceNode);
134+
132135
private:
133136
void recreateBuffers();
134137

Source/Processors/GenericProcessor/GenericProcessor.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,15 @@ void GenericProcessor::update()
364364

365365
for (int i = 0; i < dataChannelArray.size(); i++)
366366
{
367-
if (i < m_recordStatus.size())
368-
dataChannelArray[i]->setRecordState(m_recordStatus[i]);
369-
else
370-
if (isSource())
371-
dataChannelArray[i]->setRecordState(true);
367+
if (i < m_recordStatus.size())
368+
{
369+
dataChannelArray[i]->setRecordState(m_recordStatus[i]);
370+
dataChannelArray[i]->setMonitored(m_monitorStatus[i]);
371+
}
372+
else if (isSource())
373+
{
374+
dataChannelArray[i]->setRecordState(true);
375+
}
372376
}
373377
}
374378

Source/Processors/ProcessorGraph/ProcessorGraph.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,14 @@ void ProcessorGraph::connectProcessorToAudioAndRecordNodes(GenericProcessor* sou
476476
if (source == nullptr)
477477
return;
478478

479+
getAudioNode()->registerProcessor(source);
479480
getRecordNode()->registerProcessor(source);
480481

481482
for (int chan = 0; chan < source->getNumOutputs(); chan++)
482483
{
483484

484485
getAudioNode()->addInputChannel(source, chan);
485486

486-
// THIS IS A HACK TO MAKE SURE AUDIO NODE KNOWS WHAT THE SAMPLE RATE SHOULD BE
487-
// IT CAN CAUSE PROBLEMS IF THE SAMPLE RATE VARIES ACROSS PROCESSORS
488-
489-
//TODO: See if this causes problems with the newer architectures
490-
//getAudioNode()->settings.sampleRate = source->getSampleRate();
491-
492487
addConnection(source->getNodeId(), // sourceNodeID
493488
chan, // sourceNodeChannelIndex
494489
AUDIO_NODE_ID, // destNodeID

0 commit comments

Comments
 (0)