Hello community,

here is the log from the commit of package cava for openSUSE:Factory checked in 
at 2018-05-06 15:02:41
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/cava (Old)
 and      /work/SRC/openSUSE:Factory/.cava.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "cava"

Sun May  6 15:02:41 2018 rev:5 rq:604592 version:0.6.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/cava/cava.changes        2017-08-29 
11:46:41.558231953 +0200
+++ /work/SRC/openSUSE:Factory/.cava.new/cava.changes   2018-05-06 
15:02:46.406152138 +0200
@@ -1,0 +2,14 @@
+Sun May  6 08:27:29 UTC 2018 - mvet...@suse.com
+
+- Update to 0.6.1:
+  new features:
+  * sndio backend
+  bug fixes:
+  * Fix fftw_complex usage, drastically improving visualization
+  * better cleanup and exiting
+  * added a check to see if pulseaudio is running
+  * fixed bug preventing color in noncurses mode from working
+  * Fix build errors and warnings if not using ncurses
+  * Generally improved fifo input and raw output
+
+-------------------------------------------------------------------

Old:
----
  0.6.0.tar.gz

New:
----
  0.6.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ cava.spec ++++++
--- /var/tmp/diff_new_pack.n8ttT1/_old  2018-05-06 15:02:47.070127767 +0200
+++ /var/tmp/diff_new_pack.n8ttT1/_new  2018-05-06 15:02:47.070127767 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package cava
 #
-# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -17,7 +17,7 @@
 
 
 Name:           cava
-Version:        0.6.0
+Version:        0.6.1
 Release:        0
 Summary:        Console-based Audio Visualizer for Alsa
 License:        MIT

++++++ 0.6.0.tar.gz -> 0.6.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/README.md new/cava-0.6.1/README.md
--- old/cava-0.6.0/README.md    2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/README.md    2018-05-03 18:07:33.000000000 +0200
@@ -136,7 +136,10 @@
 
 ### Fedora
 
