a log of the developpement and my ideas that i can organize Later
earlier today i found bytebeats again, and i found it realy interesting!
its a tiny program where f(t) is an audio sample for time t (usually a byte, at a sample rate of 8khz). if the sample is outputted to stdout, the program can be piped into aplay, and generate music!
i find that pretty interesting and cool. most bytebeats are really short C programs with a lot of freaky math to make nice sounds.
so inspired by that i tried making some in python like this:
#python bytebeat.py | aplay
from math import *
t=0
while True:
s=t%([61,41,48,65][int(t/4000%4)]+t/8000%8*3)*min(t/4000%1,0.6)
print(chr(int(s)%256),end="",flush=True)
t+=1
(i just came up with this, idk if it works or sounds good)
the problem with this method is that when you updayte the script it doesnt auto-update, so i decided to make another python program that pipes the program into aplay, and when the file changes it reloads it (source coming, if i dont completely rework it lol).
the problem with this is that it outputs samples faster than they get played so desynchronization happens. what i did is to generate 100 samples, then wait the amount of time it should take for them to be processed but that feels inaccurare. idk if theres a way to know if aplay has consumed everything. the right solution would probably be to output audio samples with portaudio or something but that sounds annoying, and you need dependencies :(
its really cool tho cuz it lets the user(me) use their favorite editor, without needing a special IDE. i wonder if theres a way to edit a file in memory or something, to limit disk writes and get updates more easily. maybe ill end up making a special ide lol
im lowkey considering making a forth (in golang) for this. it would solve some problems, and it feels pretty apt for this. let me try to conver the previous example into some sort of forth-like
: beat T SR 2 / / ;
: notes { 61 41 48 65 } ;
: melody
[ notes beat 4 % NTH
, beat 2 / 8 % 3 * ] SUM ;
: amp [ beat 1 % , 0.6 ] MIN ;
melody amp *
this is literally just an idea but its interesting ! its pretty basic, but it has arrays :O i dont think its essential, but its pretty useful for buffers and whatnot. its not as concise as C/python, but is that so bad? it seems fun for doing synthesizer stuff, but i dont really see a need for it, when python works lol.