giuliomoro It sounds like the second solution is safer. I have another question: If I use audio inputs 0/1 (L/R) of the cape and ananlog IN2/3 (enable analog IN0-3 as audio inputs, sample rate is same with audio sample rate)of the capelet to receive signal of 4 mics, is it a possible alternative solution to use 4-mic array to mearsure AoA? If it is possible, what issues do I need to pay attention to? For example, how can I synchronize these 4-mic signal inputs?
Here is the simple code for FMCW audio output and 4-mic inputs with real time logging, is it feasible?
WriteFile file;
//FMCW
float gFrequencyLow = 18000.0; // Frequency of the sine wave in Hz
float gBandwidth = 4000.0;
float gT_chirp = 0.04;
float gPhase = 0;
float shift = 0;
int gAudioPerAnalog;
bool setup(BelaContext *context, void *userData)
{
printf("Audio Sample Rate: %f\n", context->audioSampleRate);
printf("Audio Frames: %d\n", context->audioFrames);
printf("Audio Output Channels: %d\n", context->audioOutChannels);
printf("Audio Input Channels: %d\n", context->audioInChannels);
printf("Analog Sample Rate: %f\n", context->analogSampleRate);
printf("Analog Frames: %d\n", context->analogFrames);
printf("Analog Output Channels: %d\n", context->analogOutChannels);
printf("Analog Input Channels: %d\n", context->analogInChannels);
gAudioPerAnalog = context->audioFrames/context->analogFrames;
printf("Audio/Analog Frames: %d\n", gAudioPerAnalog);
file.setup("trans_and_rece.bin");
file.setFileType(kBinary);
file.setFormat("binary: %.4f %.4f\n");
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->audioFrames; n++) {
float out = cos(gPhase);
float gFrequency = 1/gT_chirp * shift;
gFrequency = gFrequencyLow + gFrequency;
gPhase += 2.0 * M_PI * gFrequency / context->audioSampleRate;
if(gPhase > M_PI)
gPhase -= 2.0 * M_PI;
shift += gBandwidth / context->audioSampleRate;
if(shift >= gBandwidth * gT_chirp)
shift -= gBandwidth * gT_chirp;
file.log(out); // log out
audioWrite(context, n, 0, out); %audio oupt channel:0
// first 2 mics inputs from audio IN0-1
for(unsigned int ch = 0; ch < context->audioInChannels; ch++){
float val = audioRead(context, n, ch);
file.log(val);
}
// then 2 mics inputs from analog IN2-3 of capelet
float input3 = analogRead(context, n/gAudioPerAnalog, 2);
file.log(input3);
float input4 = analogRead(context, n/gAudioPerAnalog, 3);
file.log(input4);
}
}
void cleanup(BelaContext *context, void *userData)
{
}