7 ms·
'Music' from /dev/urandom
- Gnouc 11y agoIt's great! Using: </dev/urandom hexdump -v -e '/1 "%u\n"' | ... save you from spawning one process.
- ckaygusu 11y agoHere is one with the blues scale. From time to time it grooves really nice. 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 24000
- robertelder 11y agoThis sounds better than my version.
- Vivtek 11y agoIt really does! At twice the sampling rate it's pretty interesting, too. Incidentally, this little idea rocks. It's amazing what's buried down there in Unix command-line utilities.
- robertelder 11y agoI received an email suggestion yesterday of a variant of this command that places it inside a function, so that you could play multiple instruments at once with function calls. I guess you could make an entire music composing utility in bash if you wanted to.
- ep103 11y agoanyone got a sample?
- sajal83 11y agohttps://dl.dropboxusercontent.com/u/361747/urandom.mp3 https://dl.dropboxusercontent.com/u/361747/urandom.mp3
- sajal83 11y ago80s/90s computer game soundtrack...
- laumars 11y agoI have this version and the authors "sad" version playing together. It's weird because after about 10 or so minutes they stop sounding random and become almost like chiptune jazz.
- unsignedint 11y agoHere's Ryukyu (Okinawa) Japanese music scale 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 24000
- laumars 11y agoUnfortunately markdown formatting has broken your code. I can make a guess based on where the italics starts and ends, but you might want to indent that code.
- unsignedint 11y agoOops, I'm sorry. Looks better now?
- wookoouk 11y agoAnyone got this working on OSX afplay does not accept the same input :(
- alvare 11y agoI did, install sox and use: > ... | play -c 2 -r 16000 -e signed -L -b 32 -t raw -
- balducien 11y agoAnother solution: [1] 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_one_liner_compose_music_from_entropy_in/d0nu6ta https://www.reddit.com/r/programming/comments/48xf6k/bash_on...
- pavel_lishin 11y agoHeads up, that is incredibly loud.
- Tepix 11y agoIs there a way to make it sounds more pleasant? The sine wave is a bit harsh...
- exDM69 11y agoA triangle/sawtooth wave sounds nicer without any filtering or other effects. It's the only "elementary" waveform that I know of that doesn't sound earpiercingly harsh.
- kittxkat 11y agoThe example from /r/coding[1] is very nice to listen to: 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_liner_compose_music_from_entropy_in/ https://www.reddit.com/r/coding/comments/48zvn4/bash_one_lin...
- geographomics 11y agoThat's quite a delight for the ears. Reminds me of Stéphane Picq's work on the Dune computer game soundtrack, back in the early 90s. It had some similar sounds.
- robertelder 11y agoHere is a recording created by someone on reddit: http://mirror.xwl.me/bash_music_aac.mp4 http://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_one_liner_compose_music_from_entropy_in/ https://www.reddit.com/r/programming/comments/48xf6k/bash_on... https://www.reddit.com/r/linux/comments/48xj46/bash_one_liner_compose_music_from_entropy_in/ https://www.reddit.com/r/linux/comments/48xj46/bash_one_line... https://www.reddit.com/r/coding/comments/48zvn4/bash_one_liner_compose_music_from_entropy_in/ 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.
- ckaygusu 11y agoThose popping sounds give me the impression of a percussion instrument playing, which I find desirable.
- visy 11y agoSomething a bit less random but on the same realm of things: http://countercomplex.blogspot.fi/2011/10/algorithmic-symphonies-from-one-line-of.html http://countercomplex.blogspot.fi/2011/10/algorithmic-sympho...
- chei0aiV 11y agoI hope everyone is turning off CSS before copy-pasting this command-line into their terminal :) http://thejh.net/misc/website-terminal-copy-paste http://thejh.net/misc/website-terminal-copy-paste
- enibundo 11y agoyou mean js?
- chei0aiV 11y agoI mean CSS, as explained by the link I posted.
- hnmcs 11y agoIt was an excellent share you although I don't quite think "turning off CSS" would be my preferred defense. 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".)
- ikeboy 11y agoIf you try to copy a search result, it turns into a Google url that redirects to the result. On iOS this doesn't happen for some reason.
- witty_username 11y agoThe onclick attribute of the search result does it, that may have something to do with that.
- noinsight 11y agoFor those moments when you need cryptographically secure background noise. You can also pipe it directly to pcspkr for a real wake-up call: cat /dev/urandom > /dev/pcspkr
- phatbyte 11y agoI was listening to Esbjron Svensson Trio, and then I tried this...my ears...
- logicrook 11y agoIf you're into jazz, you can check the label Rune Grammofon; you can start bands that are easy to listen to, such as Elephant9 (just listen to Fugl Fønix and try to resist the groove), and then get into the rest (woohoo, Shining). After that, you shouldn't find these bleep-bloops that hard.
- blinkme 11y agoIs... is that blinking text at the bottom?
- tedks 11y agoYeah. It is.
- michaelmior 11y agoHandy smoke test for a good RNG? Not sure I see any case where it would actually be useful for this in practice, but I find the idea amusing in theory.
- jerf 11y agoYou may be able to hear or see that a very bad RNG is bad (there are certainly sufficiently bad ones for which you can), but you can not hear or see that one is good.
- michaelmior 11y agoMy thoughts exactly. You certainly wouldn't want to rely on this to identify a good RNG, but you might be able to catch a bad one.
- zeveb 11y ago> I only expected this to work on Ubuntu 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.
- JoeAltmaier 11y agoBut lets admit that distros of Linux have become idiomatic. Its reasonable to give a caveat when describing any Linux procedure. This is not an Ubuntu issue at all. In fact, what's the point of different distros if they aren't idiomatic?
- cyphar 11y agoIt's incorrect to assume that a shell script that uses tools like xxd and awk is distro-specific. Almost every distribution ships the GNU coreutils and other GNU base tools. It's going to work on basically every distribution. What makes distributions unique is their package manager, release and security philosophy, amount of cruft, etc.
- JoeAltmaier 11y agoEven the same distro line but different versions may have significant issues. This is why every build on top of Linux (e.g. Android) calls out a particular kernel version. Even a particular version for the build machine. Because things like command line tools differ over time. Versionology is a whole universe of hurt on Linux.
- cyphar 11y agoThat's the cost of supporting code that is constantly being updated, you need to start freezing versions and backporting fixes. Also, I'm not sure what command line tools you're referring to as "differing over time". Kernel version freezing is mainly fear of new code (or out-of-tree vendor patchsets that depend very strongly on the kernel ABI which changes every few months -- but that's not user visible). Sure, if your system never changes anything you don't need to worry about software versions. But there are many other problems with that.
- mpnordland 11y agoAlmost could replace Pandora for me. All I want is some somewhat melodious tones in the background anyway.
- kroger 11y agoI wrote something similar (but using Python), on how one can generate music using mathematical sequences such as Fibonacci's: http://pedrokroger.net/pascals-triangle-sound/ http://pedrokroger.net/pascals-triangle-sound/ I used to spend a lot of time on The On-Line Encyclopedia of Integer Sequences ;-)
- sbierwagen 11y agoBack in the day you could just do: cat /dev/urandom > /dev/audio http://everything2.com/title/catting+weird+things+to+%252Fdev%252Faudio http://everything2.com/title/catting+weird+things+to+%252Fde...
- jeffreyrogers 11y ago> If you're a level 500 elite hacker like I am, you will note that the cryptographic quality of numbers from /dev/urandom is not the same as numbers from /dev/random. In our case, we don't want this operation to block, so we use /dev/urandom. This is wrong. See http://www.2uo.de/myths-about-urandom/ 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-from-dev-urandom-secure-for-a-login-key http://security.stackexchange.com/questions/3936/is-a-rand-f... to the current link, since the current link is more to the point.
- tinix 11y agoThis reminds me of something similar, music from malloc, and file reads... by hooking with ld_preload. Code: https://github.com/gordol/ld_preload-sounds https://github.com/gordol/ld_preload-sounds Preview: https://soundcloud.com/glowdon/malloc-read-hook-self-compile https://soundcloud.com/glowdon/malloc-read-hook-self-compile
- bipin_nag 11y agoWho knew chaos sounds so melodious. You sir are a genius.
- kerny 11y agoI don't know if I'm the only one who have noticed that, but on 64 bit machines you have to change "%08X\n" to "%016X\n". Although using %08X sounds interesting, the result is not a major scale and probably not the original intent of the code.
- deleted 11y ago[deleted]