Hello,
I have the following situation where I need your help. I have a standalone app, which uses the ChannelRemappingAudioSource to route channels into Custom Channel Strips. A channelstrip is a class which holds a transportsource for playback and a self written audiorecorder from the tutorial. I use Foleys Audiometer to show the level.
Now the situation is: I can’t get the input from the interface (RME Fireface) to be measured correctly. My first approach was to read the samples directly from the Recorder since it’s an AudioIODevice and I have direct access to the inputsamples.
if (activeWriter.load() != nullptr)
{
if (!stereo_ && input_ != -1)
{
auto data = inputChannelData[input_];
// Create a buffer with 2 channels
buffer_.reset(new juce::AudioBuffer<float>(2, numSamples));
buffer_->clear();
// Copy the mono data to both channels
buffer_->copyFrom(0, 0, data, numSamples);
buffer_->copyFrom(1, 0, data, numSamples);
// No gain reduction for mono
buffer_->applyGain(gain_);
activeWriter.load()->write(buffer_->getArrayOfReadPointers(), numSamples);
// levelMeterSource_.measureBlock(*buffer_);
nextSampleNum += numSamples;
}
else if (input_ != -1)
{
int channel = input_;
if (channel % 2 != 0)
{
auto dataL = inputChannelData[input_ - 1];
auto dataR = inputChannelData[input_];
buffer_.reset(new juce::AudioBuffer<float>(2, numSamples));
buffer_->clear();
buffer_->copyFrom(0, 0, dataL, numSamples);
buffer_->copyFrom(1, 0, dataR, numSamples);
buffer_->applyGain(gain_);
activeWriter.load()->write(buffer_->getArrayOfReadPointers(), numSamples);
// levelMeterSource_.measureBlock(*buffer_);
nextSampleNum += numSamples;
}
else
{
auto dataL = inputChannelData[input_];
auto dataR = inputChannelData[input_ + 1];
buffer_.reset(new juce::AudioBuffer<float>(2, numSamples));
buffer_->clear();
buffer_->copyFrom(0, 0, dataL, numSamples);
buffer_->copyFrom(1, 0, dataR, numSamples);
buffer_->applyGain(gain_);
activeWriter.load()->write(buffer_->getArrayOfReadPointers(), numSamples);
//if (s > 0.01f)
// levelMeterSource_.measureBlock(*buffer_);
nextSampleNum += numSamples;
}
}
}
else
{
int channel = input_;
if (!stereo_ && input_ != -1)
{
auto data = inputChannelData[input_];
buffer_.reset(new juce::AudioBuffer<float>(2, numSamples)); // Allocate for stereo
buffer_->clear();
// Copy mono data to both channels
if (data != nullptr)
{
buffer_->copyFrom(0, 0, data, numSamples);
buffer_->copyFrom(1, 0, data, numSamples);
}
buffer_->applyGain(gain_);
// levelMeterSource_.measureBlock(*buffer_);
nextSampleNum += numSamples;
}
else if (channel % 2 != 0 && channel != -1)
{
auto dataL = inputChannelData[input_ - 1];
auto dataR = inputChannelData[input_];
buffer_.reset(new juce::AudioBuffer<float>(2, numSamples));
buffer_->clear();
if (dataL != nullptr)
buffer_->copyFrom(0, 0, dataL, numSamples);
if (dataR != nullptr)
buffer_->copyFrom(1, 0, dataR, numSamples);
buffer_->applyGain(gain_);
//if (s > 0.01f)
// levelMeterSource_.measureBlock(*buffer_);
nextSampleNum += numSamples;
}
else if (channel != -1)
{
auto dataL = inputChannelData[input_];
auto dataR = inputChannelData[input_ + 1];
buffer_.reset(new juce::AudioBuffer<float>(2, numSamples));
buffer_->clear();
if (dataL != nullptr)
buffer_->copyFrom(0, 0, dataL, numSamples);
if (dataR != nullptr)
buffer_->copyFrom(1, 0, dataR, numSamples);
buffer_->applyGain(gain_);
// levelMeterSource_.measureBlock(*buffer_);
nextSampleNum += numSamples;
}
}
But this approach was showing always a litte input. I don’t need to measure the preamp noise. I assume it’s the channel noise because Totalmix shows also a slight inputmeasure at around -77 dBFs. Usually nothing to really worry about, but I would worry if I always would see it in my Inputmeter. @daniel I couldn’t find a function to smooth the meter but on the other hand, I thought why should be? It actually does the job, it’s only that it shows too much of the noise.
Then I tried another approach. I thought since I have my own Slot Channelclass, I can measure the input after the ChannelRemappingAudioThing by just reading the bufferToFill.buffer->getWritePointer():
for (int channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
{
inputBuffer_->copyFrom(channel, bufferToFill.startSample, bufferToFill.buffer->getWritePointer(channel), bufferToFill.numSamples);
}
inputMeterSource_.measureBlock(*inputBuffer_);
Also tried with ReadPointer instead of writePointer, but strangely, results in the same metering. It shows kind of the same level as the outputmeter shows, so I assume it might be directly the output signal. I physically looped an output into one of the inputs of the fireface. Interestingly the Inputmeter shows Signal even though there is no input signal at the interface.
Then I thought, it could be the CRAS and that I might do a wrong routing. I double checked that and tried also to switch source and destination channel, but it was right, how it was.
And now, I have no more Idea how to access my audiointerface Inputs with only using AudioSources. This snipped is the last thing I tried so far:
void Slot::getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill)
{
if (readerSource == nullptr)
{
bufferToFill.clearActiveBufferRegion();
return;
}
juce::AudioBuffer<float> inBuffer(bufferToFill.buffer->getArrayOfWritePointers(), bufferToFill.buffer->getNumChannels(), bufferToFill.numSamples);
juce::AudioSourceChannelInfo inputInfo(inBuffer);
audioRecorder_->getNextAudioBlock(inputInfo);
inputMeterSource_.measureBlock(*inputInfo.buffer);
// Get the audio block from the transport source
if (channelNode_.hasProperty(Identifiers::outputGain))
{
float outputGain = channelNode_[Identifiers::outputGain];
bufferToFill.buffer->applyGain(outputGain);
}
transportSource_.getNextAudioBlock(bufferToFill);
outputMeterSource_.measureBlock(*bufferToFill.buffer);
}
My Idea behind it:
MainComponent = Controller. It has power over ChannelRemappingAudioSources and maps the channels according to user actions. CRAS send buffer to Slot internal as I understand, so I only giv bufferToFill in CRAS, CRAS Maps, Slot receives, Slot passes Input to AudioRecorder (AudioSource) and passes buffer afterwords to transportSource which can play a file. AudioRecorder receives bufferToFill and writes that Buffer to a file. The Transport Source is from juce, so I just create an Instance of it in the Slot and pass the buffer. The Transportssource works fine and the mapping also. The AudioRecorder records only burst noise. Like an unflashed buffer, but how can I clear a buffer, if I want to record the Audiointerface Input, which in my understanding must than already be in the buffer.
If the bufferToFill would really hold Audio Interface Input Channel Data it must be already in there, otherwise I think I missunderstood how it’s ment with InBuffer and Outbuffer from this tutorial I followed:
https://docs.juce.com/master/tutorial_processing_audio_input.html
Actually that tutorial gave me the idea to change my code from the AudioIODevice AudioRecorder to an AudioSource AudioRecorder but I’m now a bit afraid that I just wasted my time and missunderstood something completely. I will revert my code now to use AudioIoDevice for the AudioRecorder and leave the AudioSource to the Transportsource for output. If somebody understands my text and my situation and has a solution for using both AudioSources, I would be super happy and I would learn a lot. So thanks in advance and sorry for the long message.