logo

bytemedia

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

battery_back: Use clarinet

Diffstat:

MC/Makefile2+-
MC/battery_back.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 battery_low.au +all: au8b_8kHz au8b_44.1kHz SDL_YUV_visualisation wayland kagome_kagome.au battery_low.au battery_back.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_back.c b/C/battery_back.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++*2 ); - for(int t = 0;t<2000;t++)putchar( t++*3 ); + 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, 2-8), volume); + note(header.samplerate/4, &header, note_to_hertz(ref_tune, 3-8), volume); + silence(header.samplerate/4); return 0; }