2022-02-06.c (943B)
- #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;
- }