Internal PC Speaker Music Programming (Linux)

beep old school code software script bash

A long time ago on a high school when we had a programming class I got this idea to make a song played my this PC speaker. You know, the speakers are in most cases not present at school computers and the only sound you computer does is the beep sound when you turn it on. I thought that it would be a great idea to use it! So I wrote a simple program in Pascal, then rewrote that in C (since I learned I can do it in C as well) and played it. The teacher had no idea what's going on. Haha yea always trolling...

Anyway, this PC speaker or internal speaker is a simple sound generating device that was mainly used in the old computers for a diagnostic messages, old games and many stuff that needed this sound output without using the modern speakers. For example BIOS uses this PC speaker for example to let you know that your hardware is alright and starting.

This is nothing difficult, just a funny piece of programming that sounds pretty cool, at least to me. In Linux you can use a beep command (apt-get install beep) where you simply give a frequency and duration. The best way is to make a shell script like that with notes.

beep -f 500 -l 250
beep -f 240 -l 500
sleep 0.2
beep -f 350 -l 200
...

The tone frequencies can be found here: https://courses.engr.illinois.edu/ece390/books/labmanual/io-devices-speaker.html

If you want to use C, well let's take a look at the beep command implementation here: http://www.johnath.com/beep/beep.c. I have put a simplified version below.

int fd = open("/dev/console", O_WRONLY);

ioctl(fd, KIOCSOUND, (int)(1193180/500));
usleep(250000);
ioctl(fd, KIOCSOUND, 0);

ioctl(fd, KIOCSOUND, (int)(1193180/240));
usleep(500000);
ioctl(fd, KIOCSOUND, 0);

usleep(200000);

ioctl(fd, KIOCSOUND, (int)(1193180/350));
usleep(200000);
ioctl(fd, KIOCSOUND, 0);

...
close(fd);

Be sure to type sudo modprobe -v pcspkr before and run the compiled program with sudo as well.

Sources: Bash version of Tetris Theme and C template with example (was too lazy to rewrite the whole song).

Oh and here is a demo...


Last edits: by

Latest suggestions

Susano vfxI love susano . hope u will do it by Adarsh
chidori forms if you can make chidori forms like chidori spear or chidori stream by
Neiji palm attack effectCan you do Neiji palm technique effectby Jack Kyndra Jimmer
I HAVE SUGGESTION....Please make Boruto VS Naruto in REAL LIFE.... :-) by Jack Kyndra Jimmer @ The
Tsuna\'s X burner from hitman rebornby Roxxas

Latest uploads

3D Collision detection & simple physics engine - Separating Axis Theorem, Impulse based response

3D Collision detection & simple physics engine - Separating Axis Theorem, Impulse based response

100% Free Melee Fight Sounds (punches,swishes,falls...)

100% Free Melee Fight Sounds (punches,swishes,falls...)

Tsuna's X Burner - Katekyo Hitman Reborn! in REAL LIFE

Tsuna's X Burner - Katekyo Hitman Reborn! in REAL LIFE

Behind the scenes

Back to this world Explosion again Rasengan on the beach

Search