From 0844e2e9fa9441cc021f20ef2d613fe3396b64b9 Mon Sep 17 00:00:00 2001 From: Sandy Date: Wed, 10 Oct 2018 10:55:33 -0500 Subject: [PATCH] Updated the code by deleting all whitespaces ended with newline. This is just nitpicknig and small update but it will save several bytes in each file --- cava.c | 56 +++++++++++++++++++-------------------- config.c | 8 +++--- input/fifo.c | 4 +-- input/pulse.c | 4 +-- output/terminal_ncurses.c | 30 ++++++++++----------- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/cava.c b/cava.c index f0f6ea7..f7727d2 100644 --- a/cava.c +++ b/cava.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -177,7 +177,7 @@ int * separate_freq_bands(fftw_complex out[M / 2 + 1], int bars, int lcf[200], if (channel == 1) return fl; else return fr; -} +} int * monstercat_filter (int * f, int bars, int waves, double monstercat) { @@ -348,7 +348,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co output_mode = p.om; - if (p.om != 4) { + if (p.om != 4) { // Check if we're running in a tty inAtty = 0; if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), @@ -417,7 +417,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co if (p.im == 2) { //starting fifomusic listener - thr_id = pthread_create(&p_thread, NULL, input_fifo, (void*)&audio); + thr_id = pthread_create(&p_thread, NULL, input_fifo, (void*)&audio); audio.rate = 44100; } @@ -429,7 +429,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co } else sourceIsAuto = 0; //starting pulsemusic listener - thr_id = pthread_create(&p_thread, NULL, input_pulse, (void*)&audio); + thr_id = pthread_create(&p_thread, NULL, input_pulse, (void*)&audio); audio.rate = 44100; } #endif @@ -500,7 +500,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co exit(1); } //fifo needs to be open for reading in order to write to it - fptest = open(p.raw_target, O_RDONLY | O_NONBLOCK, 0644); + fptest = open(p.raw_target, O_RDONLY | O_NONBLOCK, 0644); } } @@ -574,18 +574,18 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co } - double freqconst = log10((float)p.lowcf / (float)p.highcf) / + double freqconst = log10((float)p.lowcf / (float)p.highcf) / ((float)1 / ((float)bars + (float)1) - 1); //freqconst = -2; // process: calculate cutoff frequencies for (n = 0; n < bars + 1; n++) { - fc[n] = p.highcf * pow(10, freqconst * (-1) + ((((float)n + 1) / - ((float)bars + 1)) * freqconst)); - fre[n] = fc[n] / (audio.rate / 2); - //remember nyquist!, pr my calculations this should be rate/2 - //and nyquist freq in M/2 but testing shows it is not... + fc[n] = p.highcf * pow(10, freqconst * (-1) + ((((float)n + 1) / + ((float)bars + 1)) * freqconst)); + fre[n] = fc[n] / (audio.rate / 2); + //remember nyquist!, pr my calculations this should be rate/2 + //and nyquist freq in M/2 but testing shows it is not... //or maybe the nq freq is in M/4 //lfc stores the lower cut frequency foo each bar in the fft out buffer @@ -594,13 +594,13 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co hcf[n - 1] = lcf[n] - 1; //pushing the spectrum up if the expe function gets "clumped" - if (lcf[n] <= lcf[n - 1])lcf[n] = lcf[n - 1] + 1; + if (lcf[n] <= lcf[n - 1])lcf[n] = lcf[n - 1] + 1; hcf[n - 1] = lcf[n] - 1; } #ifdef DEBUG if (n != 0) { - mvprintw(n,0,"%d: %f -> %f (%d -> %d) \n", n, + mvprintw(n,0,"%d: %f -> %f (%d -> %d) \n", n, fc[n - 1], fc[n], lcf[n - 1], hcf[n - 1]); } @@ -609,7 +609,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co // process: weigh signal to frequencies for (n = 0; n < bars; - n++)k[n] = pow(fc[n],0.85) * ((float)height/(M*32000)) * + n++)k[n] = pow(fc[n],0.85) * ((float)height/(M*32000)) * p.smooth[(int)floor(((double)n) * smh)]; if (p.stereo) bars = bars * 2; @@ -711,13 +711,13 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co fftw_execute(pl); fftw_execute(pr); - fl = separate_freq_bands(outl,bars/2,lcf,hcf, k, 1, + fl = separate_freq_bands(outl,bars/2,lcf,hcf, k, 1, p.sens, p.ignore); - fr = separate_freq_bands(outr,bars/2,lcf,hcf, k, 2, + fr = separate_freq_bands(outr,bars/2,lcf,hcf, k, 2, p.sens, p.ignore); } else { fftw_execute(pl); - fl = separate_freq_bands(outl,bars,lcf,hcf, k, 1, + fl = separate_freq_bands(outl,bars,lcf,hcf, k, 1, p.sens, p.ignore); } @@ -784,11 +784,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co f[o] = fmem[o] * p.integral + f[o]; fmem[o] = f[o]; - int diff = (height + 1) - f[o]; + int diff = (height + 1) - f[o]; if (diff < 0) diff = 0; double div = 1 / (diff + 1); - //f[o] = f[o] - pow(div, 10) * (height + 1); - fmem[o] = fmem[o] * (1 - div / 20); + //f[o] = f[o] - pow(div, 10) * (height + 1); + fmem[o] = fmem[o] * (1 - div / 20); #ifdef DEBUG mvprintw(o,0,"%d: f:%f->%f (%d->%d)peak:%d \n", @@ -828,7 +828,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co switch (p.om) { case 1: #ifdef NCURSES - rc = draw_terminal_ncurses(inAtty, h, w, bars, + rc = draw_terminal_ncurses(inAtty, h, w, bars, p.bw, p.bs, rest, f, flastd, p.gradient); break; #endif @@ -842,7 +842,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co p.bw, p.bs, rest, f, flastd); break; case 4: - rc = print_raw_out(bars, fp, p.is_bin, + rc = print_raw_out(bars, fp, p.is_bin, p.bit_format, p.ascii_range, p.bar_delim, p.frame_delim,f); break; @@ -855,7 +855,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co req.tv_sec = 1 / (float)p.framerate; } else { req.tv_sec = 0; - req.tv_nsec = (1 / (float)p.framerate) * 1000000000; + req.tv_nsec = (1 / (float)p.framerate) * 1000000000; } nanosleep (&req, NULL); @@ -870,11 +870,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co cleanup(); fprintf(stderr, "Audio thread exited unexpectedly. %s\n", audio.error_message); - exit(EXIT_FAILURE); - } + exit(EXIT_FAILURE); + } }//resize terminal - + }//reloading config req.tv_sec = 0; req.tv_nsec = 100; //waiting some time to make shure audio is ready @@ -886,7 +886,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co if (p.customEQ) free(p.smooth); if (sourceIsAuto) free(audio.source); - + cleanup(); //fclose(fp); diff --git a/config.c b/config.c index 597c7d6..050ee28 100644 --- a/config.c +++ b/config.c @@ -14,7 +14,7 @@ struct config_params { char *color, *bcolor, *raw_target, *audio_source, /**gradient_color_1, *gradient_color_2,*/ **gradient_colors, *data_format; char bar_delim, frame_delim ; -double monstercat, integral, gravity, ignore, sens; +double monstercat, integral, gravity, ignore, sens; unsigned int lowcf, highcf; double *smooth; int smcount, customEQ, im, om, col, bgcol, autobars, stereo, is_bin, ascii_range, @@ -273,7 +273,7 @@ if (!validate_colors(p, error)) { p->gravity = p->gravity / 100; if (p->gravity < 0) { p->gravity = 0; -} +} // validate: integral @@ -391,11 +391,11 @@ if (colorsOnly) { } //setting fifo to defaualt if no other input modes supported -inputMethod = (char *)iniparser_getstring(ini, "input:method", "fifo"); +inputMethod = (char *)iniparser_getstring(ini, "input:method", "fifo"); //setting alsa to defaualt if supported #ifdef ALSA - inputMethod = (char *)iniparser_getstring(ini, "input:method", "alsa"); + inputMethod = (char *)iniparser_getstring(ini, "input:method", "alsa"); #endif //setting pulse to defaualt if supported diff --git a/input/fifo.c b/input/fifo.c index b6bb70b..58d7841 100644 --- a/input/fifo.c +++ b/input/fifo.c @@ -92,8 +92,8 @@ void* input_fifo(void* data) if (templ >= 0)templ = templ + lo; else templ = templ - lo; - if (audio->channels == 1) audio->audio_out_l[n] = (tempr + -templ) / + if (audio->channels == 1) audio->audio_out_l[n] = (tempr + +templ) / 2; diff --git a/input/pulse.c b/input/pulse.c index 75a4c86..66b6cb2 100644 --- a/input/pulse.c +++ b/input/pulse.c @@ -58,7 +58,7 @@ void pulseaudio_context_state_callback(pa_context *pulseaudio_context, case PA_CONTEXT_TERMINATED: printf("TERMINATED\n"); pa_mainloop_quit(m_pulseaudio_mainloop, 0); - break; + break; } } @@ -138,7 +138,7 @@ void* input_pulse(void* data) } n = 0; - + while (1) { /* Record some data ... */ if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) { diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c index 41d4392..94d5b14 100644 --- a/output/terminal_ncurses.c +++ b/output/terminal_ncurses.c @@ -87,33 +87,33 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi init_pair(color_pair_number, fg_color_number, bg_color_number); } else if (gradient) { - + // 0 -> col1, 1-> col1<=>col2, 2 -> col2 and so on short unsigned int rgb[2 * gradient_count - 1][3]; char next_color[8]; - + gradient_size = *height; if (gradient_size > COLORS) gradient_size = COLORS - 1; - + if (gradient_size > COLOR_PAIRS) gradient_size = COLOR_PAIRS - 1; - + if (gradient_size > MAX_COLOR_REDEFINITION) gradient_size = MAX_COLOR_REDEFINITION - 1; for(int i = 0;i < gradient_count;i++){ int col = (i + 1)*2 - 2; - sscanf(gradient_colors[i]+1, "%02hx%02hx%02hx", &rgb[col][0], &rgb[col][1], &rgb[col][2]); + sscanf(gradient_colors[i]+1, "%02hx%02hx%02hx", &rgb[col][0], &rgb[col][1], &rgb[col][2]); } //sscanf(gradient_color_1 + 1, "%02hx%02hx%02hx", &rgb[0][0], &rgb[0][1], &rgb[0][2]); - //sscanf(gradient_color_2 + 1, "%02hx%02hx%02hx", &rgb[1][0], &rgb[1][1], &rgb[1][2]); + //sscanf(gradient_color_2 + 1, "%02hx%02hx%02hx", &rgb[1][0], &rgb[1][1], &rgb[1][2]); int individual_size = gradient_size/(gradient_count - 1); int row = 0; for(int i = 0;i < gradient_count - 1;i++){ - + int col = (i + 1)* 2 - 2; if(i == gradient_count - 1) col = 2*(gradient_count - 1) - 2; @@ -124,8 +124,8 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi rgb[col+1][k] = rgb[col][k] + (rgb[col+2][k] - rgb[col][k]) * (j / (individual_size * 0.85)); if (rgb[col+1][k] > 255) rgb[col][k] = 0; if ( j > individual_size * 0.85 ) rgb[col+1][k] = rgb[col+2][k]; - } - + } + sprintf(next_color,"#%02x%02x%02x",rgb[col+1][0], rgb[col+1][1], rgb[col+1][2]); change_color_definition(row + 1, next_color, row + 1); @@ -136,7 +136,7 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi int left = individual_size * (gradient_count - 1); int col = 2*(gradient_count) - 2; - while(left < gradient_size){ + while(left < gradient_size){ sprintf(next_color,"#%02x%02x%02x",rgb[col][0], rgb[col][1], rgb[col][2]); change_color_definition(row + 1, next_color, row + 1); init_pair(color_pair_number++, row + 1, bg_color_number); @@ -188,19 +188,19 @@ int flastd[200], int gradient) { if (f[bar] > flastd[bar]) { // higher then last frame if (is_tty) { for (int n = flastd[bar] / 8; n < f[bar] / 8; n++) { - if (gradient) change_colors(n, height); + if (gradient) change_colors(n, height); for (int width = 0; width < bar_width; width++) mvprintw((height - n), CURRENT_COLUMN, "%d", 8); } } else { - for (int n = flastd[bar] / 8; n < f[bar] / 8; n++) { - if (gradient) change_colors(n, height); + for (int n = flastd[bar] / 8; n < f[bar] / 8; n++) { + if (gradient) change_colors(n, height); for (int width = 0; width < bar_width; width++) mvaddwstr((height - n), CURRENT_COLUMN, bar_heights[LAST]); } } - if (gradient) change_colors(f[bar] / 8, height); + if (gradient) change_colors(f[bar] / 8, height); if (f[bar] % 8) { if (is_tty) { for (int width = 0; width < bar_width; width++) @@ -217,7 +217,7 @@ int flastd[200], int gradient) { for (int width = 0; width < bar_width; width++) mvaddstr((height - n), CURRENT_COLUMN, " "); if (f[bar] % 8) { - if (gradient) change_colors(f[bar] / 8, height); + if (gradient) change_colors(f[bar] / 8, height); if (is_tty) { for (int width = 0; width < bar_width; width++) mvprintw((height - f[bar] / 8), CURRENT_COLUMN, "%d",