This commit is contained in:
usr 2024-03-30 17:11:03 +03:00
parent 0160622031
commit 84d2041fd6
2 changed files with 29 additions and 47 deletions

View File

@ -1,2 +1,2 @@
#!/bin/sh
arecord --rate 10000 --buffer-size=1024 -D loopout -MNqc 1 -f S24_LE -t raw | hexdump -e '/4 " %d"' | tr -d '*' | ./spark
arecord --buffer-size=128 -Dloopout -MNqc1 -fS24_LE -traw 2> /dev/null | hexdump -e '/4 "%d "' | ./spark

View File

@ -9,35 +9,19 @@
#include <ctype.h>
#include <math.h>
#define NARGS 4096
#define NARGS 1024
#define ARG_SIZE 50
#define MAX 1000000
#define MIN 90000
int args;
double values[NARGS + 1];
int values[NARGS + 1];
struct winsize ws;
int parse_double(const char *str, double *res) {
char *ptr;
*res = strtod(str, &ptr);
if (*ptr)
return 0;
return 1;
}
int add_value(const char *str) {
if (args >= sizeof(values) / sizeof(double) || args > ws.ws_col)
if (args >= sizeof(values) / sizeof(int) || args > ws.ws_col)
return 1;
double val = 0;
if (!parse_double(str, &val))
return 1;
values[args] = val;
values[args] = atoi(str);
args++;
return 0;
@ -47,7 +31,6 @@ void stdin_read(void) {
char arg[ARG_SIZE + 1];
char *p = arg;
fflush(stdin);
while (1) {
int c = getchar();
if (c == EOF)
@ -71,26 +54,6 @@ void stdin_read(void) {
}
}
void print(double value, double diff, int col) {
if (col % 2)
return;
int lvl = 0;
if (value > 0)
lvl = (int)round((value - MIN + 1) / diff);
else
lvl = (int)round(((value * -1) - MIN + 1) / diff);
for (int i = 0; i < lvl; i++) {
if (value > 0)
mvprintw((ws.ws_row / 2) - i, col, "$");
else
mvprintw((ws.ws_row / 2) + i, col, "$");
}
}
void sig_handler(int sig) {
(void)sig;
@ -100,25 +63,44 @@ void sig_handler(int sig) {
int main(void) {
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
return 1;
initscr();
noecho();
curs_set(0);
timeout(0);
double diff = MAX - MIN + 1;
if (diff < 1)
diff = 1;
int min = 0;
int max = 0;
int middle = ws.ws_row / 2;
while (1) {
args = 0;
stdin_read();
clear();
for (int i = 0; i < args; i++) {
if (values[i] < min)
min = values[i];
for (int i = 1; i < args - 1; i++)
print((values[i - 1] + values[i] + values[i + 1]) / 3, diff, i);
else if (values[i] > max)
max = values[i];
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, "#");
}
}
/* 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, "<=");
}
refresh();
}