in reply to Re: Does Perl ring a bell? (shame)
in thread Does Perl ring a bell?

I once was sniffing through this man page:

http://www.themanualpage.org/man/man4/console_codes.4.php

and noted that on the Linux console you could control the pitch and duration of the console bell by echoing escape codes:

ESC [ 10 ; n ] Set bell frequency in Hz. ESC [ 11 ; n ] Set bell duration in msec.

...you can test this with:

FREQ=440 DUR=500 echo -e "\e[10;$FREQ]\e[11;$DUR]" >/dev/console echo -e "\a" >/dev/console</p>

I then found pages like these:

which gave the frequencies of the different notes (because I don't know much technical stuff about music) and figured out that I could play music on the console...

I got the sheet music for our national anthem, and wrote a C program which would set the frequency and the duration, send a ^G and then usleep for the appropriate number of microseconds before playing the next note. (if you don't sleep you just get a mess of quick beeps because it sends the next one immediately - it doesn't wait for the playing beep to finish)

(I did need to get a musically aware friend to tell me which notes I should play sharp or flat - as some needed tweaking for it to be right)

I found this was a lot more attention getting and pleasant to listen to than using a normal beep as a signal when something was happening on my box (don't forget to reset it back to the normal pitch and duration after playing the tune though, otherwise your adjusted beeps could annoy you when you're using the console beep as a normal console beep!)

For a while I even left my old laptop running 24x7 in my bedroom and had a cron job to launch the binary at /dev/console (so it played through the PC speaker) in the morning as my alarm clock! - it worked nicely until the clock on the ancient laptop started to go silly ;o)