Hi, I’m trying to record music as data from my guitar using FFT.
What I’ve done is :
- I use the schematic provided on this page : https://www.arduino.cc/en/tutorial/knock. I replace the piezzo by a jack cable plugged into a female jack.
- I use the code below to record each byte of data. It’s pure copy / paste of two different codes I found :-*
#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft
#include <FFT.h> // include the library
void setup() {
Serial.begin(115200); // use the serial port
TIMSK0 = 0; // turn off timer0 for lower jitter - delay() and millis() killed
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc03
DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop() {
Serial.write("begin");
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fft_input[i] = k; // put real data into even bins
fft_input[i+1] = 0; // set odd bins to 0
}
// window data, then reorder, then run, then take output
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei(); // turn interrupts back on
Serial.write(255); // send a start byte
for (int i=0; i<FFT_N/2; i++) {
Serial.print(i);
Serial.print(" ");
Serial.print(fft_log_out[i]);
}
Serial.println("");
}
}
I encounter two issues :
-
First one : the results that I get when nothing is recorded are non-sence but still identical : ÿ0 2241 2082 743 564 445 436 377 378 249 3010 3011 3012 3013 3014 3015 3516 817 2418 2419 2420 2421 2722 2423 3024 2425 2426 3027 2728 2729 3030 2731 3032 033 834 1935 1936 837 838 2439 2440 041 1942 1943 2744 845 1946 1947 2748 049 2450 2451 1952 853 054 2455 1956 1957 1958 1959 1960 061 1962 1963 1964 065 866 067 068 869 870 871 072 873 074 075 076 877 078 079 1980 081 1982 883 1984 085 086 887 088 889 890 091 1992 2493 894 895 096 897 098 099 0100 0101 0102 0103 0104 0105 8106 8107 8108 0109 0110 0111 19112 8113 0114 0115 8116 0117 8118 8119 8120 8121 8122 8123 8124 19125 8126 8127 0
-
Second one : if I plug the jack on my guitar and then play something, the results don’t change (= no signal received). But if I tap on the jack, I well receive something.
Any idea ?
(sorry if it’s not clear, don’t hesitate to ask for more details…)