fixed
This commit is contained in:
parent
f17b2c7eee
commit
9cc92ed38e
2
audio_vis.sh
Normal file → Executable file
2
audio_vis.sh
Normal file → Executable file
@ -1,2 +1,2 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
arecord --buffer-size=128 -Dloopout -MNqc1 -fS24_LE -traw 2> /dev/null | hexdump -e '/4 "%d "' | ./spark
|
arecord -r 48000 --buffer-size=1024 -Dloopout -MNqc1 -fS16_LE -traw 2> /dev/null | ./spark
|
||||||
|
@ -1,75 +1,10 @@
|
|||||||
#include <fcntl.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#define ARG_SIZE 50
|
|
||||||
|
|
||||||
struct winsize ws;
|
|
||||||
|
|
||||||
int max;
|
|
||||||
int min;
|
|
||||||
|
|
||||||
int args;
|
|
||||||
size_t middle;
|
|
||||||
int add_value(const char *str) {
|
|
||||||
if (args > (int)ws.ws_col)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
int val1 = atoi(str);
|
|
||||||
|
|
||||||
int val2 = val1;
|
|
||||||
if (val2 < 0)
|
|
||||||
val2 *= -1;
|
|
||||||
|
|
||||||
if (val2 > max)
|
|
||||||
max = val2;
|
|
||||||
|
|
||||||
else if (val2 < min)
|
|
||||||
min = val2;
|
|
||||||
|
|
||||||
int k = (val2 - min) * (middle - 5) / ((max - min) + 1);
|
|
||||||
if (val1 > 0)
|
|
||||||
mvprintw(middle - k, args, "@");
|
|
||||||
|
|
||||||
else
|
|
||||||
mvprintw(middle + k, args, "@");
|
|
||||||
|
|
||||||
args++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void stdin_read(void) {
|
|
||||||
char arg[ARG_SIZE + 1];
|
|
||||||
char *p = arg;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
int c = getchar();
|
|
||||||
if (c == EOF)
|
|
||||||
return;
|
|
||||||
|
|
||||||
else if (c == ' ' && p != arg) {
|
|
||||||
*p = '\0';
|
|
||||||
p = arg;
|
|
||||||
|
|
||||||
if (add_value(arg))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
*p = c;
|
|
||||||
if (p + 1 == arg + sizeof(arg))
|
|
||||||
break;
|
|
||||||
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sig_handler(int sig) {
|
void sig_handler(int sig) {
|
||||||
(void)sig;
|
(void)sig;
|
||||||
@ -81,6 +16,8 @@ void sig_handler(int sig) {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
signal(SIGTERM, sig_handler);
|
signal(SIGTERM, sig_handler);
|
||||||
|
|
||||||
|
struct winsize ws;
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -89,12 +26,22 @@ int main(void) {
|
|||||||
curs_set(0);
|
curs_set(0);
|
||||||
timeout(0);
|
timeout(0);
|
||||||
|
|
||||||
middle = ws.ws_row / 2;
|
size_t middle = ws.ws_row / 2;
|
||||||
while (1) {
|
|
||||||
args = 0;
|
|
||||||
|
|
||||||
clear();
|
size_t args = 0;
|
||||||
stdin_read();
|
while (1) {
|
||||||
refresh();
|
if (args > ws.ws_col) {
|
||||||
|
refresh();
|
||||||
|
clear();
|
||||||
|
args = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int val1;
|
||||||
|
read(STDIN_FILENO, &val1, sizeof(val1));
|
||||||
|
|
||||||
|
int k = val1 * (middle - 5) / INT_MAX;
|
||||||
|
mvprintw(middle + k, args, "@");
|
||||||
|
|
||||||
|
args++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user