battery_back.c (1091B)
- #define _XOPEN_SOURCE 700
- #include <stdio.h>
- #include <inttypes.h> // uint32_t
- #include "au.h"
- #include "misc.h"
- #include "instruments.h"
- #include "effects.h"
- void
- note(int dur, struct au_header *header, int hertz, float volume) {
- char buf[4];
- for(int t = 0;t<dur;t++) {
- //float tune = pure_sin(header, hertz, t);
- float tune = clarinet(header, hertz, t);
- float vol = crossfade(dur, t, volume);
- putchar((uint8_t)(tune * vol));
- }
- }
- int
- main(void)
- {
- // Use AU defaults
- struct au_header header = {
- .offset = 24, // no-annotation, in octets
- .length = 0xFFFFFFFF, // unknown data size
- .encoding = AU_ENCODING_8B_LPCM,
- .samplerate = 48000, // Hz
- .channels = 1
- };
- header.length = header.samplerate;
- // fd 1 is stdout
- write_au_header(1, &header);
- int volume = 60;
- int ref_tune = 440;
- note(header.samplerate/4, &header, note_to_hertz(ref_tune, 1-8), volume);
- note(header.samplerate/4, &header, note_to_hertz(ref_tune, 2-8), volume*1.1);
- note(header.samplerate/4, &header, note_to_hertz(ref_tune, 4-8), volume*1.3);
- silence(header.samplerate/4);
- return 0;
- }