|
|
|
|
@ -137,12 +137,13 @@ int *separate_freq_bands(int FFTbassbufferSize, fftw_complex out_bass[FFTbassbuf |
|
|
|
|
int FFTmidbufferSize, fftw_complex out_mid[FFTmidbufferSize / 2 + 1], |
|
|
|
|
int FFTtreblebufferSize, |
|
|
|
|
fftw_complex out_treble[FFTtreblebufferSize / 2 + 1], int bass_cut_off_bar, |
|
|
|
|
int treble_cut_off_bar, int number_of_bars, int lcf[256], int hcf[256], |
|
|
|
|
int treble_cut_off_bar, int number_of_bars, |
|
|
|
|
int FFTbuffer_lower_cut_off[256], int FFTbuffer_upper_cut_off[256], |
|
|
|
|
double eq[256], int channel, double sens, double ignore) { |
|
|
|
|
int n, i; |
|
|
|
|
double peak[257]; |
|
|
|
|
static int fl[256]; |
|
|
|
|
static int fr[256]; |
|
|
|
|
static int bars_left[256]; |
|
|
|
|
static int bars_right[256]; |
|
|
|
|
double y[FFTbassbufferSize / 2 + 1]; |
|
|
|
|
double temp; |
|
|
|
|
|
|
|
|
|
@ -153,7 +154,7 @@ int *separate_freq_bands(int FFTbassbufferSize, fftw_complex out_bass[FFTbassbuf |
|
|
|
|
i = 0; |
|
|
|
|
|
|
|
|
|
// process: get peaks
|
|
|
|
|
for (i = lcf[n]; i <= hcf[n]; i++) { |
|
|
|
|
for (i = FFTbuffer_lower_cut_off[n]; i <= FFTbuffer_upper_cut_off[n]; i++) { |
|
|
|
|
if (n <= bass_cut_off_bar) { |
|
|
|
|
y[i] = hypot(out_bass[i][0], out_bass[i][1]); |
|
|
|
|
} else if (n > bass_cut_off_bar && n <= treble_cut_off_bar) { |
|
|
|
|
@ -165,21 +166,22 @@ int *separate_freq_bands(int FFTbassbufferSize, fftw_complex out_bass[FFTbassbuf |
|
|
|
|
peak[n] += y[i]; // adding upp band
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
peak[n] = peak[n] / (hcf[n] - lcf[n] + 1); // getting average
|
|
|
|
|
peak[n] = peak[n] / |
|
|
|
|
(FFTbuffer_upper_cut_off[n] - FFTbuffer_lower_cut_off[n] + 1); // getting average
|
|
|
|
|
temp = peak[n] * sens * eq[n]; // multiplying with k and sens
|
|
|
|
|
// printf("%d peak o: %f * sens: %f * k: %f = f: %f\n", o, peak[o], sens, eq[o], temp);
|
|
|
|
|
if (temp <= ignore) |
|
|
|
|
temp = 0; |
|
|
|
|
if (channel == LEFT_CHANNEL) |
|
|
|
|
fl[n] = temp; |
|
|
|
|
bars_left[n] = temp; |
|
|
|
|
else |
|
|
|
|
fr[n] = temp; |
|
|
|
|
bars_right[n] = temp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (channel == LEFT_CHANNEL) |
|
|
|
|
return fl; |
|
|
|
|
return bars_left; |
|
|
|
|
else |
|
|
|
|
return fr; |
|
|
|
|
return bars_right; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int *monstercat_filter(int *bars, int number_of_bars, int waves, double monstercat) { |
|
|
|
|
@ -227,7 +229,7 @@ int main(int argc, char **argv) { |
|
|
|
|
int thr_id GCC_UNUSED; |
|
|
|
|
float cut_off_frequency[256]; |
|
|
|
|
float relative_cut_off[256]; |
|
|
|
|
int bars[256], lcf[256], hcf[256]; |
|
|
|
|
int bars[256], FFTbuffer_lower_cut_off[256], FFTbuffer_upper_cut_off[256]; |
|
|
|
|
int *bars_left, *bars_right, *bars_mono; |
|
|
|
|
int bars_mem[256]; |
|
|
|
|
int bars_last[256]; |
|
|
|
|
@ -586,14 +588,15 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
// handle for user setting too many bars
|
|
|
|
|
if (p.fixedbars) { |
|
|
|
|
p.autobars = 0; |
|
|
|
|
if (p.fixedbars * p.bar_width + p.fixedbars * p.bs - p.bs > width) |
|
|
|
|
if (p.fixedbars * p.bar_width + p.fixedbars * p.bar_spacing - p.bar_spacing > width) |
|
|
|
|
p.autobars = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// getting orignial numbers of barss incase of resize
|
|
|
|
|
if (p.autobars == 1) { |
|
|
|
|
number_of_bars = (width + p.bs) / (p.bar_width + p.bs); |
|
|
|
|
// if (p.bs != 0) number_of_bars = (width - number_of_bars * p.bs + p.bs) / bar_width;
|
|
|
|
|
number_of_bars = (width + p.bar_spacing) / (p.bar_width + p.bar_spacing); |
|
|
|
|
// if (p.bar_spacing != 0) number_of_bars = (width - number_of_bars * p.bar_spacing
|
|
|
|
|
// + p.bar_spacing) / bar_width;
|
|
|
|
|
} else |
|
|
|
|
number_of_bars = p.fixedbars; |
|
|
|
|
|
|
|
|
|
@ -608,7 +611,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// checks if there is stil extra room, will use this to center
|
|
|
|
|
rest = (width - number_of_bars * p.bar_width - number_of_bars * p.bs + p.bs) / 2; |
|
|
|
|
rest = (width - number_of_bars * p.bar_width - number_of_bars * p.bar_spacing + |
|
|
|
|
p.bar_spacing) / |
|
|
|
|
2; |
|
|
|
|
if (rest < 0) |
|
|
|
|
rest = 0; |
|
|
|
|
|
|
|
|
|
@ -619,19 +624,22 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
double integral = p.integral * sqrt(log10(lines / 3 + 1)); |
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG |
|
|
|
|
printw("height: %d width: %d bars:%d bar width: %d rest: %d\n", width, lines, number_of_bars, p.bar_width, rest); |
|
|
|
|
printw("height: %d width: %d bars:%d bar width: %d rest: %d\n", width, lines, |
|
|
|
|
number_of_bars, p.bar_width, rest); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (p.stereo) |
|
|
|
|
number_of_bars = number_of_bars / 2; // in stereo onle half number of number_of_bars per channel
|
|
|
|
|
number_of_bars = |
|
|
|
|
number_of_bars / 2; // in stereo onle half number of number_of_bars per channel
|
|
|
|
|
|
|
|
|
|
if (p.userEQ_enabled && (number_of_bars > 0)) { |
|
|
|
|
userEQ_keys_to_bars_ratio = (double)(((double)p.userEQ_keys) / ((double)number_of_bars)); |
|
|
|
|
userEQ_keys_to_bars_ratio = |
|
|
|
|
(double)(((double)p.userEQ_keys) / ((double)number_of_bars)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// calculate frequency constant (used to distribute bars across the frequency band)
|
|
|
|
|
double frequency_constant = |
|
|
|
|
log10((float)p.lower_cut_off / (float)p.upper_cut_off) / (1 / ((float)number_of_bars + 1) - 1); |
|
|
|
|
double frequency_constant = log10((float)p.lower_cut_off / (float)p.upper_cut_off) / |
|
|
|
|
(1 / ((float)number_of_bars + 1) - 1); |
|
|
|
|
|
|
|
|
|
// process: calculate cutoff frequencies and eq
|
|
|
|
|
int bass_cut_off_bar = -1; |
|
|
|
|
@ -641,7 +649,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
|
|
|
|
|
for (n = 0; n < number_of_bars + 1; n++) { |
|
|
|
|
double bar_distribution_coefficient = frequency_constant * (-1); |
|
|
|
|
bar_distribution_coefficient += ((float)n + 1) / ((float)number_of_bars + 1) * frequency_constant; |
|
|
|
|
bar_distribution_coefficient += |
|
|
|
|
((float)n + 1) / ((float)number_of_bars + 1) * frequency_constant; |
|
|
|
|
cut_off_frequency[n] = p.upper_cut_off * pow(10, bar_distribution_coefficient); |
|
|
|
|
relative_cut_off[n] = cut_off_frequency[n] / (audio.rate / 2); |
|
|
|
|
// remember nyquist!, pr my calculations this should be rate/2
|
|
|
|
|
@ -652,34 +661,45 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
eq[n] *= (float)height / pow(2, 28); |
|
|
|
|
if (p.userEQ_enabled) |
|
|
|
|
eq[n] *= p.userEQ[(int)floor(((double)n) * userEQ_keys_to_bars_ratio)]; |
|
|
|
|
|
|
|
|
|
eq[n] /= log2(audio.FFTbassbufferSize); |
|
|
|
|
// lfc stores the lower cut frequency foo each bar in the fft out buffer
|
|
|
|
|
|
|
|
|
|
if (cut_off_frequency[n] < bass_cut_off) { |
|
|
|
|
lcf[n] = relative_cut_off[n] * (audio.FFTbassbufferSize / 2) + 1; |
|
|
|
|
// BASS
|
|
|
|
|
FFTbuffer_lower_cut_off[n] = |
|
|
|
|
relative_cut_off[n] * (audio.FFTbassbufferSize / 2) + 1; |
|
|
|
|
bass_cut_off_bar++; |
|
|
|
|
treble_cut_off_bar++; |
|
|
|
|
|
|
|
|
|
eq[n] *= log2(audio.FFTbassbufferSize); |
|
|
|
|
} else if (cut_off_frequency[n] > bass_cut_off && cut_off_frequency[n] < treble_cut_off) { |
|
|
|
|
lcf[n] = relative_cut_off[n] * (audio.FFTmidbufferSize / 2) + 1; |
|
|
|
|
} else if (cut_off_frequency[n] > bass_cut_off && |
|
|
|
|
cut_off_frequency[n] < treble_cut_off) { |
|
|
|
|
// MID
|
|
|
|
|
FFTbuffer_lower_cut_off[n] = |
|
|
|
|
relative_cut_off[n] * (audio.FFTmidbufferSize / 2) + 1; |
|
|
|
|
treble_cut_off_bar++; |
|
|
|
|
if ((treble_cut_off_bar - bass_cut_off_bar) == 1) { |
|
|
|
|
first_bar = true; |
|
|
|
|
hcf[n - 1] = relative_cut_off[n] * (audio.FFTbassbufferSize / 2); |
|
|
|
|
if (hcf[n - 1] < lcf[n - 1]) |
|
|
|
|
hcf[n - 1] = lcf[n - 1]; |
|
|
|
|
FFTbuffer_upper_cut_off[n - 1] = |
|
|
|
|
relative_cut_off[n] * (audio.FFTbassbufferSize / 2); |
|
|
|
|
if (FFTbuffer_upper_cut_off[n - 1] < FFTbuffer_lower_cut_off[n - 1]) |
|
|
|
|
FFTbuffer_upper_cut_off[n - 1] = FFTbuffer_lower_cut_off[n - 1]; |
|
|
|
|
} else { |
|
|
|
|
first_bar = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
eq[n] *= log2(audio.FFTmidbufferSize); |
|
|
|
|
} else { |
|
|
|
|
lcf[n] = relative_cut_off[n] * (audio.FFTtreblebufferSize / 2) + 1; |
|
|
|
|
// TREBLE
|
|
|
|
|
FFTbuffer_lower_cut_off[n] = |
|
|
|
|
relative_cut_off[n] * (audio.FFTtreblebufferSize / 2) + 1; |
|
|
|
|
first_treble_bar++; |
|
|
|
|
if (first_treble_bar == 1) { |
|
|
|
|
first_bar = true; |
|
|
|
|
hcf[n - 1] = relative_cut_off[n] * (audio.FFTmidbufferSize / 2); |
|
|
|
|
if (hcf[n - 1] < lcf[n - 1]) |
|
|
|
|
hcf[n - 1] = lcf[n - 1]; |
|
|
|
|
FFTbuffer_upper_cut_off[n - 1] = |
|
|
|
|
relative_cut_off[n] * (audio.FFTmidbufferSize / 2); |
|
|
|
|
if (FFTbuffer_upper_cut_off[n - 1] < FFTbuffer_lower_cut_off[n - 1]) |
|
|
|
|
FFTbuffer_upper_cut_off[n - 1] = FFTbuffer_lower_cut_off[n - 1]; |
|
|
|
|
} else { |
|
|
|
|
first_bar = false; |
|
|
|
|
} |
|
|
|
|
@ -688,18 +708,21 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (n != 0 && !first_bar) { |
|
|
|
|
hcf[n - 1] = lcf[n] - 1; |
|
|
|
|
FFTbuffer_upper_cut_off[n - 1] = FFTbuffer_lower_cut_off[n] - 1; |
|
|
|
|
|
|
|
|
|
// pushing the spectrum up if the expe function gets "clumped"
|
|
|
|
|
if (lcf[n] <= lcf[n - 1]) |
|
|
|
|
lcf[n] = lcf[n - 1] + 1; |
|
|
|
|
hcf[n - 1] = lcf[n] - 1; |
|
|
|
|
// pushing the spectrum up if the exponential function gets "clumped" in the
|
|
|
|
|
// bass
|
|
|
|
|
if (FFTbuffer_lower_cut_off[n] <= FFTbuffer_lower_cut_off[n - 1]) |
|
|
|
|
FFTbuffer_lower_cut_off[n] = FFTbuffer_lower_cut_off[n - 1] + 1; |
|
|
|
|
FFTbuffer_upper_cut_off[n - 1] = FFTbuffer_lower_cut_off[n] - 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG |
|
|
|
|
if (n != 0) { |
|
|
|
|
mvprintw(n, 0, "%d: %f -> %f (%d -> %d) bass: %d, treble:%d \n", n, cut_off_frequency[n - 1], |
|
|
|
|
cut_off_frequency[n], lcf[n - 1], hcf[n - 1], bass_cut_off_bar, treble_cut_off_bar); |
|
|
|
|
mvprintw(n, 0, "%d: %f -> %f (%d -> %d) bass: %d, treble:%d \n", n, |
|
|
|
|
cut_off_frequency[n - 1], cut_off_frequency[n], |
|
|
|
|
FFTbuffer_lower_cut_off[n - 1], FFTbuffer_upper_cut_off[n - 1], |
|
|
|
|
bass_cut_off_bar, treble_cut_off_bar); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
@ -814,17 +837,17 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
fftw_execute(p_treble_l); |
|
|
|
|
fftw_execute(p_treble_r); |
|
|
|
|
|
|
|
|
|
bars_left = separate_freq_bands(audio.FFTbassbufferSize, out_bass_l, |
|
|
|
|
audio.FFTmidbufferSize, out_mid_l, |
|
|
|
|
audio.FFTtreblebufferSize, out_treble_l, |
|
|
|
|
bass_cut_off_bar, treble_cut_off_bar, number_of_bars / 2, |
|
|
|
|
lcf, hcf, eq, LEFT_CHANNEL, p.sens, p.ignore); |
|
|
|
|
bars_left = separate_freq_bands( |
|
|
|
|
audio.FFTbassbufferSize, out_bass_l, audio.FFTmidbufferSize, out_mid_l, |
|
|
|
|
audio.FFTtreblebufferSize, out_treble_l, bass_cut_off_bar, |
|
|
|
|
treble_cut_off_bar, number_of_bars / 2, FFTbuffer_lower_cut_off, |
|
|
|
|
FFTbuffer_upper_cut_off, eq, LEFT_CHANNEL, p.sens, p.ignore); |
|
|
|
|
|
|
|
|
|
bars_right = separate_freq_bands(audio.FFTbassbufferSize, out_bass_r, |
|
|
|
|
audio.FFTmidbufferSize, out_mid_r, |
|
|
|
|
audio.FFTtreblebufferSize, out_treble_r, |
|
|
|
|
bass_cut_off_bar, treble_cut_off_bar, number_of_bars / 2, |
|
|
|
|
lcf, hcf, eq, RIGHT_CHANNEL, p.sens, p.ignore); |
|
|
|
|
bars_right = separate_freq_bands( |
|
|
|
|
audio.FFTbassbufferSize, out_bass_r, audio.FFTmidbufferSize, out_mid_r, |
|
|
|
|
audio.FFTtreblebufferSize, out_treble_r, bass_cut_off_bar, |
|
|
|
|
treble_cut_off_bar, number_of_bars / 2, FFTbuffer_lower_cut_off, |
|
|
|
|
FFTbuffer_upper_cut_off, eq, RIGHT_CHANNEL, p.sens, p.ignore); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
fftw_execute(p_bass_l); |
|
|
|
|
@ -833,7 +856,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
bars_mono = separate_freq_bands( |
|
|
|
|
audio.FFTbassbufferSize, out_bass_l, audio.FFTmidbufferSize, out_mid_l, |
|
|
|
|
audio.FFTtreblebufferSize, out_treble_l, bass_cut_off_bar, |
|
|
|
|
treble_cut_off_bar, number_of_bars, lcf, hcf, eq, LEFT_CHANNEL, p.sens, p.ignore); |
|
|
|
|
treble_cut_off_bar, number_of_bars, FFTbuffer_lower_cut_off, |
|
|
|
|
FFTbuffer_upper_cut_off, eq, LEFT_CHANNEL, p.sens, p.ignore); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { //**if in sleep mode wait and continue**//
|
|
|
|
|
@ -851,10 +875,13 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
|
|
|
|
|
if (p.monstercat) { |
|
|
|
|
if (p.stereo) { |
|
|
|
|
bars_left = monstercat_filter(bars_left, number_of_bars / 2, p.waves, p.monstercat); |
|
|
|
|
bars_right = monstercat_filter(bars_right, number_of_bars / 2, p.waves, p.monstercat); |
|
|
|
|
bars_left = |
|
|
|
|
monstercat_filter(bars_left, number_of_bars / 2, p.waves, p.monstercat); |
|
|
|
|
bars_right = monstercat_filter(bars_right, number_of_bars / 2, p.waves, |
|
|
|
|
p.monstercat); |
|
|
|
|
} else { |
|
|
|
|
bars_mono = monstercat_filter(bars_mono, number_of_bars, p.waves, p.monstercat); |
|
|
|
|
bars_mono = |
|
|
|
|
monstercat_filter(bars_mono, number_of_bars, p.waves, p.monstercat); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -903,7 +930,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
#ifndef NDEBUG |
|
|
|
|
mvprintw(n, 0, "%d: f:%f->%f (%d->%d), k-value:\
|
|
|
|
|
%15e, peak:%d \n", |
|
|
|
|
n, cut_off_frequency[n], cut_off_frequency[n + 1], lcf[n], hcf[n], eq[n], bars[n]); |
|
|
|
|
n, cut_off_frequency[n], cut_off_frequency[n + 1], |
|
|
|
|
FFTbuffer_lower_cut_off[n], FFTbuffer_upper_cut_off[n], eq[n], |
|
|
|
|
bars[n]); |
|
|
|
|
// if(bars[n] > maxvalue) maxvalue = bars[n];
|
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
@ -931,16 +960,18 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co |
|
|
|
|
switch (output_mode) { |
|
|
|
|
case OUTPUT_NCURSES: |
|
|
|
|
#ifdef NCURSES |
|
|
|
|
rc = draw_terminal_ncurses(inAtty, lines, width, number_of_bars, p.bar_width, p.bs, rest, bars, previous_frame, |
|
|
|
|
rc = draw_terminal_ncurses(inAtty, lines, width, number_of_bars, p.bar_width, |
|
|
|
|
p.bar_spacing, rest, bars, previous_frame, |
|
|
|
|
p.gradient); |
|
|
|
|
break; |
|
|
|
|
#endif |
|
|
|
|
case OUTPUT_NONCURSES: |
|
|
|
|
rc = draw_terminal_noncurses(inAtty, lines, width, number_of_bars, p.bar_width, p.bs, rest, bars, previous_frame); |
|
|
|
|
rc = draw_terminal_noncurses(inAtty, lines, width, number_of_bars, p.bar_width, |
|
|
|
|
p.bar_spacing, rest, bars, previous_frame); |
|
|
|
|
break; |
|
|
|
|
case OUTPUT_RAW: |
|
|
|
|
rc = print_raw_out(number_of_bars, fp, p.is_bin, p.bit_format, p.ascii_range, p.bar_delim, |
|
|
|
|
p.frame_delim, bars); |
|
|
|
|
rc = print_raw_out(number_of_bars, fp, p.is_bin, p.bit_format, p.ascii_range, |
|
|
|
|
p.bar_delim, p.frame_delim, bars); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|