diff --git a/cava.c b/cava.c index b895144..58f2492 100644 --- a/cava.c +++ b/cava.c @@ -83,6 +83,7 @@ double smoothDef[64] = {0.8, 0.8, 1, 1, 0.8, 0.8, 1, 0.8, 0.8, 1, 1, 0.8, 0.7, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6}; double *smooth = smoothDef; int smcount = 64; +int customEQ = 0; struct audio_data audio; int im = 0; int om = 1; @@ -93,13 +94,16 @@ int bars = 25; int autobars = 1; int stereo = -1; int M = 2048; -char supportedInput[255] = "'fifo'"; int is_bin = 1; char bar_delim = ';'; char frame_delim = '\n'; int ascii_range = 1000; int bit_format = 16; int gradient = 0; +dictionary* ini; +char supportedInput[255] = "'fifo'"; + + // whether we should reload the config or not int should_reload = 0; @@ -178,20 +182,18 @@ FILE *fp; } // config: parse ini - dictionary* ini = iniparser_load(configPath); + ini = iniparser_load(configPath); //setting fifo to defaualt if no other input modes supported inputMethod = (char *)iniparser_getstring(ini, "input:method", "fifo"); //setting alsa to defaualt if supported #ifdef ALSA - strcat(supportedInput,", 'alsa'"); inputMethod = (char *)iniparser_getstring(ini, "input:method", "alsa"); #endif //setting pulse to defaualt if supported #ifdef PULSE - strcat(supportedInput,", 'pulse'"); inputMethod = (char *)iniparser_getstring(ini, "input:method", "pulse"); #endif @@ -238,8 +240,10 @@ FILE *fp; bit_format = iniparser_getint(ini, "output:bit_format", 16); // read & validate: eq + smcount = iniparser_getsecnkeys(ini, "eq"); if (smcount > 0) { + customEQ = 1; smooth = malloc(smcount*sizeof(*smooth)); #ifndef LEGACYINIPARSER const char *keys[smcount]; @@ -252,6 +256,7 @@ FILE *fp; smooth[sk] = iniparser_getdouble(ini, keys[sk], 1); } } else { + customEQ = 0; smcount = 64; //back to the default one } @@ -312,6 +317,7 @@ void validate_config() // validate: input method + im = 0; if (strcmp(inputMethod, "alsa") == 0) { im = 1; #ifndef ALSA @@ -325,9 +331,6 @@ void validate_config() } if (strcmp(inputMethod, "pulse") == 0) { im = 3; - #ifdef PULSE - if (strcmp(audio.source, "auto") == 0) getPulseDefaultSink((void*)&audio); - #endif #ifndef PULSE fprintf(stderr, "cava was built without pulseaudio support, install pulseaudio dev files and run make clean && ./configure && make again\n"); @@ -343,6 +346,7 @@ void validate_config() } // validate: output method + om = 0; if (strcmp(outputMethod, "ncurses") == 0) { om = 1; #ifndef NCURSES @@ -621,12 +625,6 @@ int main(int argc, char **argv) int sleep = 0; int i, n, o, height, h, w, c, rest, inAtty, silence, fp, fptest; float temp; - double inr[2 * (M / 2 + 1)]; - fftw_complex outr[M / 2 + 1][2]; - fftw_plan pr; - double inl[2 * (M / 2 + 1)]; - fftw_complex outl[M / 2 + 1][2]; - fftw_plan pl; //int cont = 1; int fall[200]; float fpeak[200]; @@ -645,6 +643,8 @@ Options:\n\ as of 0.4.0 all options are specified in config file, see in '/home/username/.config/cava/' \n"; char ch = '\0'; + double inr[2 * (M / 2 + 1)]; + double inl[2 * (M / 2 + 1)]; //int maxvalue = 0; @@ -685,17 +685,26 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co n = 0; } + #ifdef ALSA + strcat(supportedInput,", 'alsa'"); + #endif + #ifdef PULSE + strcat(supportedInput,", 'pulse'"); + #endif + + //fft: planning to rock + fftw_complex outl[M / 2 + 1][2]; + fftw_plan pl = fftw_plan_dft_r2c_1d(M, inl, *outl, FFTW_MEASURE); + fftw_complex outr[M / 2 + 1][2]; + fftw_plan pr = fftw_plan_dft_r2c_1d(M, inr, *outr, FFTW_MEASURE); - - // general: main loop while (1) { //config: load & validate load_config(configPath); - validate_config(); - + validate_config(); if (om != 4) { // Check if we're running in a Virtual console todo: replace virtual console with terminal emulator @@ -768,7 +777,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co #ifdef PULSE if (im == 3) { - thr_id = pthread_create(&p_thread, NULL, input_pulse, (void*)&audio); //starting fifomusic listener + if (strcmp(audio.source, "auto") == 0) getPulseDefaultSink((void*)&audio); + thr_id = pthread_create(&p_thread, NULL, input_pulse, (void*)&audio); //starting pulsemusic listener audio.rate = 44100; } #endif @@ -780,12 +790,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co ); exit(EXIT_FAILURE); } + - pl = fftw_plan_dft_r2c_1d(M, inl, *outl, FFTW_MEASURE); //planning to rock - - if (stereo) { - pr = fftw_plan_dft_r2c_1d(M, inr, *outr, FFTW_MEASURE); - } bool reloadConf = FALSE; bool senseLow = TRUE; @@ -976,9 +982,6 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co } if (should_reload) { - //**telling audio thread to terminate**// - audio.terminate = 1; - pthread_join( p_thread, NULL); reloadConf = TRUE; resizeTerminal = TRUE; @@ -1161,9 +1164,18 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co } } }//reloading config - req.tv_sec = 1; //waiting a second to free audio streams - req.tv_nsec = 0; + req.tv_sec = 0; + req.tv_nsec = 100; //waiting some time to make shure audio is ready nanosleep (&req, NULL); + + //**telling audio thread to terminate**// + audio.terminate = 1; + pthread_join( p_thread, NULL); + + if (customEQ) free(smooth); + iniparser_freedict(ini); + + //fclose(fp); } } diff --git a/input/pulse.c b/input/pulse.c index 0bc3af7..ad4256a 100644 --- a/input/pulse.c +++ b/input/pulse.c @@ -111,7 +111,7 @@ void* input_pulse(void* data) .fragsize = BUFSIZE }; - pa_simple *s = NULL; + pa_simple *s = NULL; int error; if (!(s = pa_simple_new(NULL, "cava", PA_STREAM_RECORD, audio->source, "audio for cava", &ss, NULL, &pb, &error))) { @@ -145,9 +145,10 @@ void* input_pulse(void* data) } if (audio->terminate == 1) { + free(audio->source); pa_simple_free(s); break; - } + } } return 0;