'Music' from /dev/urandom
blog.robertelder.org
blog.robertelder.org
cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("0,3,5,6,7,10,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | aplay -c 2 -f S32_LE -r 24000Incidentally, this little idea rocks. It's amazing what's buried down there in Unix command-line utilities.
cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("4,5,7,11",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1046*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | aplay -c 2 -f S32_LE -r 24000http://mirror.xwl.me/bash_music_aac.mp4
The above is close to what it should sound like.
Here are the reddit comment threads, some of which contain instructions for OSX:
https://www.reddit.com/r/programming/comments/48xf6k/bash_on...
https://www.reddit.com/r/linux/comments/48xj46/bash_one_line...
https://www.reddit.com/r/coding/comments/48zvn4/bash_one_lin...
Someone recorded what they got working on OSX, and it sounded terrible (not how it sounds on my Ubuntu machine). I haven't tested this on a mac since I don't have one.
I was surprised that many people suggested listening to the music for pleasure or inspiration. There are a few things I could do that would probably improve the sounds quality: One is experimenting with the sampling rate of the sin wave, and another is adjusting the for loop to make sure that it ends on the end of the sine curve close to y = 0. Right now, for some notes it will just stop halfway through close to y=1, and the next note will start at y=0. I think that is the source of the 'poping' sound between notes.
This is wrong. See http://www.2uo.de/myths-about-urandom/
(The part about /dev/urandom not blocking is right though)
Edit: changed http://security.stackexchange.com/questions/3936/is-a-rand-f... to the current link, since the current link is more to the point.
You can also pipe it directly to pcspkr for a real wake-up call:
cat /dev/urandom > /dev/pcspkr cat /dev/urandom > /dev/audio
http://everything2.com/title/catting+weird+things+to+%252Fde... </dev/urandom hexdump -v -e '/1 "%u\n"' | ...
save you from spawning one process.And yet here's the command:
cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("0,2,4,5,7,9,11,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | aplay -c 2 -f S32_LE -r 16000
There's nothing Ubuntu-specific there: it works fine on other Linuxes.It's gotten more than a little annoying, this widespread equivalence between Ubuntu and Linux. Ubuntu is a Linux distro, albeit hardly the best, most idiomatic or most traditional. It's just a single distro, out of many.
In fact, what's the point of different distros if they aren't idiomatic?
FWIW, I really dig the demo: it's cool.
awk 'function wl() {
rate=64000;
return (rate/160)*(0.87055^(int(rand()*10)))};
BEGIN {
srand();
wla=wl();
while(1) {
wlb=wla;
wla=wl();
if (wla==wlb)
{wla*=2;};
d=(rand()*10+5)*rate/4;
a=b=0; c=128;
ca=40/wla; cb=20/wlb;
de=rate/10; di=0;
for (i=0;i<d;i++) {
a++; b++; di++; c+=ca+cb;
if (a>wla)
{a=0; ca*=-1};
if (b>wlb)
{b=0; cb*=-1};
if (di>de)
{di=0; ca*=0.9; cb*=0.9};
printf("%c",c)};
c=int(c);
while(c!=128) {
c<128?c++:c--;
printf("%c",c)};};}' | sox -t raw -r 64k -c 1 -e unsigned -b 8 - -d
[1]: https://www.reddit.com/r/coding/comments/48zvn4/bash_one_lin...> ... | play -c 2 -r 16000 -e signed -L -b 32 -t raw -
cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("0,2,4,5,7,9,11,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | sox -traw -r44100 -b16 -e unsigned-integer - -tcoreaudio
1: https://www.reddit.com/r/programming/comments/48xf6k/bash_on...Code: https://github.com/gordol/ld_preload-sounds
Preview: https://soundcloud.com/glowdon/malloc-read-hook-self-compile
http://pedrokroger.net/pascals-triangle-sound/
I used to spend a lot of time on The On-Line Encyclopedia of Integer Sequences ;-)
http://countercomplex.blogspot.fi/2011/10/algorithmic-sympho...
You can paste to an intermediate area to be sure you didn't catch something hidden from whichever site you don't trust (which allows users to inline arbitrary HTML elements with arbitrary styles).
This is a habit one already might be in if they want to avoid being tracked from clicking on, say, Google search results. You'll avoid some of their tracking features if you copy the link you want and paste it to some text-holding zone first. (This also avoids the site you land on knowing your "referer".)
On iOS this doesn't happen for some reason.
Then I would have to say "okay copy the domain and path from your search result, which isn't a link, and which Google probably hides already (so this new advice won't work any more) or they will hide it some day, so the system doesn't work as literally as I described it."
So if Google has found more and more ways to avoid people avoiding their tracking, that's fine, and what I said literally doesn't apply if you take it 100% literally, but at least you understand what I'm saying about how to avoid the naive copy paste surprise.