Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Command line techno
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
LiamOS
n00b
n00b


Joined: 06 Jun 2012
Posts: 56
Location: Kerry/Dublin, Ireland

PostPosted: Fri Nov 30, 2012 4:33 pm    Post subject: Command line techno Reply with quote

Not sure if this has been posted yet:

Code:
echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay


One of the most fun commands I've ever run.
_________________
CFLAGS=" -O999999"
Back to top
View user's profile Send private message
smartass
Apprentice
Apprentice


Joined: 04 Jul 2011
Posts: 189
Location: right behind you ... (you did turn around, didn't you?)

PostPosted: Sat Dec 01, 2012 10:20 am    Post subject: Reply with quote

Beautiful!
An amazing trip through electronic music and genres :D

But that's just the beginning:
Now try running another
Code:
./a.out | aplay
in another terminal.
And why just one, try two, three, turn them off and on.... long live the binary DJ :D
Code:

#!/bin/bash
#binary techno program by LiamOS and smartass

echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c -o binary_techno_source -

echo "All hail the binary DJ!"
read -p "How many turntables do you want: " turntables
active_turntables=0
declare -a turntables_pids
for ((i=0;i < $turntables;i++)); do
    turntables_pids[$i]=0
done
while :; do
    echo -n "Active turntables: "
    for ((i=0;i < $turntables;i++)); do
   if [ ${turntables_pids[$i]} -ne 0 ] ; then
       echo -n "$(($i + 1)) "
   fi
    done
    echo " (${active_turntables} in total)"
    read -p "Turntable number to toggle on/off or 0 to quit: " request
    if [ $request -gt $turntables ] ; then
   echo "Invalid turntable number, you have only ${turntables} turntables"
   continue
    elif [ $request -eq 0 ] ; then
   break
    fi
    index=$(($request - 1))
    if [ ${turntables_pids[$index]} -eq 0 ] ; then
   ./binary_techno_source | aplay &>/dev/null & turntables_pids[$index]=$!
   let active_turntables++
    else
   kill ${turntables_pids[$index]} &>/dev/null
   let active_turntables--
   turntables_pids[$index]=0
    fi
done
for ((i=0;i < $turntables;i++)); do
    pid=${turntables_pids[$i]}
    if [ $pid -ne 0 ] ; then
   kill $pid &>/dev/null
    fi
done
rm -f binary_techno_source



Thank you so much LiamOS, you made my day :)

EDIT:
save as binary_techno
Code:
 while :; do echo $(($RANDOM % 5 + 1)); sleep 10s; done | binary_techno
= unlimited electronic music!
Random never sounded so cool ;)
Back to top
View user's profile Send private message
ichbinsisyphos
Guru
Guru


Joined: 08 Dec 2006
Posts: 547

PostPosted: Sat Dec 01, 2012 10:46 am    Post subject: Reply with quote

That's awesome. Where is it from? The only trace I can find is an entry in some "xkcdb"-database, probably a archived post from the xkcd forums?
Back to top
View user's profile Send private message
LiamOS
n00b
n00b


Joined: 06 Jun 2012
Posts: 56
Location: Kerry/Dublin, Ireland

PostPosted: Sat Dec 01, 2012 2:21 pm    Post subject: Reply with quote

A mate of mine posted it up on facebook. I've no idea where he found it.

Also, that's an absolutely fantastic script! Thanks, smartass.
_________________
CFLAGS=" -O999999"
Back to top
View user's profile Send private message
jacktrick
n00b
n00b


Joined: 01 Dec 2012
Posts: 0
Location: Dublin, Ireland

PostPosted: Sat Dec 01, 2012 2:52 pm    Post subject: Reply with quote

I'm LiamOS's mate. I'm subscribed to the xkcdb.com database rss feed (think bash.org, but for the #xkcd IRC channel) and that's where I saw it.

Source: http://www.xkcdb.com/?9067

So the original author (as far as I know) is rkm, who's a pretty funny guy.

smartass: that's pretty awesome, I've updated my boop.sh accordingly. :D
Back to top
View user's profile Send private message
smartass
Apprentice
Apprentice


Joined: 04 Jul 2011
Posts: 189
Location: right behind you ... (you did turn around, didn't you?)

PostPosted: Sat Dec 01, 2012 4:45 pm    Post subject: Reply with quote

Glad you liked it :)
Yeah, the only reference I found was on xkcdb. So thx for introducing me to Bucket by the way :D

I was wondering, whether to
  • include the RANDOM part in the script itself
  • suspend (SIGSTOP) processes instead of killing (SIGTERM) them (or offer both options)

I you think it's worth it, I might invest more time into it ;)

It's pretty interesting how from time to time I can trigger quite catchy loops :)
Back to top
View user's profile Send private message
sporkbox
n00b
n00b


Joined: 11 Sep 2012
Posts: 21
Location: United States

PostPosted: Sat Dec 01, 2012 9:45 pm    Post subject: Reply with quote

Mind Status == Blown

How do I learn how to make musical loops with code? This shit is amazing.
Back to top
View user's profile Send private message
LiamOS
n00b
n00b


Joined: 06 Jun 2012
Posts: 56
Location: Kerry/Dublin, Ireland

PostPosted: Mon Dec 03, 2012 4:48 am    Post subject: Reply with quote

sporkbox wrote:
Mind Status == Blown

How do I learn how to make musical loops with code? This shit is amazing.

The looping comes from the C program being run.

Nicely formatted, the program would read:
Code:

main(i) {
    for (i=0 ; ; i++)
        putchar( ((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6) );
}

This isn't a massive improvement, but this is a very low-level aspect of C. The operations here are mostly bitshifting, which is a fascinating thing in itself.
_________________
CFLAGS=" -O999999"
Back to top
View user's profile Send private message
sikpuppy
n00b
n00b


Joined: 12 Jun 2012
Posts: 34
Location: Central Coast, NSW

PostPosted: Mon Dec 03, 2012 5:09 am    Post subject: Reply with quote

Neat. It reminds me of RIchard D James (AKA Aphex Twin) who set up an old Sinclair ZX81 and changed the background hue on his TV rapidly. This caused interference to the audio circuit which, when he altered the speed of colour change, he could produce noise which approximated actual notes. The ZX81 didn't have any sound output nominally. He won some sort of prize as a schoolboy for this feat.
Quote:
Richard claims to have produced sound on a Sinclair ZX81 (a machine with no sound hardware) at the age of 11:

When I was 11, I won 50 pounds in a competition for writing this program that made sound on a ZX81. You couldn't make sound on a ZX81, but I played around with machine code and found some codes that retuned the TV signal so that it made this really weird noise when you turned the volume up.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Wed Dec 05, 2012 12:06 am    Post subject: Reply with quote

just epic !!!! thank you, plz post more if you have more..!!!! :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum