pouët.net

Experimental music from very short C programs

category: code [glöplog]
this is the remix! (this code is javascript only)
t*(1+"4451"[t>>13&3]/10)&t>>9+(t*0.003&3)
added on the 2011-10-05 10:21:41 by ryg ryg
@ryg: nice!! how can you do so much size optimization? :D
added on the 2011-10-05 10:26:15 by rez rez
you just figure out what's necessary and throw the rest away :)
added on the 2011-10-05 10:29:19 by ryg ryg
and once more the mu6k tune, 44.1kHz edit. sounds much better but constants get longer so i needed to cut some more bytes! :)
sin(8e3/(y=t&16383))*25+(x=t*"6689"[t>>16&3]/24&127)*y/4e4+((t>>8^t>>10|t>>14|x)&63)
added on the 2011-10-05 10:31:58 by ryg ryg
random remark: so sawtooth and pulse waves are easy. if you don't want to use trigonometry, use triangle waves instead of sin! sadly this is not quite as easy.
Code:(t<<4)^-(t>>4&1)

this is the corresponding triangle wave for "t<<3". the general form of this is always "(t<<N)^-(t<<(N-8)&1)" where the second shift is a right shift if N-8 is negative. and of course you can save some parentheses if you want to, but this is a bit clearer.
added on the 2011-10-05 10:58:56 by ryg ryg
good whilte noise
Code:t*t*t>>~t*t
added on the 2011-10-05 12:15:14 by rrrola rrrola
Is stereo possible?
added on the 2011-10-05 12:52:02 by psonice psonice
psonice: Yes and no.

Technically, yes. You could define a way in which the byte stream is interpreted as stereo and go by that.

In spirit, no. This whole idea started out by compiling C programs and piping them into /dev/audio or /dev/dsp or whatever your flavour of *NIX has available. While you can modify the parameters of an audio stream with ioctl calls, I don't think you can do that from that the shell. I think you need to actually open the audio stream from within the C program in order to do those ioctl calls, so then you can no longer just write stdout like now.

Of course, now everybody is using the JS or Flash applet, so it wouldn't be too hard to add a checkbox that says stereo that makes every other sample be interpreted as L/R.
added on the 2011-10-05 14:12:32 by nitro2k01 nitro2k01
You can use 2 PCs, where the onliner choose randomly which stream to use ^^ Stochastic stereo...
Also, if I'm not mistaken, /dev/* is using 8 bit UNsigned by default whereas the JS app is apparently outputting the data as 8 bit signed. Just saying...
added on the 2011-10-05 14:46:14 by nitro2k01 nitro2k01
(and I know that's just a copy of skurk's thing but more readable I think :D)
added on the 2011-10-05 15:09:34 by kb_ kb_
holy shit. just listened to the most current oneliners (mu5k, ryg, kb) - awesome - listening to this stuff I even consider to code 4k's again... ;)
added on the 2011-10-05 16:09:34 by las las
yeah, it's not at the point where we have soft synth + music in a one-liner. Nuts :D

Nitro: thanks for the explanation. Is the situation the same if this is used in say a regular 256b?
added on the 2011-10-05 16:31:17 by psonice psonice
Nitro, on many modern unix-like systems, the audio device is hogged by a daemon anyway so you need to use a tool to pipe stuff to it. E.g. ./program | aplay. Changing the sample rate, bit depth or number of channel is just about passing additional parameters to aplay or whatever there is.

I personally see no reason for sticking to 8000 Hz 8-bit mono. The code keeps more compact in the lo-fi modes, however.
Depends on whether you tell the user to pipe stdout to an audio device or open an audio device in your own code. I could totally see this kind of oneliner working in a DOS intro interfacing a SB card. They can/do push data one sample at a time IIRC. (Unless you use DMA.)
added on the 2011-10-05 16:54:47 by nitro2k01 nitro2k01
I <3 ryg's optimisation :)
added on the 2011-10-05 17:01:29 by musk musk
kb: this cant work (t> ;>17) and whats with all the arrays/square brackets?
i copied the oneliner, because noscript complains about xss attack, when i click the link and i find it easier to just copy then to disarm noscript.
added on the 2011-10-05 19:05:51 by vectory vectory
vectory: it's (t>>17) and it's JS only. C won't support the "array of an array indexed with an array of an array" trickery I've done :)
added on the 2011-10-05 19:09:47 by kb_ kb_
The problem with stereo is you have to generate 2 streams at the same time.
So the program would look something like :

Code: for(;;)putchar(t%1?left():right());


As well as setting up the stream as said above. But that's a matter of using the right platform, which already sets it up :)
still no fr025 after 11 pages :(
Should be doable using the array of arrays trick to get different parts.
added on the 2011-10-05 19:31:46 by p01 p01

login