logo

bytemedia

Home to byte-level sounds, images, videos, … git clone https://hacktivis.me/git/bytemedia.git
commit: 976d5ec2ed3371dcbfb4849f88d7ac30f6f09672
parent dcb0df488d5f9eb90a881f6842f470b2b4821be6
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 22 Mar 2022 22:55:37 +0100

battery_low: Use clarinet

Diffstat:

MC/Makefile2+-
MC/battery_low.c38+++++++++++++++++++++++++++++---------
2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/C/Makefile b/C/Makefile @@ -3,7 +3,7 @@ WAYLAND_SCANNER=`pkg-config --variable=wayland_scanner wayland-scanner` .SUFFIXES: .au -all: au8b_8kHz au8b_44.1kHz SDL_YUV_visualisation wayland kagome_kagome.au +all: au8b_8kHz au8b_44.1kHz SDL_YUV_visualisation wayland kagome_kagome.au battery_low.au SDL_YUV_visualisation: SDL_YUV_visualisation.c $(CC) $(CFLAGS) SDL_YUV_visualisation.c -o SDL_YUV_visualisation `sdl2-config --cflags --libs` diff --git a/C/battery_low.c b/C/battery_low.c @@ -1,29 +1,49 @@ -#define _POSIX_C_SOURCE 200809L +#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 - .lenght = 0xFFFFFFFF, // unknown data size - .encoding = 02, // unsigned 8-bit linear PCM - .samplerate = 8000, // Hz + .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); - for(int t = 0;t<1600;t++)putchar( t++*1 ); - for(int t = 0;t<1600;t++)putchar( t++*3 ); - for(int t = 0;t<2000;t++)putchar( t++*2 ); + int volume = 60; + int ref_tune = 440; - // Padding to make it 2s long - for(int t = 0;t<2800;t++)putchar( 0 ); + note(header.samplerate/4, &header, note_to_hertz(ref_tune, 1-8), volume); + note(header.samplerate/4, &header, note_to_hertz(ref_tune, 3-8), volume); + note(header.samplerate/4, &header, note_to_hertz(ref_tune, 2-8), volume); + silence(header.samplerate/4); return 0; }