guitar synthesizer in one line of C

f=220;echo "int s=16e3/$f;main(i){unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}"|gcc -x c -&&./a.out</dev/urandom|aplay -d 2
outputs a f=220Hz guitar string sound (fifth string A) needs ALSA

7
By: tehdog
2013-06-28 14:52:53

These Might Interest You

  • This command, taken from play's manual page, plays a synthesized guitar tone for each of the strings on a standard tuned guitar. The command "play" is a part of the package "sox".


    16
    for n in E2 A2 D3 G3 B3 E4;do play -n synth 4 pluck $n repeat 2;done
    eightmillion · 2009-12-13 06:57:26 5
  • see sample output Show Sample Output


    2
    while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt
    nottings · 2009-02-19 18:48:12 1
  • N: On the current line, sed will display it on pattern space, plus a \n (new line); but s/\n//: Will get rid of new line displayed on pattern space, joining the current line's end with the start of the next line Useful in scripts. Show Sample Output


    2
    sed 'X{N;s/\n//;}' file.txt (where X is the current line)
    pibarnas · 2016-07-30 14:27:20 0
  • You can actually do the same thing with a combination of head and tail. For example, in a file of four lines, if you just want the middle two lines: head -n3 sample.txt | tail -n2 Line 1 --\ Line 2 } These three lines are selected by head -n3, Line 3 --/ this feeds the following filtered list to tail: Line 4 Line 1 Line 2 \___ These two lines are filtered by tail -n2, Line 3 / This results in: Line 2 Line 3 being printed to screen (or wherever you redirect it).


    0
    head -n1 sample.txt | tail -n1
    gtcom · 2011-06-14 17:45:04 0

What Others Think

or, using first argument as a frequency: echo "main(int i,char **a){int s=16e3/atoi(a[1]);unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}"|gcc -x c - then ./a.out 220 </dev/urandom|aplay -d 2
tehdog · 255 weeks and 5 days ago
Karplus?Strong? Awesome! =)
MarxBro · 255 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: