all: remove include *.c from cava.c

add common.h and some stuff to make it compiled
master
Chelovechishko 9 years ago
parent 6a07a23fcb
commit 6e27b5a9c1
  1. 14
      Makefile.am
  2. 176
      cava.c
  3. 23
      common.h
  4. 10
      configure.ac
  5. 13
      input/alsa.c
  6. 129
      input/fifo.c
  7. 1
      input/fifo.h
  8. 25
      input/pulse.c
  9. 8
      output/raw.c
  10. 5
      output/raw.h
  11. 6
      output/terminal_bcircle.c
  12. 4
      output/terminal_bcircle.h
  13. 35
      output/terminal_ncurses.c
  14. 12
      output/terminal_ncurses.h
  15. 10
      output/terminal_noncurses.c
  16. 6
      output/terminal_noncurses.h

@ -14,7 +14,7 @@ cava_LDADD = -liniparser
cava_LDFLAGS = -L/usr/local/lib -Wl,-rpath /usr/local/lib
cava_CPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" \
-D_POSIX_SOURCE -D _POSIX_C_SOURCE=200809L
cava_CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-result -Wno-maybe-uninitialized
cava_CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-result -Wno-maybe-uninitialized
cava_font_dir = @FONT_DIR@
cava_font__DATA = cava.psf
@ -25,4 +25,16 @@ if !SYSTEM_LIBINIPARSER
cava_CPPFLAGS += -Iiniparser/src
endif
cava_SOURCES += input/fifo.c output/raw.c output/terminal_noncurses.c
if HAVE_ALSA
cava_SOURCES += input/alsa.c
endif
if HAVE_PULSE
cava_SOURCES += input/pulse.c
endif
if HAVE_CURSES
cava_SOURCES += output/terminal_ncurses.c output/terminal_bcircle.c
endif

176
cava.c

