I am trying to write a program that processing a audio in real-time using delay, filter and other effects in C++. I am thinking of using a dynamic mic to pick up my voice. Is it fine to just plug the mic into the audio adaptor using a XLR to 1/8 inch cable, and connect to the audio input on Bela? Also, are there anything I should set-up to pass through the audio into a buffer and process it in the program? Really appreciate if anyone could give some advice!
Audio Input using a dynamic mic
I currently have a program that sending input to output using an inBuffer and an outBuffer with both size to 16 frames. Each sample is multiplied by an amplitude. I then applies a slider to try to control the amplitude, but Bela failed running it and giving me an error :
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
Aborted
make: *** [runide] Error 134
- Edited
#include <Bela.h>
#include <algorithm>
#include <libraries/Gui/Gui.h>
#include <libraries/GuiController/GuiController.h>
#include <libraries/Scope/Scope.h>
unsigned int gAudioChannelNum;
float gInBuffer[16];
float gOutBuffer[16];
Scope scope;
Gui gui;
GuiController controller;
bool setup(BelaContext *context, void *userData)
{
//Check input and output number
if(context->audioInChannels != context->audioOutChannels){
printf("Input not mathcing output.\n");
}
gAudioChannelNum = std::min(context->audioInChannels, context->audioOutChannels);
return true;
//Set up scope
scope.setup(0, context->audioSampleRate);
gui.setup(context->projectName);
//Set up Gui
controller.setup(&gui, "EP353");
controller.addSlider("Amplitude", 5.0, 0.0, 20.0, 0.0);//Amplitude Slider
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->audioFrames; n++){
for(unsigned int ch = 0; ch < gAudioChannelNum; ch++){
float gAmp = controller.getSliderValue(0);
gInBuffer[n] = audioRead(context, n ,ch);
gOutBuffer[n] = gInBuffer[n] * gAmp;
audioWrite(context, n, ch, gOutBuffer[n]);
scope.log(gOutBuffer[n]);
}
}
}
void cleanup(BelaContext *context, void *userData)
{
}
- Edited
You are returning from setup() before calling controller.setup() and controller.addSlider() , so it fails with that error in render() when calling controller.getSliderValue(0)
.
Regarding connecting the microphone, if you could plug the + and - from the xlr into the L and R inputs and then take the difference between the two in render(). You can also increase the gain in the IDE settings, setting it to the same value for both channels
giuliomoro Hi giuliomoro. Thank you for the reply! The problem is solved. By saying taking the differences, do you mean the differences of the amplitude of the L and R channel? Also I am not sure if I am able to do that with the current wire? Thank you very much!
The wiring may be ok.
This line
gInBuffer[n] = audioRead(context, n ,ch);
Could be replaced with
gInBuffer[n] = audioRead(context, n, 0) - audioRead(context, n, 1);
this makes it a mono signal, but the signal to noise ratio should be much better.
Thank you very much! This really helps!