1 /*
2 fft_adc.pde
3 guest openmusiclabs.com 8.18.12
4 example sketch for testing the fft library.
5 it takes in data on ADC0 (Analog0) and processes them
6 with the fft. the data is sent out over the serial
7 port at 115.2kb. there is a pure data patch for
8 visualizing the data.
9 */
10
11 #define LOG_OUT 1 // use the log output function
12 #define FFT_N 256 // set to 256 point fft
13
14 #include <FFT.h> // include the library
15
16 void setup() {
17 Serial.begin(115200)
18 TIMSK0 = 0
19 ADCSRA = 0xe5
20 ADMUX = 0x40
21 DIDR0 = 0x01
22 }
23
24 void loop() {
25 while(1) { // reduces jitter
26 cli()
27 for (int i = 0
28 while(!(ADCSRA & 0x10))
29 ADCSRA = 0xf5
30 byte m = ADCL
31 byte j = ADCH
32 int k = (j << 8) | m
33 k -= 0x0200
34 k <<= 6
35 fft_input[i] = k
36 fft_input[i+1] = 0
37 }
38 fft_window()
39 fft_reorder()
40 fft_run()
41 fft_mag_log()
42 sei()
43 Serial.write(255)
44 Serial.write(fft_log_out, 128)
45 }
46 }
47