@ -1,25 +1,16 @@
#define _XOPEN_SOURCE_EXTENDED
#include <alloca.h>
#include <locale.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <termios.h>
#include <math.h>
#include <fcntl.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <fftw3.h>
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <getopt.h>
#include <pthread.h>
#include <dirent.h>
@ -27,34 +18,23 @@
#ifdef NCURSES
#include <curses.h>
#include "output/terminal_ncurses.h"
#include "output/terminal_ncurses.c"
#include "output/terminal_bcircle.h"
#include "output/terminal_bcircle.c"
#endif
#include "output/terminal_noncurses.h"
#include "output/terminal_noncurses.c"
#include "output/raw.h"
#include "output/raw.c"
#include "input/fifo.h"
#include "input/fifo.c"
#ifdef ALSA
#include <alsa/asoundlib.h>
#include "input/alsa.h"
#include "input/alsa.c"
#endif
#ifdef PULSE
#include "input/pulse.h"
#include "input/pulse.c"
#endif
#include <iniparser.h>
@ -93,7 +73,7 @@ int bgcol = -1;
int bars = 25;
int autobars = 1;
int stereo = -1;
int M = 2048;
int M = AUDIO_OUT_SIZE;
int is_bin = 1;
char bar_delim = ';';
char frame_delim = '\n';
@ -139,7 +119,7 @@ void load_config(char configPath[255])
{
FILE *fp;
//config: creating path to default config file
if (configPath[0] == '\0') {
char *configFile = "config";
@ -155,13 +135,13 @@ FILE *fp;
exit(EXIT_FAILURE);
}
}
// config: create directory
mkdir(configPath, 0777);
// config: adding default filename file
strcat(configPath, configFile);
fp = fopen(configPath, "ab+");
if (fp) {
fclose(fp);
@ -173,7 +153,7 @@ FILE *fp;
} else { //opening specified file
fp = fopen(configPath, "rb+");
fp = fopen(configPath, "rb+");
if (fp) {
fclose(fp);
} else {
@ -186,11 +166,11 @@ FILE *fp;
ini = iniparser_load(configPath);
//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
@ -371,7 +351,7 @@ void validate_config()
if (strcmp(outputMethod, "raw") == 0) {//raw:
om = 4;
autosens = 0;
//checking data format
if (strcmp(data_format, "binary") == 0) {
is_bin = 1;
@ -381,7 +361,7 @@ void validate_config()
"bit format %d is not supported, supported data formats are: '8' and '16'\n",
bit_format );
exit(EXIT_FAILURE);
}
} else if (strcmp(data_format, "ascii") == 0) {
is_bin = 0;
@ -395,7 +375,7 @@ void validate_config()
"data format %s is not supported, supported data formats are: 'binary' and 'ascii'\n",
data_format);
exit(EXIT_FAILURE);
}
@ -414,7 +394,7 @@ void validate_config()
"output method %s is not supported, supported methods are: 'ncurses' and 'noncurses'\n",
outputMethod);
exit(EXIT_FAILURE);
#endif
#endif
}
// validate: output style
@ -488,7 +468,7 @@ void validate_config()
if (strcmp(bcolor, "cyan") == 0) bgcol = 6;
if (strcmp(bcolor, "white") == 0) bgcol = 7;
// default if invalid
// validate: gravity
if (gravity < 0) {
@ -509,7 +489,7 @@ void validate_config()
"lower cutoff frequency can't be higher than higher cutoff frequency\n");
exit(EXIT_FAILURE);
}
//setting sens
sens = sens / 100;
@ -531,15 +511,15 @@ static bool directory_exists(const char * path) {
#endif
int * separate_freq_bands(fftw_complex out[M / 2 + 1][2], int bars, int lcf[200], int hcf[200], float k[200], int channel) {
int * separate_freq_bands(fftw_complex out[M / 2 + 1][2], int bars, int lcf[FRAMES_BUFFER_SIZE], int hcf[FRAMES_BUFFER_SIZE], float k[FRAMES_BUFFER_SIZE], int channel) {
int o,i;
float peak[201];
static int fl[200];
static int fr[200];
static int fl[FRAMES_BUFFER_SIZE];
static int fr[FRAMES_BUFFER_SIZE];
int y[M / 2 + 1];
float temp;
// process: separate frequency bands
for (o = 0; o < bars; o++) {
@ -550,10 +530,10 @@ int * separate_freq_bands(fftw_complex out[M / 2 + 1][2], int bars, int lcf[200]
y[i] = pow(pow(*out[i][0], 2) + pow(*out[i][1], 2), 0.5); //getting r of compex
peak[o] += y[i]; //adding upp band
}
peak[o] = peak[o] / (hcf[o]-lcf[o]+1); //getting average
temp = peak[o] * k[o] * sens; //multiplying with k and adjusting to sens settings
if (temp <= ignore)temp = 0;
@ -564,7 +544,7 @@ int * separate_freq_bands(fftw_complex out[M / 2 + 1][2], int bars, int lcf[200]
if (channel == 1) return fl;
else return fr;
}
}
int * monstercat_filter (int * f, int bars) {
@ -616,20 +596,20 @@ int main(int argc, char **argv)
pthread_t p_thread;
int thr_id GCC_UNUSED;
int modes = 3; // amount of smoothing modes
float fc[200];
float fre[200];
int f[200], lcf[200], hcf[200];
float fc[FRAMES_BUFFER_SIZE];
float fre[FRAMES_BUFFER_SIZE];
int f[FRAMES_BUFFER_SIZE], lcf[FRAMES_BUFFER_SIZE], hcf[FRAMES_BUFFER_SIZE];
int *fl, *fr;
int fmem[200];
int flast[200];
int flastd[200];
int fmem[FRAMES_BUFFER_SIZE];
int flast[FRAMES_BUFFER_SIZE];
int flastd[FRAMES_BUFFER_SIZE];
int sleep = 0;
int i, n, o, height, h, w, c, rest, inAtty, silence, fp, fptest;
float temp;
//int cont = 1;
int fall[200];
float fpeak[200];
float k[200];
int fall[FRAMES_BUFFER_SIZE];
float fpeak[FRAMES_BUFFER_SIZE];
float k[FRAMES_BUFFER_SIZE];
float g;
struct timespec req = { .tv_sec = 0, .tv_nsec = 0 };
char configPath[255];
@ -646,12 +626,12 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
char ch = '\0';
double inr[2 * (M / 2 + 1)];
double inl[2 * (M / 2 + 1)];
//int maxvalue = 0;
// general: console title
printf("%c]0;%s%c", '\033', PACKAGE, '\007');
configPath[0] = '\0';
setlocale(LC_ALL, "");
@ -695,7 +675,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//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_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);
@ -705,13 +685,13 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//config: load & validate
load_config(configPath);
validate_config();
validate_config();
if (om != 4) {
if (om != 4) {
// Check if we're running in a Virtual console todo: replace virtual console with terminal emulator
inAtty = 0;
if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAtty = 1;
if (inAtty) {
system("setfont cava.psf >/dev/null 2>&1");
system("setterm -blank 0");
@ -722,7 +702,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//input: init
audio.format = -1;
audio.rate = 0;
audio.terminate = 0;
audio.terminate = false;
if (stereo) audio.channels = 2;
if (!stereo) audio.channels = 1;
@ -747,9 +727,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
thr_id = pthread_create(&p_thread, NULL, input_alsa,
(void *)&audio); //starting alsamusic listener
n = 0;
while (audio.format == -1 || audio.rate == 0) {
req.tv_sec = 0;
req.tv_nsec = 1000000;
@ -773,7 +753,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (im == 2) {
thr_id = pthread_create(&p_thread, NULL, input_fifo, (void*)&audio); //starting fifomusic listener
audio.rate = 44100;
audio.rate = SAMPLE_RATE;
}
#ifdef PULSE
@ -784,7 +764,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
}
else sourceIsAuto = 0;
thr_id = pthread_create(&p_thread, NULL, input_pulse, (void*)&audio); //starting pulsemusic listener
audio.rate = 44100;
audio.rate = SAMPLE_RATE;
}
#endif
@ -795,14 +775,14 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
);
exit(EXIT_FAILURE);
}
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++) {
for (i = 0; i < FRAMES_BUFFER_SIZE; i++) {
flast[i] = 0;
flastd[i] = 0;
fall[i] = 0;
@ -848,11 +828,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
printf("could not open file %s for writing\n",raw_target);
exit(1);
}
printf("open file %s for writing raw ouput\n",raw_target);
printf("open file %s for writing raw ouput\n",raw_target);
//height and with must be hardcoded for raw output.
h = 112;
w = 200;
w = 200;
}
//handle for user setting too many bars
@ -875,7 +855,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (bars%2 != 0) bars--;
}
height = h - 1;
@ -896,7 +876,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//output: start noncurses mode
if (om == 3) init_terminal_noncurses(col, bgcol, w, h, bw);
if (stereo) bars = bars / 2; // in stereo onle half number of bars per channel
@ -906,7 +886,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
double freqconst = log10((float)lowcf / (float)highcf) / ((float)1 / ((float)bars + (float)1) - 1);
//freqconst = -2;
// process: calculate cutoff frequencies
@ -931,10 +911,10 @@ 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*4000)) * smooth[(int)floor(((double)n) * smh)];
if (stereo) bars = bars * 2;
bool resizeTerminal = FALSE;
if (stereo) bars = bars * 2;
bool resizeTerminal = false;
while (!resizeTerminal) {
@ -952,11 +932,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break;
case 68: // key right
bw++;
resizeTerminal = TRUE;
resizeTerminal = true;
break;
case 67: // key left
if (bw > 1) bw--;
resizeTerminal = TRUE;
resizeTerminal = true;
break;
case 'm':
if (mode == modes) {
@ -971,12 +951,12 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
case 'c': //change forground color
if (col < 7) col++;
else col = 0;
resizeTerminal = TRUE;
resizeTerminal = true;
break;
case 'b': //change backround color
if (bgcol < 7) bgcol++;
else bgcol = 0;
resizeTerminal = TRUE;
resizeTerminal = true;
break;
case 'q':
@ -986,8 +966,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (should_reload) {
reloadConf = TRUE;
resizeTerminal = TRUE;
reloadConf = true;
resizeTerminal = true;
should_reload = 0;
}
@ -999,7 +979,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
refresh();
#endif
// process: populate input buffer and check if input is present
// process: populate input buffer and check if input is present
silence = 1;
for (i = 0; i < (2 * (M / 2 + 1)); i++) {
if (i < M) {
@ -1028,10 +1008,10 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
} else {
fftw_execute(pl);
fl = separate_freq_bands(outl,bars,lcf,hcf, k, 1);
}
}
}
}
else { //**if in sleep mode wait and continue**//
#ifdef DEBUG
printw("no sound detected for 3 sec, going to sleep mode\n");
@ -1049,11 +1029,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (monstercat) {
if (stereo) {
fl = monstercat_filter(fl, bars / 2);
fr = monstercat_filter(fr, bars / 2);
fr = monstercat_filter(fr, bars / 2);
} else {
fl = monstercat_filter(fl, bars);
}
}
@ -1112,7 +1092,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
f[o] = 1;
if (om == 4) f[o] = 0;
}
//if(f[o] > maxvalue) maxvalue = f[o];
//if(f[o] > maxvalue) maxvalue = f[o];
}
//printf("%d\n",maxvalue); //checking maxvalue I keep forgetting its about 10000
@ -1121,11 +1101,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (autosens && om != 4) {
for (o = 0; o < bars; o++) {
if (f[o] > height * 8 + height * 8 * overshoot / 100) {
senseLow = FALSE;
senseLow = false;
sens = sens * 0.99;
break;
}
if (senseLow && !silence) sens = sens * 1.01;
if (senseLow && !silence) sens = sens * 1.01;
}
}
@ -1150,7 +1130,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
break;
}
if (rc == -1) resizeTerminal = TRUE; //terminal has been resized breaking to recalibrating values
if (rc == -1) resizeTerminal = true; //terminal has been resized breaking to recalibrating values
if (framerate <= 1) {
req.tv_sec = 1 / (float)framerate;
@ -1161,18 +1141,18 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
nanosleep (&req, NULL);
#endif
for (o = 0; o < bars; o++) {
for (o = 0; o < bars; o++) {
flastd[o] = f[o];
}
}
}
}//reloading config
req.tv_sec = 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;
audio.terminate = true;
pthread_join( p_thread, NULL);
if (customEQ) free(smooth);

