logo

bytemedia

Home to byte-level sounds, images, videos, … git clone https://hacktivis.me/git/bytemedia.git
commit: d379c6484260753cac8e550560a1c02cd20082dd
parent fb1727239bff5c5eaba68316cd60805d964f7914
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 22 Mar 2022 21:38:40 +0100

kagome_kagome: Update

Diffstat:

MC/Makefile5++++-
MC/kagome_kagome.c166++++++++++++++++++++++++++++++++++++++++---------------------------------------
2 files changed, 88 insertions(+), 83 deletions(-)

diff --git a/C/Makefile b/C/Makefile @@ -1,7 +1,7 @@ WAYLAND_PROTOCOLS=`pkg-config --variable=pkgdatadir wayland-protocols` WAYLAND_SCANNER=`pkg-config --variable=wayland_scanner wayland-scanner` -all: au8b_8kHz au8b_44.1kHz SDL_YUV_visualisation wayland +all: au8b_8kHz au8b_44.1kHz SDL_YUV_visualisation wayland kagome_kagome.au SDL_YUV_visualisation: SDL_YUV_visualisation.c $(CC) $(CFLAGS) SDL_YUV_visualisation.c -o SDL_YUV_visualisation `sdl2-config --cflags --libs` @@ -18,6 +18,9 @@ wayland: wayland.c xdg-shell-protocol.c kagome_kagome: kagome_kagome.c au.h $(CC) $(CFLAGS) -o $@ $< -lm +kagome_kagome.au: kagome_kagome + ./kagome_kagome > kagome_kagome.au + .PHONY: clean clean: rm SDL_YUV_visualisation diff --git a/C/kagome_kagome.c b/C/kagome_kagome.c @@ -7,29 +7,6 @@ #include "au.h" -#define TICK 4000 -#define NOTE (TICK*0.99) -#define GAP (TICK*0.01) - -// taken from beep(1) manpage -#define MID_C_C 261.63 -#define MID_C_CS 277.18 -#define MID_C_DB 277.18 -#define MID_C_D 293.66 -#define MID_C_DS 311.13 -#define MID_C_EB 311.13 -#define MID_C_E 329.63 -#define MID_C_F 349.23 -#define MID_C_FS 369.99 -#define MID_C_FB 369.99 -#define MID_C_G 392.00 -#define MID_C_GS 415.30 -#define MID_C_AB 415.30 -#define MID_C_A 440.00 -#define MID_C_AS 466.16 -#define MID_C_BB 466.16 -#define MID_C_B 493.88 - // https://pages.mtu.edu/~suits/NoteFreqCalcs.html #define TWELTH_ROOT_2 1.059463094359 double @@ -37,12 +14,31 @@ note_to_hertz(double ref_tune, int steps) { return ref_tune*pow(TWELTH_ROOT_2,steps); } +float +crossfade(int dur, int t, float vol) +{ + float att = dur/9; + float decay = dur/3; + + if(t < att) { + return vol*(t/att); + } else if((dur-t) < decay) { + return vol*((dur-t)/decay); + } else { + return vol; + } +} + void sin_note(int dur, struct au_header *header, int hertz, float volume, float delay) { char buf[4]; for(int t = 0;t<dur;t++) { - putchar((uint8_t)(sinf((delay + t) * 2*M_PI*hertz/header->samplerate) * volume) % 210); + //putchar((uint8_t)(sinf((delay + t) * 2*M_PI*hertz/header->samplerate) * volume) % 210); + float w1 = 2*M_PI*hertz/header->samplerate; + + float tune = sin(w1*t) + 0.75*sin(3*w1*t) + 0.5*sin(5*w1*t) + 0.14*sin(7*w1*t) + 0.5*sin(9*w1*t) + 0.12*sin(11*w1*t) + 0.17*sin(13*w1*t); + putchar((uint8_t)(tune * crossfade(dur, t, volume))); } } @@ -54,7 +50,9 @@ note(int dur, int pitch) { } } #else -#define note(dur,pitch) sin_note(dur, header, note_to_hertz(440, pitch-8), 100, 0) +#define REF_TUNE 440*1 +#define VOLUME 10 +#define note(dur,pitch) sin_note(dur, header, note_to_hertz(REF_TUNE, pitch-8), VOLUME, 0) #endif void @@ -64,129 +62,133 @@ silence(int dur) { void kagome_kagome(struct au_header *header) { - note(NOTE*2, 8); silence(GAP*2); + int tick = header->samplerate / 2; + int note = tick * 1.0; + int gap = tick * 0.00; + + note(note*2, 8); silence(gap*2); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 9); silence(GAP); + note(note*1, 9); silence(gap); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - silence(TICK*1); + silence(tick*1); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE/2, 8); silence(GAP/2); - note(NOTE/2, 8); silence(GAP/2); + note(note/2, 8); silence(gap/2); + note(note/2, 8); silence(gap/2); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE/2, 7); silence(GAP/2); - note(NOTE/2, 7); silence(GAP/2); + note(note/2, 7); silence(gap/2); + note(note/2, 7); silence(gap/2); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE/2, 8); silence(GAP/2); - note(NOTE/2, 7); silence(GAP/2); + note(note/2, 8); silence(gap/2); + note(note/2, 7); silence(gap/2); - note(NOTE*1, 5); silence(GAP); + note(note*1, 5); silence(gap); - silence(TICK*1); + silence(tick*1); // ---- - note(NOTE, 8); silence(GAP); + note(note, 8); silence(gap); - note(NOTE, 7); silence(GAP); + note(note, 7); silence(gap); - note(NOTE, 8); silence(GAP); + note(note, 8); silence(gap); - note(NOTE, 7); silence(GAP); + note(note, 7); silence(gap); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE/2, 8); silence(GAP/2); - note(NOTE/2, 7); silence(GAP/2); + note(note/2, 8); silence(gap/2); + note(note/2, 7); silence(gap/2); - note(NOTE*1, 5); silence(GAP); + note(note*1, 5); silence(gap); - silence(TICK*1); + silence(tick*1); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 9); silence(GAP); + note(note*1, 9); silence(gap); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - silence(TICK*1); + silence(tick*1); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE/2, 7); silence(GAP/2); - note(NOTE/2, 7); silence(GAP/2); + note(note/2, 7); silence(gap/2); + note(note/2, 7); silence(gap/2); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE/2, 7); silence(GAP/2); - note(NOTE/2, 7); silence(GAP/2); + note(note/2, 7); silence(gap/2); + note(note/2, 7); silence(gap/2); // ---- - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 5); silence(GAP); + note(note*1, 5); silence(gap); - silence(TICK*1); + silence(tick*1); // ---- - note(NOTE/2, 8); silence(GAP/2); - note(NOTE/2, 8); silence(GAP/2); + note(note/2, 8); silence(gap/2); + note(note/2, 8); silence(gap/2); - note(NOTE/2, 8); silence(GAP/2); - note(NOTE/2, 8); silence(GAP/2); + note(note/2, 8); silence(gap/2); + note(note/2, 8); silence(gap/2); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - note(NOTE*1, 9); silence(GAP); + note(note*1, 9); silence(gap); // ---- - note(TICK*1, 8); // silence(GAP); + note(note*1, 8); // silence(gap); - note(NOTE*1, 7); silence(GAP); + note(note*1, 7); silence(gap); - note(NOTE*1, 8); silence(GAP); + note(note*1, 8); silence(gap); - silence(TICK*1); + silence(tick*1); } int @@ -196,8 +198,8 @@ main(void) struct au_header header = { .offset = 24, // no-annotation, in octets .length = 0xFFFFFFFF, // unknown data size - .encoding = 02, // unsigned 8-bit linear PCM - .samplerate = 8000, // Hz + .encoding = AU_ENCODING_8B_LPCM, + .samplerate = 48000, // Hz .channels = 1 };