I want to perform some real-time audio processing on my audio input and output it to my speakers. However, when I try to get the device from the device manager and print out the name, I only find that my speakers are selected. How would I go about getting an object that points to my microphone? I am windows running Visual Studio 2022. Code below:
auto* InputDevice = deviceManager.getCurrentAudioDevice();
auto* OutputDevice = deviceManager.getCurrentAudioDevice();
/*DBG(InputDevice->getName() + "\n");
DBG(OutputDevice->getName() + "\n");*/
auto activeInputChannels = InputDevice->getActiveInputChannels();
auto activeOutputChannels = OutputDevice->getActiveOutputChannels();
auto maxInputChannels = activeInputChannels.getHighestBit() + 1;
auto maxOutputChannels = activeOutputChannels.getHighestBit() + 1;
auto buffer = bufferToFill.buffer;
for (auto channel = 0; channel < maxOutputChannels; ++channel) {
//in case we have no input channels due to permissions OR if the active output channels isn't outputting anything
if ((!activeOutputChannels[channel]) || maxInputChannels == 0) {
DBG("failed to get inputs\n");
buffer->clear(channel, bufferToFill.startSample, bufferToFill.numSamples);
}
else {
auto actualInputChannel = channel % maxInputChannels;
if (!activeInputChannels[channel]) {
DBG("input not active\n");
buffer->clear(channel, bufferToFill.startSample, bufferToFill.numSamples);
}
else {
auto* inBuffer = buffer->getReadPointer(actualInputChannel, bufferToFill.startSample);
auto* outBuffer = buffer->getWritePointer(channel, bufferToFill.startSample);
int numSamplesToProcess = 10;
for (auto sample = 0; sample < bufferToFill.numSamples; ++sample) {
int loudness = juce::Decibels::gainToDecibels(buffer->getRMSLevel(channel, sample, numSamplesToProcess));
auto noise = (random.nextFloat() * 2.0f) - 1.0f;
outBuffer[sample] = inBuffer[sample] + (inBuffer[sample] * noise * 2);
}
}
}