@ -0,0 +1,23 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#define AUDIO_OUT_SIZE 2048
#define BUFFER_SIZE 1024
// assuming stereo
#define CHANNELS_COUNT 2
#define SAMPLE_RATE 44100
#define FRAMES_BUFFER_SIZE 200
struct audio_data {
int audio_out_r[AUDIO_OUT_SIZE];
int audio_out_l[AUDIO_OUT_SIZE];
int8_t format;
uint8_t channels;
bool terminate; // shared variable used to terminate audio thread
unsigned int rate;
char *source; // alsa device, fifo path or pulse source
};

@ -41,6 +41,7 @@ dnl ######################
dnl checking for alsa dev
dnl ######################
AC_CHECK_LIB(asound, snd_pcm_open, have_alsa=yes, have_alsa=no)
AM_CONDITIONAL(HAVE_ALSA, test "x$have_alsa" = "xyes")
if [[ $have_alsa = "yes" ]] ; then
LIBS="$LIBS -lasound"
CPPFLAGS="$CPPFLAGS -DALSA"
@ -55,6 +56,7 @@ dnl ######################
dnl checking for pulse dev
dnl ######################
AC_CHECK_LIB(pulse-simple, pa_simple_new, have_pulse=yes, have_pulse=no)
AM_CONDITIONAL(HAVE_PULSE, test "x$have_pulse" = "xyes")
if [[ $have_pulse = "yes" ]] ; then
LIBS="$LIBS -lpulse-simple -lpulse"
CPPFLAGS="$CPPFLAGS -DPULSE"
@ -78,7 +80,7 @@ AC_CHECK_LIB(m, sqrt, have_m=yes, have_m=no)
dnl ######################
dnl checking for fftw3
dnl checking for fftw3
dnl ######################
AC_CHECK_LIB(fftw3,fftw_execute, have_fftw=yes, have_fftw=no)
if [[ $have_fftw = "yes" ]] ; then
@ -101,6 +103,7 @@ AC_CHECK_LIB(ncursesw, initscr,
)
AC_CHECK_LIB($curses_lib, initscr,
AM_CONDITIONAL(HAVE_CURSES, test "$CURSES_CONFIG" != "")
if test "$CURSES_CONFIG" = "" ; then
LIBS="$LIBS -l$curses_lib"
CPPFLAGS="$CPPFLAGS -DNCURSES"
@ -163,8 +166,3 @@ fi
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

@ -1,8 +1,9 @@
// input: ALSA
#include <alsa/asoundlib.h>
#include <alloca.h>
#include <stdlib.h>
// assuming stereo
#define CHANNELS_COUNT 2
#define SAMPLE_RATE 44100
#include "common.h"
#include "alsa.h"
static void initialize_audio_parameters(snd_pcm_t** handle, struct audio_data* audio,
snd_pcm_uframes_t* frames) {
@ -83,7 +84,7 @@ const int size) {
}
++audio_out_buffer_index;
audio_out_buffer_index %= 2048;
audio_out_buffer_index %= AUDIO_OUT_SIZE;
}
}
@ -117,7 +118,7 @@ void* input_alsa(void* data) {
#endif
}
fill_audio_outs(audio, buffer, size);
if (audio->terminate == 1) {
if (audio->terminate) {
free(buffer);
snd_pcm_close(handle);
return NULL;

@ -1,90 +1,71 @@
struct audio_data {
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
int audio_out_r[2048];
int audio_out_l[2048];
int format;
unsigned int rate ;
char *source; //alsa device, fifo path or pulse source
int im; //input mode alsa, fifo or pulse
int channels;
int terminate; // shared variable used to terminate audio thread
};
#include "common.h"
#include "fifo.h"
//input: FIFO
void* input_fifo(void* data)
{
void* input_fifo(void* data) {
struct audio_data *audio = (struct audio_data *)data;
int fd;
int n = 0;
signed char buf[1024];
int tempr, templ, lo;
int q, i;
int t = 0;
int size = 1024;
int bytes = 0;
int flags;
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);
int file_descriptor = open(audio->source, O_RDONLY);
int flags = fcntl(file_descriptor, F_GETFL, 0);
fcntl(file_descriptor, F_SETFL, flags | O_NONBLOCK);
int audio_out_index = 0;
int attempts_count = 0;
signed char buf[BUFFER_SIZE];
while (1) {
bytes = read(fd, buf, sizeof(buf));
if (bytes == -1) { //if no bytes read sleep 10ms and zero shared buffer
int bytes = read(file_descriptor, buf, sizeof(buf));
if (bytes == -1) { // if no bytes read sleep 10ms and zero shared buffer
struct timespec req = { .tv_sec = 0, .tv_nsec = 10000000 };
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;
t = 0;
attempts_count++;
if (attempts_count > 10) {
memset(audio->audio_out_l, 0,
AUDIO_OUT_SIZE * sizeof(audio->audio_out_l));
memset(audio->audio_out_r, 0,
AUDIO_OUT_SIZE * sizeof(audio->audio_out_l));
attempts_count = 0;
}
} else { //if bytes read go ahead
t = 0;
for (q = 0; q < (size / 4); q++) {
tempr = ( buf[ 4 * q + 3] << 2);
lo = ( buf[4 * q + 2] >> 6);
if (lo < 0)lo = abs(lo) + 1;
if (tempr >= 0)tempr = tempr + lo;
else tempr = tempr - lo;
templ = ( buf[ 4 * q + 1] << 2);
lo = ( buf[ 4 * q] >> 6);
if (lo < 0)lo = abs(lo) + 1;
if (templ >= 0)templ = templ + lo;
else templ = templ - lo;
if (audio->channels == 1) audio->audio_out_l[n] = (tempr +
templ) /
2;
//stereo storing channels in buffer
if (audio->channels == 2) {
audio->audio_out_l[n] = templ;
audio->audio_out_r[n] = tempr;
} else { // if bytes read go ahead
attempts_count = 0;
for (int q = 0; q < (BUFFER_SIZE / 4); q++) {
int tempr = (buf[4 * q + 3] << 2);
int lo = (buf[4 * q + 2] >> 6);
if (lo < 0)
lo = abs(lo) + 1;
if (tempr >= 0)
tempr += lo;
else
tempr -= lo;
int templ = (buf[ 4 * q + 1] << 2);
lo = (buf[ 4 * q] >> 6);
if (lo < 0)
lo = abs(lo) + 1;
if (templ >= 0)
templ += lo;
else
templ -= lo;
if (audio->channels == 1)
audio->audio_out_l[audio_out_index] = (tempr + templ) / 2;
else { //stereo storing channels in buffer
audio->audio_out_l[audio_out_index] = templ;
audio->audio_out_r[audio_out_index] = tempr;
}
n++;
if (n == 2048 - 1)n = 0;
audio_out_index++;
audio_out_index %= AUDIO_OUT_SIZE;
}
}
if (audio->terminate == 1) {
close(fd);
if (audio->terminate) {
close(file_descriptor);
break;
}
}
return 0;
return NULL;
}

@ -1,2 +1,3 @@
//header files for fifo, part of cava
void* input_fifo(void* data);

@ -1,11 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <pulse/simple.h>
#include <pulse/error.h>
#include <pulse/pulseaudio.h>
#define BUFSIZE 1024
#include "common.h"
#include "pulse.h"
pa_mainloop *m_pulseaudio_mainloop;
@ -13,7 +16,7 @@ void cb(__attribute__((unused)) pa_context *pulseaudio_context, const pa_server_
//getting default sink name
struct audio_data *audio = (struct audio_data *)userdata;
audio->source = malloc(sizeof(char) * 1024);
audio->source = malloc(sizeof(char) * BUFFER_SIZE);
strcpy(audio->source,i->default_sink_name);
@ -31,7 +34,7 @@ void cb(__attribute__((unused)) pa_context *pulseaudio_context, const pa_server_
void pulseaudio_context_state_callback(pa_context *pulseaudio_context,
void *userdata) {
//make sure loop is ready
//make sure loop is ready
switch (pa_context_get_state(pulseaudio_context))
{
case PA_CONTEXT_UNCONNECTED:
@ -57,7 +60,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;
}
}
@ -101,17 +104,17 @@ void* input_pulse(void* data)
struct audio_data *audio = (struct audio_data *)data;
int i, n;
int16_t buf[BUFSIZE / 2];
int16_t buf[BUFFER_SIZE / 2];
/* The sample type to use */
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,
.rate = SAMPLE_RATE,
.channels = 2
};
static const pa_buffer_attr pb = {
.maxlength = BUFSIZE * 2,
.fragsize = BUFSIZE
.maxlength = BUFFER_SIZE * 2,
.fragsize = BUFFER_SIZE
};
pa_simple *s = NULL;
@ -123,7 +126,7 @@ void* input_pulse(void* data)
}
n = 0;
while (1) {
/* Record some data ... */
if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
@ -133,7 +136,7 @@ void* input_pulse(void* data)
//sorting out channels
for (i = 0; i < BUFSIZE / 2; i += 2) {
for (i = 0; i < BUFFER_SIZE / 2; i += 2) {
if (audio->channels == 1) audio->audio_out_l[n] = (buf[i] + buf[i + 1]) / 2;
@ -147,7 +150,7 @@ void* input_pulse(void* data)
if (n == 2048 - 1)n = 0;
}
if (audio->terminate == 1) {
if (audio->terminate) {
pa_simple_free(s);
break;
}

@ -1,5 +1,9 @@
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "raw.h"
#define TEN_THSND 10000
#define TEN_THSND_F 10000.0
@ -16,7 +20,7 @@
}
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]) {
int ascii_range, char bar_delim, char frame_delim, const int f[FRAMES_BUFFER_SIZE]) {
if (is_binary) {
switch (bit_format) {
case BIT_16:

@ -1,2 +1,5 @@
#include "common.h"
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]);
int ascii_range, char bar_delim, char frame_delim,
const int f[FRAMES_BUFFER_SIZE]);

@ -1,10 +1,12 @@
#include <curses.h>
#include <ncursesw/curses.h>
#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "terminal_bcircle.h"
#ifndef M_PI
#define M_PI 3.141592
#endif
@ -36,7 +38,7 @@ void get_terminal_dim_bcircle(int *w, int *h) {
}
int draw_terminal_bcircle(int tty, int h, int w, int f[200]) {
int draw_terminal_bcircle(int tty, int h, int w, int f[FRAMES_BUFFER_SIZE]) {
const wchar_t* bars[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"};

@ -1,5 +1,7 @@
#include "common.h"
int init_terminal_bcircle(int col, int bgcol);
void get_terminal_dim_bcircle(int *w, int *h);
int draw_terminal_bcircle(int virt, int height, int width, int f[200]);
int draw_terminal_bcircle(int virt, int height, int width,
int f[FRAMES_BUFFER_SIZE]);
void cleanup_terminal_bcircle(void);

@ -1,7 +1,9 @@
#include <curses.h>
#include <ncursesw/curses.h>
#include <wchar.h>
#include <stdlib.h>
#include "terminal_ncurses.h"
int gradient_size = 64;
struct colors {
@ -87,20 +89,20 @@ 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) {
short unsigned int rgb[3][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;
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]);
for (int n = 0; n < gradient_size; n++) {
@ -109,8 +111,8 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi
if (rgb[2][i] > 255) rgb[2][i] = 0;
if ( n > gradient_size * 0.85 ) rgb[2][i] = rgb[1][i];
}
sprintf(next_color,"#%02x%02x%02x",rgb[2][0], rgb[2][1], rgb[2][2]);
sprintf(next_color,"#%02hx%02hx%02hx",rgb[2][0], rgb[2][1], rgb[2][2]);
change_color_definition(n + 1, next_color, n + 1);
init_pair(color_pair_number++, n + 1, bg_color_number);
@ -126,7 +128,7 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi
}
void change_colors(int cur_height, int tot_height) {
static void change_colors(int cur_height, int tot_height) {
tot_height /= gradient_size ;
if (tot_height < 1) tot_height = 1;
cur_height /= tot_height;
@ -143,8 +145,9 @@ void get_terminal_dim_ncurses(int* width, int* height) {
#define TERMINAL_RESIZED -1
int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width,
int bars_count, int bar_width, int bar_spacing, int rest, const int f[200],
int flastd[200], int gradient) {
int bars_count, int bar_width, int bar_spacing, int rest,
const int f[FRAMES_BUFFER_SIZE], int flastd[FRAMES_BUFFER_SIZE],
int gradient) {
const wchar_t* bar_heights[] = {L"\u2581", L"\u2582", L"\u2583",
L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"};
@ -162,19 +165,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++)
@ -191,7 +194,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",

@ -1,8 +1,12 @@
#include "common.h"
void init_terminal_ncurses(char* const fg_color_string,
char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradient,
char* const gradient_color_1, char* const gradient_color_2,int* width, int* height);
char* const bg_color_string, int predef_fg_color, int predef_bg_color,
int gradient, char* const gradient_color_1, char* const gradient_color_2,
int* width, int* height);
void get_terminal_dim_ncurses(int* width, int* height);
int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width,
int bars_count, int bar_width, int bar_spacing, int rest, const int f[200],
int flastd[200], int gradient);
int bars_count, int bar_width, int bar_spacing, int rest,
const int f[FRAMES_BUFFER_SIZE], int flastd[FRAMES_BUFFER_SIZE],
int gradient);
void cleanup_terminal_ncurses(void);

@ -1,15 +1,21 @@
#include <locale.h>
#include <wchar.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include "terminal_noncurses.h"
wchar_t barstring[8][100];
int ttybarstring[8];
char spacestring[100];
int setecho(int fd, int onoff) {
static int setecho(int fd, int onoff) {
struct termios t;

@ -1,4 +1,8 @@
#include "common.h"
int init_terminal_noncurses(int col, int bgcol, int w, int h, int bw);
void get_terminal_dim_noncurses(int *w, int *h);
int draw_terminal_noncurses(int virt, int height, int width, int bars, int bw, int bs, int rest, int f[200], int flastd[200]);
int draw_terminal_noncurses(int virt, int height, int width, int bars, int bw,
int bs, int rest, int f[FRAMES_BUFFER_SIZE],
int flastd[FRAMES_BUFFER_SIZE]);
void cleanup_terminal_noncurses(void);

Loading…
Cancel
Save