Hi everyone, I'm trying to do a Timegrapher and I want to analyse the output samples[n].
I'm trying to apply the FFT on the output before printing it, without success. Any help will be welcome.
Thanks in advance.
#include <SPI.h>
#define SS 5
int16_t* samples;
uint32_t n = 0;
int count = 0;
unsigned long start_time;
unsigned long end_time;
const unsigned long event = 10000;
const uint32_t max_samples=50000;
void setup() {
Serial.begin(115200); /* initialization of serial communication */
SPI.begin(); /* initialization of SPI port */
SPI.setDataMode(SPI_MODE0); /* configuration of SPI communication in mode 0 */
SPI.setClockDivider(SPI_CLOCK_DIV64); /* configuration of clock at 1MHz */
pinMode(SS, OUTPUT);
Serial.println("Start");
samples = (int16_t*)malloc(sizeof(int16_t)*max_samples);
if(samples == NULL){
Serial.print("insufficient memory");
}
else{
Serial.print("malloc ok.");
}
}
void loop() {
start_time = millis();
for (n=0; n<max_samples; n++)
{
samples[n] = Sound();
}
end_time = millis();
Serial.print("Dauer [ms]: ");
Serial.print((end_time-start_time));
Serial.print(" ||| ");
Serial.print("Beats: ");
Serial.print(n);
Serial.println(" ||| ");
for (n = 0; n < max_samples; n++)
{
Serial.print(samples[n]);
//Serial.print(",-35000,35000");
Serial.println();
}
}
int16_t Sound(void) {
digitalWrite(SS, LOW); //activate chip select
int sound = SPI.transfer(0) | (SPI.transfer(0) << 8); //reconstruct 12-bit data
digitalWrite(SS, HIGH); //deactivate chip select
return sound;
}