logo

bytemedia

Home to byte-level sounds, images, videos, …
commit: b2e206d778f835daae17552123ee01df7e1dc858
parent 08a6d819807266914eabc6481f76fb81b4050571
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Nov 2020 10:46:07 +0100

C/alpha.c: New File

Diffstat:

AC/alpha.c37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/C/alpha.c b/C/alpha.c @@ -0,0 +1,37 @@ +// cat ./alpha.c | tcc -run ./alpha.c | mpv - +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> // getchar() +#include <inttypes.h> // uint32_t + +#include "au.h" + +int +main(void) +{ + // Use AU defaults + struct au_header header = { + .offset = 24, // no-annotation, in octets + .lenght = 0xFFFFFFFF, // unknown data size + .encoding = 02, // unsigned 8-bit linear PCM + .samplerate = 8000, // Hz + .channels = 1 + }; + + // fd 1 is stdout + write_au_header(1, &header); + + int c = 0, t = 0, o = 0; + + while((c = getchar()) != -1) { + int dur = 8000/14; + o = 1; // Magic number + if(c >= 'a' && c <= 'z') { dur = 8000/15; o=c-'a'+1; } + if(c >= '0' && c <= '9') { dur = 8000/16; o=c-'0'+1; } + if(c >= 'A' && c <= 'Z') { dur = 8000/17; o=c-'a'+1; } + + for(int i = 0;i<dur;i++,t++) + putchar(t++*o%30); + } + + return 0; +}