Experimental music from very short C programs
category: code [glöplog]
a new industrial chiptune: (t+((cos(t>>13)>0)?((cos(t>>12)>0.5)?t*0.5:t*0.1):t*0.4))&t+t>>2+((cos(t<<4)>0)?8.0:8.01)+(t*0.002&3)
this is the remix! (this code is javascript only)
t*(1+"4451"[t>>13&3]/10)&t>>9+(t*0.003&3)
t*(1+"4451"[t>>13&3]/10)&t>>9+(t*0.003&3)
@ryg: nice!! how can you do so much size optimization? :D
you just figure out what's necessary and throw the rest away :)
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)
sin(8e3/(y=t&16383))*25+(x=t*"6689"[t>>16&3]/24&127)*y/4e4+((t>>8^t>>10|t>>14|x)&63)
Discourse of The President of United Planets:
((y=(t%5)*(0xF3311337>>(t>>11)&0x1A)|t>>7)>>2)+((y*(t>>7)*7)>>3)+cos((y*2e5)/(t&8191))*11
((y=(t%5)*(0xF3311337>>(t>>11)&0x1A)|t>>7)>>2)+((y*(t>>7)*7)>>3)+cos((y*2e5)/(t&8191))*11
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.
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.
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.
good whilte noise
Code:
t*t*t>>~t*t
Is stereo possible?
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.
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.
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...
((t*Math.pow(2,([[0,4,7,12,16],[0,2,9,14,17],[-1,2,7,14,17],[0,4,7,12,16]][(t>>17)&3]["01234234"[(t>>13)&7]])/12))&0xff)*(1.0-((t%0x2000)/0x2000))
Sorry, somebody HAD to do it. Now back to the experimental stuff, please :)
Sorry, somebody HAD to do it. Now back to the experimental stuff, please :)
(and I know that's just a copy of skurk's thing but more readable I think :D)
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... ;)
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?
Nitro: thanks for the explanation. Is the situation the same if this is used in say a regular 256b?
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.
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.)
I <3 ryg's optimisation :)
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.
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.
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 :)
The problem with stereo is you have to generate 2 streams at the same time.
So the program would look something like :
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 :)
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.