implemented autosens for raw

master
karlstav 8 years ago
parent 2de93cc243
commit 58cb1d3c7f
  1. 28
      cava.c
  2. 13
      config.c
  3. 11
      output/raw.c

@ -443,6 +443,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
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) {
@ -477,9 +479,17 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
}
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
@ -504,10 +514,10 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
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
@ -567,7 +577,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*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;
@ -727,10 +737,10 @@ 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) * 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
@ -754,9 +764,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//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 ) {
if (f[o] > height ) {
senseLow = FALSE;
p.sens = p.sens * 0.985;
break;

@ -6,12 +6,12 @@ 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};
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;
@ -125,11 +125,10 @@ if (strcmp(outputMethod, "noncurses") == 0) {
}
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 ) {
@ -139,7 +138,7 @@ if (strcmp(outputMethod, "raw") == 0) {//raw:
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,
@ -149,7 +148,7 @@ if (strcmp(outputMethod, "raw") == 0) {//raw:
} 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);
}
@ -372,7 +371,7 @@ p->highcf = iniparser_getint(ini, "general:higher_cutoff_freq", 10000);
// 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);

@ -10,8 +10,7 @@
#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; \
f_##type *= f[i]; \
write(fd, &f_##type, sizeof(uint##type##_t)); \
}
@ -28,14 +27,12 @@ int ascii_range, char bar_delim, char frame_delim, const int const f[200]) {
}
} 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);

Loading…
Cancel
Save