-[RPM spec 
file](https://gist.github.com/sedrubal/617d40deb7452a25d004#file-cava-spec)
+Cava is available in Fedora 26 and later.  You can install Cava by
+running:
+
+    dnf install cava
 
 ### Arch
 
@@ -154,7 +157,7 @@
     
 
 
-All distro specific instalations sources might be out of date.
+All distro specific instalation sources might be out of date.
 
 
 Capturing audio
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/cava.c new/cava-0.6.1/cava.c
--- old/cava-0.6.0/cava.c       2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/cava.c       2018-05-03 18:07:33.000000000 +0200
@@ -1,6 +1,12 @@
 #define _XOPEN_SOURCE_EXTENDED
-#include <alloca.h>
 #include <locale.h>
+
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#else
+#include <stdlib.h>
+#endif
+
 #include <stdio.h>
 #include <stddef.h>
 #include <stdbool.h>
@@ -53,6 +59,10 @@
 #include "input/pulse.c"
 #endif
 
+#ifdef SNDIO
+#include "input/sndio.c"
+#endif
+
 #include <iniparser.h>
 
 #include "config.h"
@@ -69,7 +79,7 @@
 struct termios oldtio, newtio;
 int rc;
 int M = 2048;
-
+int output_mode;
 
 
 
@@ -80,10 +90,16 @@
 // general: cleanup
 void cleanup(void)
 {
+       if (output_mode == 1 || output_mode == 2 ) {
        #ifdef NCURSES
-       cleanup_terminal_ncurses();
+           cleanup_terminal_ncurses();
+       #else
+               ;
        #endif
-       cleanup_terminal_noncurses();
+    }
+    else if (output_mode ==3 ) {
+           cleanup_terminal_noncurses();
+    }
 }
 
 // general: handle signals
@@ -111,14 +127,16 @@
 
 static bool directory_exists(const char * path) {
        DIR * const dir = opendir(path);
-       const bool exists = dir != NULL;
+       bool exists;// = dir != NULL;
+    if (dir == NULL) exists = false;
+    else exists = true;
        closedir(dir);
        return exists;
 }
 
 #endif
 
-int * separate_freq_bands(fftw_complex out[M / 2 + 1][2], int bars, int 
lcf[200],
+int * separate_freq_bands(fftw_complex out[M / 2 + 1], int bars, int lcf[200],
                         int hcf[200], float k[200], int channel, double sens, 
double ignore) {
        int o,i;
        float peak[201];
@@ -137,7 +155,7 @@
                for (i = lcf[o]; i <= hcf[o]; i++) {
 
                        //getting r of compex
-                       y[i] =  pow(pow(*out[i][0], 2) + pow(*out[i][1], 2), 
0.5);
+                       y[i] = hypot(out[i][0], out[i][1]);
                        peak[o] += y[i]; //adding upp band
                }
 
@@ -166,7 +184,7 @@
        if (waves > 0) {
                for (z = 0; z < bars; z++) { // waves
                        f[z] = f[z] / 1.25;
-                       if (f[z] < 0.125)f[z] = 0.125;
+                       //if (f[z] < 1) f[z] = 1;
                        for (m_y = z - 1; m_y >= 0; m_y--) {
                                de = z - m_y;
                                f[m_y] = max(f[z] - pow(de, 2), f[m_y]);
@@ -178,7 +196,7 @@
                }
        } else if (monstercat > 0) {
                for (z = 0; z < bars; z++) {
-                       if (f[z] < 0.125)f[z] = 0.125;
+                       //if (f[z] < 1)f[z] = 1;
                        for (m_y = z - 1; m_y >= 0; m_y--) {
                                de = z - m_y;
                                f[m_y] = max(f[z] / pow(monstercat, de), 
f[m_y]);
@@ -228,6 +246,16 @@
        -p          path to config file\n\
        -v          print version\n\
 \n\
+Keys:\n\
+        Up        Increase sensitivity\n\
+        Down      Decrease sensitivity\n\
+        Left      Decrease number of bars\n\
+        Right     Increase number of bars\n\
+        r         Reload config\n\
+        c         Cycle foreground color\n\
+        b         Cycle background color\n\
+        q         Quit\n\
+\n\
 as of 0.4.0 all options are specified in config file, see in 
'/home/username/.config/cava/' \n";
 
        char ch = '\0';
@@ -287,13 +315,16 @@
     #ifdef PULSE
         strcat(supportedInput,", 'pulse'");
     #endif
+    #ifdef SNDIO
+        strcat(supportedInput,", 'sndio'");
+    #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 outl[M / 2 + 1];
+       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);
+       fftw_complex outr[M / 2 + 1];
+       fftw_plan pr =  fftw_plan_dft_r2c_1d(M, inr, outr, FFTW_MEASURE);
 
        // general: main loop
        while (1) {
@@ -301,6 +332,8 @@
        //config: load
        load_config(configPath, supportedInput, (void *)&p);
 
+    output_mode = p.om;
+
        if (p.om != 4) { 
                // Check if we're running in a tty
                inAtty = 0;
@@ -335,6 +368,7 @@
                if (is_loop_device_for_sure(audio.source)) {
                        if (directory_exists("/sys/")) {
                                if (! 
directory_exists("/sys/module/snd_aloop/")) {
+                               cleanup();
                                        fprintf(stderr,
                                        "Linux kernel module \"snd_aloop\" does 
not seem to  be loaded.\n"
                                        "Maybe run \"sudo modprobe 
snd_aloop\".\n");
@@ -354,11 +388,9 @@
                        nanosleep (&req, NULL);
                        n++;
                        if (n > 2000) {
-                       #ifdef DEBUG
                                cleanup();
                                fprintf(stderr,
                                "could not get rate and/or format, problems 
with audio thread? quiting...\n");
-                       #endif
                                exit(EXIT_FAILURE);
                        }
                }
@@ -388,6 +420,13 @@
        }
        #endif
 
+       #ifdef SNDIO
+       if (p.im == 4) {
+               thr_id = pthread_create(&p_thread, NULL, input_sndio, 
(void*)&audio);
+               audio.rate = 44100;
+       }
+       #endif
+
        if (p.highcf > audio.rate / 2) {
                cleanup();
                fprintf(stderr,
@@ -398,8 +437,8 @@
 
 
 
-       bool reloadConf = FALSE;
-       bool senseLow = TRUE;
+       bool reloadConf = false;
+       bool senseLow = true;
 
        while  (!reloadConf) {//jumbing back to this loop means that you 
resized the screen
                for (i = 0; i < 200; i++) {
@@ -422,6 +461,8 @@
 
                if (p.om == 3) get_terminal_dim_noncurses(&w, &h);
 
+               height = (h - 1) * 8;
+
                // output open file/fifo for raw output
                if (p.om == 4) {
 
@@ -456,9 +497,17 @@
                        }
                        printf("open file %s for writing raw 
ouput\n",p.raw_target);
 
-            //height and with must be hardcoded for raw output.
-                       h = 112;
+            //width must be hardcoded for raw output.
                        w = 200;
+
+               if (strcmp(p.data_format, "binary") == 0) {
+                height = pow(2, p.bit_format) - 1;
+            } else {
+                height = p.ascii_range;
+            }
+
+
+
                }
 
                //handle for user setting too many bars
@@ -483,10 +532,10 @@
 
 
 
-               height = h - 1;
+
 
                // process [smoothing]: calculate gravity
-               g = p.gravity * ((float)height / 270) * pow((60 / 
(float)p.framerate), 2.5);
+               g = p.gravity * ((float)height / 2160) * pow((60 / 
(float)p.framerate), 2.5);
 
 
                //checks if there is stil extra room, will use this to center
@@ -526,7 +575,7 @@
                        //or maybe the nq freq is in M/4
 
                        //lfc stores the lower cut frequency foo each bar in 
the fft out buffer
-                       lcf[n] = fre[n] * (M /4); 
+                       lcf[n] = fre[n] * (M /2);
                        if (n != 0) {
                                hcf[n - 1] = lcf[n] - 1;
        
@@ -546,12 +595,12 @@
 
                // process: weigh signal to frequencies
                for (n = 0; n < bars;
-                       n++)k[n] = pow(fc[n],0.85) * ((float)height/(M*4000)) * 
+                       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;
 
-               bool resizeTerminal = FALSE;
+               bool resizeTerminal = false;
 
                while  (!resizeTerminal) {
 
@@ -569,11 +618,11 @@
                                        break;
                                case 68:    // key right
                                        p.bw++;
-                                       resizeTerminal = TRUE;
+                                       resizeTerminal = true;
                                        break;
                                case 67:    // key left
                                        if (p.bw > 1) p.bw--;
-                                       resizeTerminal = TRUE;
+                                       resizeTerminal = true;
                                        break;
                                case 'r': //reload config
                                        should_reload = 1;
@@ -581,12 +630,12 @@
                                case 'c': //change forground color
                                        if (p.col < 7) p.col++;
                                        else p.col = 0;
-                                       resizeTerminal = TRUE;
+                                       resizeTerminal = true;
                                        break;
                                case 'b': //change backround color
                                        if (p.bgcol < 7) p.bgcol++;
                                        else p.bgcol = 0;
-                                       resizeTerminal = TRUE;
+                                       resizeTerminal = true;
                                        break;
 
                                case 'q':
@@ -596,8 +645,8 @@
 
                        if (should_reload) {
 
-                               reloadConf = TRUE;
-                               resizeTerminal = TRUE;
+                               reloadConf = true;
+                               resizeTerminal = true;
                                should_reload = 0;
 
                        }
@@ -706,10 +755,10 @@
                                        f[o] = fmem[o] * p.integral + f[o];
                                        fmem[o] = f[o];
 
-                                       int diff = (height + 1) * 8 - 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 
* 8 + 1); 
+                                       //f[o] = f[o] - pow(div, 10) * (height 
+ 1); 
                                        fmem[o] = fmem[o] * (1 - div / 20); 
 
                                        #ifdef DEBUG
@@ -733,10 +782,10 @@
                        //printf("%d\n",maxvalue); //checking maxvalue I keep 
forgetting its about 10000
 
                        //autmatic sens adjustment
-                       if (p.autosens && p.om != 4) {
+                       if (p.autosens) {
                                for (o = 0; o < bars; o++) {
-                                       if (f[o] > height * 8 ) {
-                                               senseLow = FALSE;
+                                       if (f[o] > height ) {
+                                               senseLow = false;
                                                p.sens = p.sens * 0.985;
                                                break;
                                        }
@@ -771,7 +820,7 @@
                                }
 
                                //terminal has been resized breaking to 
recalibrating values
-                               if (rc == -1) resizeTerminal = TRUE; 
+                               if (rc == -1) resizeTerminal = true;
 
                                if (p.framerate <= 1) {
                                        req.tv_sec = 1  / (float)p.framerate;
@@ -786,7 +835,17 @@
                        for (o = 0; o < bars; o++) {
                                flastd[o] = f[o];
                        }
-               }
+
+            //checking if audio thread has exited unexpectedly
+            if (audio.terminate == 1) {
+                cleanup();
+                               fprintf(stderr,
+                "Audio thread exited unexpectedly. %s\n", audio.error_message);
+                exit(EXIT_FAILURE); 
+            } 
+
+               }//resize terminal
+        
        }//reloading config
        req.tv_sec = 0;
        req.tv_nsec = 100; //waiting some time to make shure audio is ready
@@ -798,8 +857,8 @@
 
        if (p.customEQ) free(p.smooth);
        if (sourceIsAuto) free(audio.source);
-
-
+   
+    cleanup();
 
        //fclose(fp);
        }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/config.c new/cava-0.6.1/config.c
--- old/cava-0.6.0/config.c     2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/config.c     2018-05-03 18:07:33.000000000 +0200
@@ -6,12 +6,12 @@
                                        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};
 
 
-char *inputMethod, *outputMethod, *channels, *data_format;
+char *inputMethod, *outputMethod, *channels;
 
 
 struct config_params {
 
-char *color, *bcolor, *raw_target, *audio_source, *gradient_color_1, 
*gradient_color_2;
+char *color, *bcolor, *raw_target, *audio_source, *gradient_color_1, 
*gradient_color_2, *data_format;
 char bar_delim, frame_delim ;
 double monstercat, integral, gravity, ignore, sens; 
 unsigned int lowcf, highcf;
@@ -87,6 +87,13 @@
         #endif
 
 }
+if (strcmp(inputMethod, "sndio") == 0) {
+       p->im = 4;
+       #ifndef SNDIO
+               fprintf(stderr, "cava was built without sndio support\n");
+               exit(EXIT_FAILURE);
+       #endif
+}
 if (p->im == 0) {
        fprintf(stderr,
                "input method '%s' is not supported, supported methods are: 
%s\n",
@@ -98,6 +105,7 @@
 p->om = 0;
 if (strcmp(outputMethod, "ncurses") == 0) {
        p->om = 1;
+    p->bgcol = -1;
        #ifndef NCURSES
                fprintf(stderr,
                        "cava was built without ncurses support, install 
ncursesw dev files and run make clean && ./configure && make again\n");
@@ -118,11 +126,10 @@
 }
 if (strcmp(outputMethod, "raw") == 0) {//raw:
        p->om = 4;
-       p->autosens = 0;
        
        //checking data format
        p->is_bin = -1;
-       if (strcmp(data_format, "binary") == 0) {
+       if (strcmp(p->data_format, "binary") == 0) {
                p->is_bin = 1;
                //checking bit format:
                if (p->bit_format != 8 && p->bit_format != 16 ) {
@@ -132,7 +139,7 @@
                exit(EXIT_FAILURE);
        
                }
-       } else if (strcmp(data_format, "ascii") == 0) {
+       } else if (strcmp(p->data_format, "ascii") == 0) {
                p->is_bin = 0;
                if (p->ascii_range < 1 ) {
                fprintf(stderr,
@@ -142,7 +149,7 @@
        } else {
        fprintf(stderr,
                "data format %s is not supported, supported data formats are: 
'binary' and 'ascii'\n",
-                                       data_format);
+                                       p->data_format);
        exit(EXIT_FAILURE);
        
        }
@@ -206,6 +213,17 @@
        exit(EXIT_FAILURE);
 }
 
+if (p->gradient) {
+    if (!validate_color(p->gradient_color_1, p->om)) {
+           fprintf(stderr, "The first gradient color is invalid. It must be 
HTML color of the form '#xxxxxx'.\n");
+           exit(EXIT_FAILURE);
+    }
+    if (!validate_color(p->gradient_color_2, p->om)) {
+           fprintf(stderr, "The second gradient color is invalid. It must be 
HTML color of the form '#xxxxxx'.\n");
+           exit(EXIT_FAILURE);
+    }
+}
+
 // In case color is not html format set bgcol and col to predefinedint values
 p->col = 6;
 if (strcmp(p->color, "black") == 0) p->col = 0;
@@ -219,7 +237,6 @@
 // default if invalid
 
 // validate: background color
-p->bgcol = -1;
 if (strcmp(p->bcolor, "black") == 0) p->bgcol = 0;
 if (strcmp(p->bcolor, "red") == 0) p->bgcol = 1;
 if (strcmp(p->bcolor, "green") == 0) p->bgcol = 2;
@@ -325,6 +342,10 @@
        inputMethod = (char *)iniparser_getstring(ini, "input:method", "pulse");
 #endif
 
+//setting sndio to defaualt if supported
+#ifdef SNDIO
+       inputMethod = (char *)iniparser_getstring(ini, "input:method", "sndio");
+#endif
 
 #ifdef NCURSES
        outputMethod = (char *)iniparser_getstring(ini, "output:method", 
"ncurses");
@@ -361,7 +382,7 @@
 // config: output
 channels =  (char *)iniparser_getstring(ini, "output:channels", "stereo");
 p->raw_target = (char *)iniparser_getstring(ini, "output:raw_target", 
"/dev/stdout");
-data_format = (char *)iniparser_getstring(ini, "output:data_format", "binary");
+p->data_format = (char *)iniparser_getstring(ini, "output:data_format", 
"binary");
 p->bar_delim = (char)iniparser_getint(ini, "output:bar_delimiter", 59);
 p->frame_delim = (char)iniparser_getint(ini, "output:frame_delimiter", 10);
 p->ascii_range = iniparser_getint(ini, "output:ascii_max_range", 1000);
@@ -402,6 +423,12 @@
        p->im = 3;
        p->audio_source = (char *)iniparser_getstring(ini, "input:source", 
"auto");
 }
+#ifdef SNDIO
+if (strcmp(inputMethod, "sndio") == 0) {
+       p->im = 4;
+       p->audio_source = (char *)iniparser_getstring(ini, "input:source", 
SIO_DEVANY);
+}
+#endif
 
 validate_config(supportedInput, params);
 //iniparser_freedict(ini);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/configure.ac new/cava-0.6.1/configure.ac
--- old/cava-0.6.0/configure.ac 2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/configure.ac 2018-05-03 18:07:33.000000000 +0200
@@ -36,6 +36,11 @@
        AC_MSG_ERROR([no pthread.h header header file found])
 )
 
+dnl ######################
+dnl checking for alloca.h
+dnl ######################
+
+AC_CHECK_HEADER([alloca.h], [CPPFLAGS="$CPPFLAGS -DHAVE_ALLOCA_H"])
 
 dnl ######################
 dnl checking for alsa dev
@@ -65,6 +70,19 @@
     fi
 
 dnl ######################
+dnl checking for sndio dev
+dnl ######################
+AC_CHECK_LIB(sndio, sio_open, have_sndio=yes, have_sndio=no)
+    if [[ $have_sndio = "yes" ]] ; then
+      LIBS="$LIBS -lsndio"
+      CPPFLAGS="$CPPFLAGS -DSNDIO"
+    fi
+
+    if [[ $have_sndio = "no" ]] ; then
+      AC_MSG_NOTICE([WARNING: No sndio dev files found building without sndio 
support])
+    fi
+
+dnl ######################
 dnl checking for math lib
 dnl ######################
 AC_CHECK_LIB(m, sqrt, have_m=yes, have_m=no)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/input/alsa.c new/cava-0.6.1/input/alsa.c
--- old/cava-0.6.0/input/alsa.c 2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/input/alsa.c 2018-05-03 18:07:33.000000000 +0200
@@ -35,6 +35,12 @@
                exit(EXIT_FAILURE);
        }
 
+    if ((err = snd_pcm_prepare (*handle)) < 0) {
+    fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
+             snd_strerror (err));
+    exit (EXIT_FAILURE);
+    }
+
        // getting actual format
        snd_pcm_hw_params_get_format(params, (snd_pcm_format_t*)&sample_rate);
        // converting result to number of bits
@@ -90,33 +96,57 @@
 #define FRAMES_NUMBER 256
 
 void* input_alsa(void* data) {
+    int err;
        struct audio_data* audio = (struct audio_data*)data;
        snd_pcm_t* handle;
        snd_pcm_uframes_t frames = FRAMES_NUMBER;
-
+    int16_t buf[FRAMES_NUMBER * 2];
        initialize_audio_parameters(&handle, audio, &frames);
-
        // frames * bits/8 * channels
        const int size = frames * (audio->format / 8) * CHANNELS_COUNT;
        signed char* buffer = malloc(size);
+    int n = 0;
+
        while (1) {
-               int err = snd_pcm_readi(handle, buffer, frames);
-               if (err == -EPIPE) {
-                       /* EPIPE means overrun */
-                       #ifdef DEBUG
-                               fprintf(stderr, "overrun occurred\n");
-                       #endif
-                       snd_pcm_prepare(handle);
-               } else if (err < 0) {
-                       #ifdef DEBUG
-                               fprintf(stderr, "error from read: %s\n", 
snd_strerror(err));
-                       #endif
-               } else if (err != (int)frames) {
-                       #ifdef DEBUG
-                               fprintf(stderr, "short read, read %d %d 
frames\n", err, (int)frames);
-                       #endif
-               }
-               fill_audio_outs(audio, buffer, size);
+        switch (audio->format) {
+        case 16:
+            err = snd_pcm_readi(handle, buf, frames);
+               for (int i = 0; i < FRAMES_NUMBER * 2; i += 2) {
+                if (audio->channels == 1) audio->audio_out_l[n] = (buf[i] + 
buf[i + 1]) / 2;
+                //stereo storing channels in buffer
+                if (audio->channels == 2) {
+                        audio->audio_out_l[n] = buf[i];
+                        audio->audio_out_r[n] = buf[i + 1];
+                        }
+                n++;
+                if (n == 2048 - 1)n = 0;
+            }
+            break;
+        default:
+                   err = snd_pcm_readi(handle, buffer, frames);
+            fill_audio_outs(audio, buffer, size);
+            break;
+        }
+
+           if (err == -EPIPE) {
+                   /* EPIPE means overrun */
+                   #ifdef DEBUG
+                           fprintf(stderr, "overrun occurred\n");
+                   #endif
+        snd_pcm_prepare(handle);
+           } else if (err < 0) {
+                   #ifdef DEBUG
+                           fprintf(stderr, "error from read: %s\n", 
snd_strerror(err));
+                   #endif
+           } else if (err != (int)frames) {
+                   #ifdef DEBUG
+                           fprintf(stderr, "short read, read %d %d frames\n", 
err, (int)frames);
+                   #endif
+           }
+
+
+
+
                if (audio->terminate == 1) {
                        free(buffer);
                        snd_pcm_close(handle);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/input/fifo.c new/cava-0.6.1/input/fifo.c
--- old/cava-0.6.0/input/fifo.c 2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/input/fifo.c 2018-05-03 18:07:33.000000000 +0200
@@ -1,3 +1,5 @@
+#include <unistd.h>
+#define BUFSIZE 1024
 int rc;
 
 struct audio_data {
@@ -10,8 +12,17 @@
         int im; //input mode alsa, fifo or pulse
         int channels;
        int terminate; // shared variable used to terminate audio thread
+        char error_message[1024];
 };
 
+int open_fifo(const char *path)
+{
+       int fd = open(path, O_RDONLY);
+       int flags = fcntl(fd, F_GETFL, 0);
+       fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+       return fd;
+}
+
 
 //input: FIFO
 void* input_fifo(void* data)
@@ -19,36 +30,52 @@
        struct audio_data *audio = (struct audio_data *)data;
        int fd;
        int n = 0;
-       signed char buf[1024];
-       int tempr, templ, lo;
-       int q, i;
+       //signed char buf[1024];
+       //int tempr, templ, lo, q;
+       int i;
        int t = 0;
-       int size = 1024;
+       //int size = 1024;
        int bytes = 0;
-       int flags;
+       int16_t buf[BUFSIZE / 2];
        struct timespec req = { .tv_sec = 0, .tv_nsec = 10000000 };
 
 
 
 
-       fd = open(audio->source, O_RDONLY);
-       flags = fcntl(fd, F_GETFL, 0);
-       fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+       fd = open_fifo(audio->source);
 
        while (1) {
 
                bytes = read(fd, buf, sizeof(buf));
 
-               if (bytes == -1) { //if no bytes read sleep 10ms and zero 
shared buffer
+               if (bytes < 1) { //if no bytes read sleep 10ms and zero shared 
buffer
                        nanosleep (&req, NULL);
                        t++;
                        if (t > 10) {
                                for (i = 0; i < 2048; i++)audio->audio_out_l[i] 
= 0;
                                for (i = 0; i < 2048; i++)audio->audio_out_r[i] 
= 0;
+                               close(fd);
+                               fd = open_fifo(audio->source);
                                t = 0;
                        }
                } else { //if bytes read go ahead
                        t = 0;
+
+            for (i = 0; i < BUFSIZE / 2; i += 2) {
+
+                if (audio->channels == 1) audio->audio_out_l[n] = (buf[i] + 
buf[i + 1]) / 2;
+
+                //stereo storing channels in buffer
+                if (audio->channels == 2) {
+                        audio->audio_out_l[n] = buf[i];
+                        audio->audio_out_r[n] = buf[i + 1];
+                        }
+
+                n++;
+                if (n == 2048 - 1) n = 0;
+        }
+
+/*
                        for (q = 0; q < (size / 4); q++) {
 
                                tempr = ( buf[ 4 * q + 3] << 2);
@@ -76,9 +103,12 @@
                                        audio->audio_out_r[n] = tempr;
                                        }
 
+
+
                                n++;
                                if (n == 2048 - 1)n = 0;
                        }
+*/
                }
 
                if (audio->terminate == 1) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/input/pulse.c new/cava-0.6.1/input/pulse.c
--- old/cava-0.6.0/input/pulse.c        2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/input/pulse.c        2018-05-03 18:07:33.000000000 +0200
@@ -52,11 +52,12 @@
        pulseaudio_context, cb, userdata));
        break;
        case PA_CONTEXT_FAILED:
-       //printf("FAILED\n");
+       printf("failed to coennect to pulseaudio server\n");
+       exit(EXIT_FAILURE);
        break;
        case PA_CONTEXT_TERMINATED:
-       //printf("TERMINATED\n");
-    pa_mainloop_quit(m_pulseaudio_mainloop, 0);
+       printf("TERMINATED\n");
+       pa_mainloop_quit(m_pulseaudio_mainloop, 0);
        break;    
        }
 }
@@ -65,7 +66,7 @@
 void getPulseDefaultSink(void* data) {
 
 
-    struct audio_data *audio = (struct audio_data *)data;
+       struct audio_data *audio = (struct audio_data *)data;
        pa_mainloop_api *mainloop_api;
        pa_context *pulseaudio_context;
        int ret;
@@ -76,31 +77,43 @@
        mainloop_api = pa_mainloop_get_api(m_pulseaudio_mainloop);
        pulseaudio_context = pa_context_new(mainloop_api, "cava device list");
 
+
        // This function connects to the pulse server
        pa_context_connect(pulseaudio_context, NULL, PA_CONTEXT_NOFLAGS,
                               NULL);
 
 
+//        printf("connecting to server\n");
+
        //This function defines a callback so the server will tell us its state.
        pa_context_set_state_callback(pulseaudio_context,
                                          pulseaudio_context_state_callback,
                                          (void*)audio);
 
+
+
        //starting a mainloop to get default sink
-       if (pa_mainloop_run(m_pulseaudio_mainloop, &ret) < 0)
-       {
-       printf("Could not open pulseaudio mainloop to "
-                                         "find default device name: %d",
-                  ret);
-       }
+
+       //starting with one nonblokng iteration in case pulseaudio is not able 
to run
+       if (!(ret = pa_mainloop_iterate(m_pulseaudio_mainloop, 0, &ret))){
+        printf("Could not open pulseaudio mainloop to "
+                                          "find default device name: %d\n"
+                                        "check if pulseaudio is running\n",
+                   ret);
+
+        exit(EXIT_FAILURE);
+        }
+
+       pa_mainloop_run(m_pulseaudio_mainloop, &ret);
+       
 
 }
 
 void* input_pulse(void* data)
 {
 
-        struct audio_data *audio = (struct audio_data *)data;
-        int i, n;
+    struct audio_data *audio = (struct audio_data *)data;
+    int i, n;
        int16_t buf[BUFSIZE / 2];
 
        /* The sample type to use */
@@ -118,8 +131,10 @@
        int error;
 
        if (!(s = pa_simple_new(NULL, "cava", PA_STREAM_RECORD, audio->source, 
"audio for cava", &ss, NULL, &pb, &error))) {
-               fprintf(stderr, __FILE__": Could not open pulseaudio source: 
%s, %s. To find a list of your pulseaudio sources run 'pacmd 
list-sources'\n",audio->source, pa_strerror(error));
-               exit(EXIT_FAILURE);
+               //fprintf(stderr, __FILE__": Could not open pulseaudio source: 
%s, %s. To find a list of your pulseaudio sources run 'pacmd 
list-sources'\n",audio->source, pa_strerror(error));
+        sprintf(audio->error_message, __FILE__": Could not open pulseaudio 
source: %s, %s. To find a list of your pulseaudio sources run 'pacmd 
list-sources'\n",audio->source, pa_strerror(error));
+               audio->terminate = 1;
+        pthread_exit(NULL);
        }
 
        n = 0;
@@ -127,8 +142,11 @@
        while (1) {
                /* Record some data ... */
                if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
-                       fprintf(stderr, __FILE__": pa_simple_read() failed: 
%s\n", pa_strerror(error));
-               exit(EXIT_FAILURE);
+            //fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", 
pa_strerror(error));
+               //exit(EXIT_FAILURE);
+            sprintf(audio->error_message, __FILE__": pa_simple_read() failed: 
%s\n", pa_strerror(error));
+            audio->terminate = 1;
+            pthread_exit(NULL);
                }
 
                 //sorting out channels
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/input/sndio.c new/cava-0.6.1/input/sndio.c
--- old/cava-0.6.0/input/sndio.c        1970-01-01 01:00:00.000000000 +0100
+++ new/cava-0.6.1/input/sndio.c        2018-05-03 18:07:33.000000000 +0200
@@ -0,0 +1,63 @@
+#include <assert.h>
+#include <errno.h>
+#include <sndio.h>
+#include <string.h>
+
+void* input_sndio(void* data)
+{
+       struct audio_data *audio = (struct audio_data *)data;
+       struct sio_par par;
+       struct sio_hdl *hdl;
+       int16_t buf[256];
+       unsigned int i, n, channels;
+
+       assert(audio->channels > 0);
+       channels = audio->channels;
+
+       sio_initpar(&par);
+       par.sig = 1;
+       par.bits = 16;
+       par.le = 1;
+       par.rate = 44100;
+       par.rchan = channels;
+       par.appbufsz = sizeof(buf) / channels;
+
+       if ((hdl = sio_open(audio->source, SIO_REC, 0)) == NULL) {
+               fprintf(stderr, __FILE__": Could not open sndio source: %s\n", 
audio->source);
+               exit(EXIT_FAILURE);
+       }
+
+       if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) || par.sig != 1 || 
par.le != 1 || par.rate != 44100 || par.rchan != channels) {
+               fprintf(stderr, __FILE__": Could not set required audio 
parameters\n");
+               exit(EXIT_FAILURE);
+       }
+
+       if (!sio_start(hdl)) {
+               fprintf(stderr, __FILE__": sio_start() failed\n");
+               exit(EXIT_FAILURE);
+       }
+
+       n = 0;
+       while (audio->terminate != 1) {
+               if (sio_read(hdl, buf, sizeof(buf)) == 0) {
+                       fprintf(stderr, __FILE__": sio_read() failed: %s\n", 
strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+
+               for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i += 2) {
+                       if (par.rchan == 1) {
+                               // sndiod has already taken care of averaging 
the samples
+                               audio->audio_out_l[n] = buf[i];
+                       } else if (par.rchan == 2) {
+                               audio->audio_out_l[n] = buf[i];
+                               audio->audio_out_r[n] = buf[i + 1];
+                       }
+                       n = (n + 1) % 2048;
+               }
+       }
+
+       sio_stop(hdl);
+       sio_close(hdl);
+
+       return 0;
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/output/raw.c new/cava-0.6.1/output/raw.c
--- old/cava-0.6.0/output/raw.c 2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/output/raw.c 2018-05-03 18:07:33.000000000 +0200
@@ -1,41 +1,34 @@
 #include <stdio.h>
 #include <stdint.h>
-
-#define TEN_THSND 10000
-#define TEN_THSND_F 10000.0
-#define BIT_16 16
-#define BIT_8 8
-
-#define NORMALIZE_AND_WRITE(type) _NORMALIZE_AND_WRITE(type)
-#define _NORMALIZE_AND_WRITE(type) \
-       for (int i = 0; i < bars_count; i++) { \
-               uint##type##_t f_##type = UINT##type##_MAX; \
-               if (f[i] < TEN_THSND) \
-                       f_##type *= f[i] / TEN_THSND_F; \
-               write(fd, &f_##type, sizeof(uint##type##_t)); \
-       }
+int16_t buf_16;
+int8_t buf_8;
 
 int print_raw_out(int bars_count, int fd, int is_binary, int bit_format,
 int ascii_range, char bar_delim, char frame_delim, const int const f[200]) {
        if (is_binary) {
-               switch (bit_format) {
-               case BIT_16:
-                       NORMALIZE_AND_WRITE(BIT_16);
-                       break;
-               case BIT_8:
-                       NORMALIZE_AND_WRITE(BIT_8);
-                       break;
-               }
+        for (int i = 0; i < bars_count; i++) {
+            int f_limited = f[i];
+            if (f_limited > (pow(2, bit_format) - 1)) f_limited = pow(2, 
bit_format) - 1;
+
+                   switch (bit_format) {
+                   case 16:
+                buf_16 = f_limited;
+                           write(fd, &buf_16, sizeof(int16_t));
+                           break;
+                   case 8:
+                buf_8 = f_limited;
+                           write(fd, &buf_8, sizeof(int8_t));
+                           break;
+                   }
+        }
        } else { // ascii
                for (int i = 0; i < bars_count; i++) {
-                       int f_ranged = (f[i] / TEN_THSND_F) * ascii_range;
-                       if (f_ranged > ascii_range)
-                               f_ranged = ascii_range;
+                       int f_ranged = f[i];
+                       if (f_ranged > ascii_range) f_ranged = ascii_range;
 
                        // finding size of number-string in byte
                        int bar_height_size = 2; // a number + \0
-                       if (f_ranged != 0)
-                               bar_height_size += floor (log10 (f_ranged));
+                       if (f_ranged != 0) bar_height_size += floor (log10 
(f_ranged));
 
                        char bar_height[bar_height_size];
                        snprintf(bar_height, bar_height_size, "%d", f_ranged);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/output/terminal_noncurses.c 
new/cava-0.6.1/output/terminal_noncurses.c
--- old/cava-0.6.0/output/terminal_noncurses.c  2017-08-26 10:52:40.000000000 
+0200
+++ new/cava-0.6.1/output/terminal_noncurses.c  2018-05-03 18:07:33.000000000 
+0200
@@ -1,6 +1,7 @@
 #include <locale.h>
 #include <wchar.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <termios.h>
 #include <unistd.h>
 
@@ -57,7 +58,6 @@
        }
 
        col += 30;
-       bgcol += 40;
 
        system("setterm -cursor off");
        system("setterm -blank 0");
@@ -71,9 +71,11 @@
 
        printf("\033[1m"); //setting "bright" color mode, looks cooler... I 
think
 
-       if (bgcol != 0)
+       if (bgcol != 0) {
+
+        bgcol += 40;
                printf("\033[%dm", bgcol);
-       {
+       
                for (n = (h); n >= 0; n--) {
                        for (i = 0; i < w; i++) {
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cava-0.6.0/todo new/cava-0.6.1/todo
--- old/cava-0.6.0/todo 2017-08-26 10:52:40.000000000 +0200
+++ new/cava-0.6.1/todo 2018-05-03 18:07:33.000000000 +0200
@@ -1,11 +1,13 @@
 TODO
 ----
 
-* switch to libconfig
+
+* config option print cut-off frequencies on x-axis
+* config option different color for different threshold amplitude
+* configurable left OR right when in mono
+* switch to libconfig ?
+* downloag iniconfig from git instad of bundle
 * possibility to save settings to config file
 * openGL
 * plug-in api
-* 256 colors (https://github.com/dpayne/cli-visualizer#256-colors)
-* explore possibilities of true colors (https://gist.github.com/XVilka/8346728)
-
 * new demo video


Reply via email to