logo

bytemedia

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

kagome_kagome: Extract clarinet to a function

Diffstat:

MC/kagome_kagome.c14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/C/kagome_kagome.c b/C/kagome_kagome.c @@ -29,16 +29,24 @@ crossfade(int dur, int t, float vol) } } +float +clarinet(struct au_header *header, int hertz, int t) +{ + float w1 = 2*M_PI*hertz/header->samplerate; + + return 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); +} + 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); - float w1 = 2*M_PI*hertz/header->samplerate; + float tune = clarinet(header, hertz, t); + float vol = crossfade(dur, t, volume); - 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))); + putchar((uint8_t)(tune * vol)); } }