logo

bytemedia

Home to byte-level sounds, images, videos, … git clone https://hacktivis.me/git/bytemedia.git
commit: 25287ed92b8cbfd75ffe83b56fb240019c3fcd2e
parent 4933695039f2b8493212ec675dea7598c70aa562
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  6 Feb 2022 02:24:11 +0100

2022-02-06.c: New

Diffstat:

AC/2022-02-06.c41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/C/2022-02-06.c b/C/2022-02-06.c @@ -0,0 +1,41 @@ +#define _XOPEN_SOURCE 700 +#include <stdio.h> +#include <inttypes.h> // uint32_t +#include <math.h> // sinf(), M_PI, pow() + +#include "au.h" +int +main(void) +{ + // Use AU defaults + struct au_header header = { + .offset = 24, // no-annotation, in octets + .length = 0, + .encoding = AU_ENCODING_8B_LPCM, + .samplerate = 44000, // Hz + .channels = 1 + }; + + char buf[4]; + int32_t t; + + // fd 1 is stdout + write_au_header(1, &header); + + //for(t = 0;;t++) { + for(t = 0;t<header.samplerate*60;t++) { + float tune; + int freq = 140; + //int freq = 180 + (t / (header.samplerate / 666) % 10); + int phase = t >> 5; + int volume = 20; + + tune = sinf(t * 2*M_PI * (freq + ((t>>3) % 300))/header.samplerate) * volume/9; + //tune += sinf(t * 2*M_PI * (freq + ((t>>5) % 600))/header.samplerate) * volume/3; + tune += sinf(t * 2*M_PI * (freq + ((713&t>>(t/header.samplerate/3)) % 2000))/header.samplerate) * volume/2; + + putchar((uint8_t)(tune)); + } + + return 0; +}