Hi there,
I currently have a microphone array consisting of eight microphones. Here is a link for more details on the microphones that I am currently using 9https://www.amazon.co.uk/Omni-directional-Microphone-Condenser-Camcorder-Smartphone/dp/B07F37J6ZL)
It’s essentially two lavalier microphones that are powered by one module that in turn has one TRRS connection. This is then plugged into the audio inputs on the Bela CTAG Beast using the 3.5mm stereo adapters.
The current issue I’m having is that when recording, if I’m only using microphone 1. The audio will record to channel 1 but also will appear on channel 2. This is probably due to the TRRS connection with the 3.5mm stereo adapter. However I basically require just for microphone 1 recordings to appear only on channel 1, then microphone 2 on channel 2 and so on. I was wondering if there is a way to achieve this by modifying the current code? Maybe by splitting it to left (microphone 1) and right (microphone 2) with the same pattern for all the other channels?
I’ve also attached a screen grab to explain what I mean a bit more clearly.
My current code that I’ve written and have been using is outlined below:
#include <Bela.h>
#include <libraries/Pipe/Pipe.h>
#include <libraries/sndfile/sndfile.h>
#include <libraries/WriteFile/WriteFile.h>
//const char* path = "./audioCh.wav";
const char* path = "/mnt/usb/audioCh.wav";
SNDFILE * outfile2;
char originalFilename[] = "/mnt/usb/audioCh.wav";
char* uniqueFilename = WriteFile::generateUniqueFilename(originalFilename);
//Audio
AuxiliaryTask gFillBufferTask;
SNDFILE * outfile;
unsigned int gAudioFrames;
unsigned int gAudioInChannels;
float gAudioSampleRate;
Pipe gPipe;
//Open files audio
void openFile() {
SF_INFO sfinfo;
sfinfo.channels = gAudioInChannels;
sfinfo.samplerate = gAudioSampleRate;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
//outfile = sf_open(path, SFM_WRITE, &sfinfo);
outfile2 = sf_open(uniqueFilename, SFM_WRITE, &sfinfo);
}
//close audio files
void closeFile() {
sf_write_sync(outfile2);
sf_close(outfile2);
//sf_write_sync(outfile);
//sf_close(outfile);
printf(".wav file written and closed\n");
}
void writeBuffer(void*) {
unsigned int numItems = gAudioFrames * gAudioInChannels;
float buf[numItems];
int ret;
while((ret = gPipe.readNonRt(buf, numItems) ) > 0)
{
sf_write_float(outfile2, &buf[0], ret);
}
}
bool setup(BelaContext* context, void* arg)
{
//setup audio frames and channels
gAudioSampleRate = context->audioSampleRate;
gAudioFrames = context->audioFrames;
gAudioInChannels = context->audioInChannels;
gPipe.setup("sndfile-write", 65536, false, false);
openFile();
if((gFillBufferTask = Bela_createAuxiliaryTask(&writeBuffer, 90, "writeBuffer")) == 0) {
return false;
}
return true;
}
void render(BelaContext* context, void* arg)
{
// context->audioIn is the float* that points to all the input samples, stored as interleaved channels)
// audioIn is an array of 4 frames * 2 channels = 8 audio input samples.
gPipe.writeRt(context->audioIn, context->audioFrames * context->audioInChannels);
Bela_scheduleAuxiliaryTask(gFillBufferTask);
}
void cleanup(BelaContext* context, void* arg)
{
closeFile();
free(uniqueFilename);
}