Following is the code-snippet:
#include <Bela.h>
#include <ne10/NE10.h>
#include <sndfile.h>
#include <WriteFile.h>
//#include <Midi.h>
AuxiliaryTask gTask;
WriteFile file1;
int numAnalogFrames;
int numAnalogChannels;
float *gInputAudio = NULL;
void writeWAV_background();
void print_results();
bool setup(BelaContext *context, void *userData)
{
// For this example we need the same amount of audio and analog input and output channels
if(context->audioInChannels != context->audioOutChannels ||
context->analogInChannels != context-> analogOutChannels){
printf("Error: for this project, you need the same number of input and output channels.\n");
return false;
}
// Allocate buffer to mirror and modify the input
gInputAudio = (float *)malloc(context->analogFrames * context->analogInChannels * sizeof(float));
if(gInputAudio == 0)
return false;
file1.init("outNew.txt"); //set the file name to write to
file1.setFileType(kText);
//file1.setHeader("myvar=[\n"); //set a line to be printed at the beginning of the file
//file1.setFooter("];\n"); //set a line to be printed at the end of the file
//file1.setEcho(true); // enable echo to the console (as well as to the file)
file1.setFormat("%f %f %f %f %f %f %f %f\n"); // set the format that you want to use for your output. Please use %f only (with modifiers)
//if((gAudioTask = Bela_createAuxiliaryTask(&writeWAV_background, 95, "write-wav", )) == 0);
// Initialise auxiliary tasks
if((gTask = Bela_createAuxiliaryTask(&writeWAV_background, 95, "write-wav-new")) == 0)
return false;
return true;
}
void render(BelaContext *context, void *userData)
{
numAnalogFrames = context->analogFrames;
numAnalogChannels = context->analogInChannels;
//numAnalogChannels = 1;
// Simplest possible case: pass inputs through to outputs
/*for(unsigned int n = 0; n < context->audioFrames; n++) {
for(unsigned int ch = 0; ch < context->audioInChannels; ch++){
// Two equivalent ways to write this code
// The long way, using the buffers directly:
// context->audioOut[n * context->audioOutChannels + ch] =
// context->audioIn[n * context->audioInChannels + ch];
//float val = analogRead(context, n, ch);
//file1.log(val);
//gInputAudio[n * numAnalogChannels + ch] = val;
// Or using the macros:
audioWrite(context, n, ch, audioRead(context, n, ch));
}
}*/
// Same with analog channels
for(unsigned int n = 0; n < numAnalogFrames; n++) {
for(unsigned int ch = 0; ch < numAnalogChannels; ch++) {
// Two equivalent ways to write this code
// The long way, using the buffers directly:
// context->analogOut[n * context->analogOutChannels + ch] =
// context->analogIn[n * context->analogInChannels + ch];
float val = analogRead(context, n, ch);
//file1.log(val);
gInputAudio[n * numAnalogChannels + ch] = val;
// Or using the macros:
//audioWrite(context, n, ch, analogRead(context, n, ch));
}
}
Bela_scheduleAuxiliaryTask(gTask);
}
void writeWAVNew(float * buffer, int bufferSize){
for (int i =0; i <bufferSize; i++ )
file1.log(buffer[i]);
}
void writeWAV_background() {
writeWAVNew(gInputAudio, numAnalogFrames*numAnalogChannels);
}
void cleanup(BelaContext *context, void *userData)
{
//free(gInputAudio);
}
Is this a reasonable way to log 8-channel mic data ? 1min of recording is creating around 80 MB of data.