diff --git a/fft.c b/fft.c old mode 100644 new mode 100755 index 0f6cf85..483b037 --- a/fft.c +++ b/fft.c @@ -106,25 +106,25 @@ return fftSig; } -unsigned int* +unsigned int* average_signal(unsigned int *fftBuf, int inLen, int maxC, int *avgLen) { unsigned int* fftAvg = malloc(inLen*sizeof(unsigned int)); - int i, j, k=0; + int i, j, step, k=0; unsigned int avg; if(maxC < 200){ *avgLen = 128; } else { - *avgLen = 256; + *avgLen = 512; } - - for(i=0; i // uint16_t #include "fft.h" // fast fourier transform #include "utils_curses.h" +#include "time.h" /*FREQ 44100*/ -#define N_SAMPLES 1024 +#define N_SAMPLES 512 /*FPS FREQ/N_SAMPLES*/ int main(int argc, char *argv[]) { - int fifo, i; + int fifo, i, j; WINDOW *mainwin; - int maxR, maxC, avgLen; //curses + int maxR, maxC, avgLen, correction; //curses uint16_t buf[N_SAMPLES]; unsigned int *fftBuf, *fftAvg; fifo = open("/tmp/mpd.fifo", O_RDONLY); - + if((mainwin = curses_init()) == NULL){ exit(EXIT_FAILURE); } @@ -31,6 +32,8 @@ nodelay(stdscr, TRUE); while(read(fifo, (uint16_t*)buf, 2*N_SAMPLES) != 0){ + /*usleep(45000);*/ + if(wgetch(stdscr)=='q'){ break; } @@ -40,15 +43,24 @@ free(fftBuf); erase(); - for(i=0; iavgLen*2/3){ - color_set(2, NULL); - } else { - color_set(3, NULL); + correction = 0; + for(i=correction; iavgLen*2/3){*/ + /*color_set(2, NULL); */ + /*} else {*/ + /*color_set(3, NULL);*/ + /*}*/ + for(j=0; j<1; j++){ + if(fftAvg[i] > maxR){ + fftAvg[i] == maxR; + } + if(fftAvg[i] < 0){ + fftAvg[i] == 0; + } + print_col(i+j-correction, fftAvg[i], maxR); } - print_col(i, fftAvg[i], maxR); } refresh(); free(fftAvg); diff --git a/utils_curses.c b/utils_curses.c old mode 100644 new mode 100755 index 5fb7c41..7fc47a2 --- a/utils_curses.c +++ b/utils_curses.c @@ -35,6 +35,7 @@ int row, l; l = maxR - length; + /*l -= 5;*/ for(row=maxR; row>l; row--){ mvaddch(row, col, SHARP); } diff --git a/utils_curses.h b/utils_curses.h old mode 100644 new mode 100755 index d7ee544..b02c2fb --- a/utils_curses.h +++ b/utils_curses.h @@ -1,6 +1,6 @@ #include -#define SHARP '#' +#define SHARP '|' void init_color_pairs(); WINDOW* curses_init();