Merge pull request #14 from livibetter/make-debug

make debug option
master
karl 11 years ago
commit a81fe634a7
  1. 10
      README.md
  2. 68
      cava.c
  3. 6
      makefile

@ -53,6 +53,16 @@ Getting started
make make
You can use the following for compilation options, value in *italic style* is the default value:
| Name | Value | Description |
| ---- | ----- | ----------- |
| `debug` | *0* or 1 | Debugging message switch |
For example, turning on debugging messages:
make debug=1
### Installing ### Installing
Install `cava` to default `/usr/local`: Install `cava` to default `/usr/local`:

@ -35,7 +35,6 @@
struct sigaction old_action; struct sigaction old_action;
int M = 2048; int M = 2048;
int shared[2048]; int shared[2048];
int debug = 0;
int format = -1; int format = -1;
unsigned int rate = 0; unsigned int rate = 0;
@ -71,9 +70,10 @@ music(void* data)
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_CAPTURE , 0) < 0)) if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_CAPTURE , 0) < 0))
printf("error opening stream: %s\n", snd_strerror(err) ); printf("error opening stream: %s\n", snd_strerror(err) );
else if (debug == 1) { #ifdef DEBUG
printf("open stream succes\n"); else printf("open stream succes\n");
} #endif
snd_pcm_hw_params_alloca(&params);//assembling params snd_pcm_hw_params_alloca(&params);//assembling params
snd_pcm_hw_params_any (handle, params);//setting defaults or something snd_pcm_hw_params_any (handle, params);//setting defaults or something
snd_pcm_hw_params_set_access(handle, params, snd_pcm_hw_params_set_access(handle, params,
@ -117,19 +117,18 @@ music(void* data)
err = snd_pcm_readi(handle, buffer, frames); err = snd_pcm_readi(handle, buffer, frames);
if (err == -EPIPE) { if (err == -EPIPE) {
/* EPIPE means overrun */ /* EPIPE means overrun */
if (debug == 1) { #ifdef DEBUG
fprintf(stderr, "overrun occurred\n"); fprintf(stderr, "overrun occurred\n");
} #endif
snd_pcm_prepare(handle); snd_pcm_prepare(handle);
} else if (err < 0) { } else if (err < 0) {
if (debug == 1) { #ifdef DEBUG
fprintf(stderr, "error from read: %s\n", fprintf(stderr, "error from read: %s\n", snd_strerror(err));
snd_strerror(err)); #endif
}
} else if (err != (int)frames) { } else if (err != (int)frames) {
if (debug == 1) { #ifdef DEBUG
fprintf(stderr, "short read, read %d %d frames\n", err, (int)frames); fprintf(stderr, "short read, read %d %d frames\n", err, (int)frames);
} #endif
} }
//sorting out one channel and only biggest octet //sorting out one channel and only biggest octet
@ -257,7 +256,9 @@ int main(int argc, char **argv)
int col = 36; int col = 36;
int bgcol = 0; int bgcol = 0;
int sens = 100; int sens = 100;
#ifndef DEBUG
int move = 0; int move = 0;
#endif
int fall[200]; int fall[200];
float fpeak[200]; float fpeak[200];
float k[200]; float k[200];
@ -390,12 +391,15 @@ Options:\n\
nanosleep (&req, NULL); nanosleep (&req, NULL);
n++; n++;
if (n > 2000) { if (n > 2000) {
if (debug == 1) #ifdef DEBUG
printf("could not get rate and or format, problems with audoi thread? quiting...\n"); printf("could not get rate and or format, problems with audoi thread? quiting...\n");
#endif
exit(1); exit(1);
} }
} }
if (debug == 1)printf("got format: %d and rate %d\n", format, rate); #ifdef DEBUG
printf("got format: %d and rate %d\n", format, rate);
#endif
} }
@ -422,12 +426,14 @@ Options:\n\
1; //handle for user setting to many bars 1; //handle for user setting to many bars
height = (int)w.ws_row - 1; height = (int)w.ws_row - 1;
width = (int)w.ws_col - bands - 1; width = (int)w.ws_col - bands - 1;
#ifndef DEBUG
int matrix[width][height]; int matrix[width][height];
for (i = 0; i < width; i++) { for (i = 0; i < width; i++) {
for (n = 0; n < height; n++) { for (n = 0; n < height; n++) {
matrix[i][n] = 0; matrix[i][n] = 0;
} }
} }
#endif
bw = width / bands; bw = width / bands;
g = ((float)height / 1000) * pow((60 / (float)framerate), g = ((float)height / 1000) * pow((60 / (float)framerate),
@ -441,12 +447,11 @@ Options:\n\
rest = (((w.ws_col) - (bw * bands + bands - 1))); rest = (((w.ws_col) - (bw * bands + bands - 1)));
if (rest < 0)rest = 0; if (rest < 0)rest = 0;
if (debug == 1) #ifdef DEBUG
printf("hoyde: %d bredde: %d bands:%d bandbredde: %d rest: %d\n", printf("hoyde: %d bredde: %d bands:%d bandbredde: %d rest: %d\n",
(int)w.ws_row, (int)w.ws_row,
(int)w.ws_col, bands, bw, rest); (int)w.ws_col, bands, bw, rest);
#endif
//**calculating cutof frequencies**/ //**calculating cutof frequencies**/
for (n = 0; n < bands + 1; n++) { for (n = 0; n < bands + 1; n++) {
@ -464,10 +469,12 @@ Options:\n\
hcf[n - 1] = lcf[n] - 1; hcf[n - 1] = lcf[n] - 1;
} }
if (debug == 1 && n != 0) { #ifdef DEBUG
if (n != 0) {
printf("%d: %f -> %f (%d -> %d) \n", n, fc[n - 1], fc[n], lcf[n - 1], printf("%d: %f -> %f (%d -> %d) \n", n, fc[n - 1], fc[n], lcf[n - 1],
hcf[n - 1]); hcf[n - 1]);
} }
#endif
} }
//exit(1); //exit(1);
@ -480,8 +487,8 @@ Options:\n\
//**preparing screen**// //**preparing screen**//
if (debug == 0) {
virt = system("setfont cava.psf >/dev/null 2>&1"); virt = system("setfont cava.psf >/dev/null 2>&1");
#ifndef DEBUG
system("setterm -cursor off"); system("setterm -cursor off");
system("setterm -blank 0"); system("setterm -blank 0");
//resetting console //resetting console
@ -505,7 +512,7 @@ Options:\n\
} }
printf("\033[%dA", height); //backup printf("\033[%dA", height); //backup
} }
} #endif
//debug=1; //debug=1;
//**start main loop**// //**start main loop**//
@ -522,12 +529,9 @@ Options:\n\
} }
} }
#ifdef DEBUG
if (debug == 1) {
system("clear"); system("clear");
} #endif
//**populating input buffer & checking if there is sound**// //**populating input buffer & checking if there is sound**//
lpeak = 0; lpeak = 0;
@ -585,16 +589,18 @@ Options:\n\
flast[o] = f[o]; //memmory for falloff func flast[o] = f[o]; //memmory for falloff func
if (f[o] < 0.125)f[o] = 0.125; if (f[o] < 0.125)f[o] = 0.125;
if (debug == 1) { #ifdef DEBUG
printf("%d: f:%f->%f (%d->%d)peak:%f adjpeak: %f \n", o, fc[o], fc[o + 1], printf("%d: f:%f->%f (%d->%d)peak:%f adjpeak: %f \n", o, fc[o], fc[o + 1],
lcf[o], hcf[o], peak[o], f[o]); lcf[o], hcf[o], peak[o], f[o]);
} #endif
} }
// if(debug==1){ printf("topp overall unfiltered:%f \n",peak[bands]); } // if(debug==1){ printf("topp overall unfiltered:%f \n",peak[bands]); }
//if(debug==1){ printf("topp overall alltime:%f \n",sum);} //if(debug==1){ printf("topp overall alltime:%f \n",sum);}
} else { //**if in sleep mode wait and continiue**// } else { //**if in sleep mode wait and continiue**//
if (debug == 1)printf("no sound detected for 3 sec, going to sleep mode\n"); #ifdef DEBUG
printf("no sound detected for 3 sec, going to sleep mode\n");
#endif
//for (i=0;i<200;i++)flast[i]=0; //zeroing memory no more nesceseary after faloff on pauses //for (i=0;i<200;i++)flast[i]=0; //zeroing memory no more nesceseary after faloff on pauses
//pthread_cancel(thr_id);// this didnt work to well, killing sound thread //pthread_cancel(thr_id);// this didnt work to well, killing sound thread
//wait 1 sec, then check sound again. //wait 1 sec, then check sound again.
@ -619,7 +625,7 @@ Options:\n\
} }
//**DRAWING**// -- put in function file maybe? //**DRAWING**// -- put in function file maybe?
if (debug == 0) { #ifndef DEBUG
for (n = (height - 1); n >= 0; n--) { for (n = (height - 1); n >= 0; n--) {
o = 0; o = 0;
move = rest / 2; //center adjustment move = rest / 2; //center adjustment
@ -672,9 +678,7 @@ Options:\n\
req.tv_sec = 0; req.tv_sec = 0;
req.tv_nsec = (1 / (float)framerate) * 1000000000; //sleeping for set us req.tv_nsec = (1 / (float)framerate) * 1000000000; //sleeping for set us
nanosleep (&req, NULL); nanosleep (&req, NULL);
#endif
}
} }
} }
return 0; return 0;

@ -9,6 +9,12 @@ INSTALL_BIN = $(INSTALL) -D -m 755
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR = $(DESTDIR)/$(PREFIX)/bin BINDIR = $(DESTDIR)/$(PREFIX)/bin
debug ?= 0
ifeq ($(debug),1)
CPPFLAGS += -DDEBUG
endif
all: cava all: cava
cava: cava.c cava: cava.c

Loading…
Cancel
Save