diff --git a/README.md b/README.md index 1a8043b..9b2c40a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ ![audio-visual.sh and alsamixer](/img/sshot.jpg) -git clone https://git.thedroth.rocks/8nlight/micro-utils -cc micro-utils/miscutils/spark.c -o ~/spark +.asoundrc (Должно быть в ~/) +Нужно поменять rockchipes8316c, на вашу карту (aplay -L) -.asound (Должно быть в ~/) -Нужно поменять rockchipes8316c, на вашу карту - -audio-vis.sh -Нужно поменять путь до spark (по умолч ~/spark) +cc spark.c -lm -s -o spark +modprobe snd-aloop +chmod +x audio_vis.sh +./audio_vis.sh diff --git a/audio_vis.sh b/audio_vis.sh old mode 100644 new mode 100755 index d27207f..e1c7c7e --- a/audio_vis.sh +++ b/audio_vis.sh @@ -1,4 +1,4 @@ #!/bin/sh -cols=124 +cols=180 -arecord -q -c 1 --period-size=256 --buffer-size=512 -f S24_LE -t raw -D loopout | hexdump -e '/4 "%d "' | tr -d '-' | tr -d '*' | xargs -n $cols ~/spark -n +arecord --rate 48000 --buffer-size=2048 -D loopout -N -q -c 1 -f S24_LE -t raw | hexdump -e '/4 " %d"' | tr -d '*' | tr -d '-' | xargs -n $cols ./spark diff --git a/spark.c b/spark.c new file mode 100644 index 0000000..a2d3307 --- /dev/null +++ b/spark.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include + +double min = 90000; +double max = 3000000; + +int parse_double(const char *str, double *res) { + char *ptr; + + *res = strtod(str, &ptr); + if (*ptr) + return 0; + + return 1; +} + +void print(double diff, double val) { + int lvl = (int)round((val - min + 1) / diff * 7); + if (lvl < 0) + lvl = 0; + + else if (lvl > 7) + lvl = 7; + + putchar('\xe2'); + putchar('\x96'); + putchar('\x81' + lvl); +} + +int main(int argc, char **argv) { + argv++; + argc--; + + if (argc == 0) { + fprintf(stderr, "spark: missing operands\n"); + return 1; + } + + size_t as = argc / 2; + double *a = malloc((as + 1) * sizeof(double)); + if (a == NULL) + return 1; + + size_t j = 0; + for (size_t i = 0; i < as; i++) { + double val = 0; + if (!parse_double(argv[j], &val)) { + j++; + continue; + } + + double val2 = 0; + if (!parse_double(argv[j + 1], &val)) { + j++; + continue; + } + + a[i] = (val + val2) / 2; + j++; + } + + double diff = max - min + 1; + if (diff < 1) + diff = 1; + + for (size_t i = 0; i < as; i++) + print(diff, a[i]); + + putchar('\r'); + + free(a); + return 0; +}