giuliomoro For the recording part, I used nearly the same code you provide in https://forum.bela.io/d/1083-bela-audio-recorder/4, I just change all the audio channels to analog channels.
But even if I deleted all the code for playing audio and only use the recording code, there is still obvious noise.
The recording only code is:
#include <Bela.h>
#include <libraries/Pipe/Pipe.h>
#include <libraries/sndfile/sndfile.h>
#include <cmath>
float gFrequency;
float gPhase;
float gInverseSampleRate;
const char* path = "./recording_only.wav";
AuxiliaryTask gFillBufferTask;
SNDFILE * outfile;
Pipe gPipe;
unsigned int numAnalogFrames;
unsigned int numAnalogChannels;
float numAnalogSampleRate;
void openFile() {
SF_INFO sfinfo;
sfinfo.channels = numAnalogChannels;
sfinfo.samplerate = numAnalogSampleRate;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
outfile = sf_open(path, SFM_WRITE, &sfinfo);
}
void closeFile() {
sf_write_sync(outfile);
sf_close(outfile);
}
void writeBuffer(void*) {
unsigned int numItemsAnalog = numAnalogFrames * numAnalogChannels;
float bufAnalog[numItemsAnalog];
int retAnalog;
while ((retAnalog = gPipe.readNonRt(bufAnalog, numItemsAnalog)) > 0)
{
sf_write_float(outfile, &bufAnalog[0], retAnalog);
}
}
bool setup(BelaContext* context, void* arg)
{
numAnalogSampleRate = context->analogSampleRate;
numAnalogFrames = context->analogFrames;
numAnalogChannels = context->analogInChannels;
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)
{
gPipe.writeRt(context->analogIn, context->analogFrames * context->analogInChannels);
Bela_scheduleAuxiliaryTask(gFillBufferTask);
}
void cleanup(BelaContext* context, void* arg)
{
closeFile();
}
Thanks for your help!