This commit is contained in:
Your Name 2024-04-01 20:46:47 +03:00
parent 84d2041fd6
commit 71bcd4d370
3 changed files with 23 additions and 16 deletions

View File

@ -5,6 +5,6 @@
~ # modprobe snd-aloop
~ $ cc spark_ncurses.c -lm -lncurses -s -ospark
~ $ cc spark_ncurses.c -lncurses -s -ospark
~ $ chmod +x audio_vis.sh
~ $ ./audio_vis.sh

0
audio_vis.sh Executable file → Normal file
View File

View File

@ -7,7 +7,6 @@
#include <ncurses.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <math.h>
#define NARGS 1024
#define ARG_SIZE 50
@ -61,6 +60,14 @@ void sig_handler(int sig) {
exit(0);
}
void print(int y, int x, char *str, int val) {
if (val < 0)
mvprintw(y, x, "%s", str);
else
mvprintw(y, x, "%s", str);
}
int main(void) {
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
@ -82,24 +89,24 @@ int main(void) {
clear();
for (int i = 0; i < args; i++) {
if (values[i] < min)
min = values[i];
int val = values[i];
if (val < 0)
val *= -1;
else if (values[i] > max)
max = values[i];
if (val < min)
min = val;
int val = (values[i] - min) * 10 / ((max - min) + 1);
for (int j = 0; j < val; j++) {
mvprintw(middle - 2 - j, i, "#");
mvprintw(middle + 2 + j, i, "#");
else if (val > max)
max = val;
int lvl = (val - min) * (ws.ws_row / 5) / ((max - min) + 1);
for (int j = 0; j < lvl; j++) {
print(middle - j, i, "$", values[i]);
print(middle + j, i, "$", values[i]);
}
}
/* Vol */
int val = (values[args - 1] - min) * ws.ws_col / ((max - min) + 1);
for (int j = 0; j < val; j++) {
mvprintw(middle - 1, ws.ws_col - j, "<=");
mvprintw(middle + 1, ws.ws_col - j, "<=");
print(middle - lvl, i, ".", values[i]);
print(middle + lvl, i, "'", values[i]);
}
refresh();