This commit is contained in:
Your Name 2024-03-19 22:53:34 +03:00
parent 12e89027f9
commit 7ad4f70d75
3 changed files with 85 additions and 9 deletions

View File

@ -1,10 +1,9 @@
![audio-visual.sh and alsamixer](/img/sshot.jpg) ![audio-visual.sh and alsamixer](/img/sshot.jpg)
git clone https://git.thedroth.rocks/8nlight/micro-utils .asoundrc (Должно быть в ~/)
cc micro-utils/miscutils/spark.c -o ~/spark Нужно поменять rockchipes8316c, на вашу карту (aplay -L)
.asound (Должно быть в ~/) cc spark.c -lm -s -o spark
Нужно поменять rockchipes8316c, на вашу карту modprobe snd-aloop
chmod +x audio_vis.sh
audio-vis.sh ./audio_vis.sh
Нужно поменять путь до spark (по умолч ~/spark)

4
audio_vis.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/bin/sh #!/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

77
spark.c Normal file
View File

@ -0,0 +1,77 @@
#include <stdio.h>
#include <float.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
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;
}