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:

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

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

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

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


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


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


Write a new comment:

All the comments are reviewed before publishing! Meaningless posts are automatically refused.

Be the first legendary hero and write a message that will last for ages!

Latest suggestions

Dies Irae Wilhelm's Second Nightby Bae
Tokyo GhoulKaneki’s Kaguneby Kroy Productions
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

Latest uploads

Hadō #91 Senjuu Kouten Taihou - REAL LIFE Bleach

Hadō #91 Senjuu Kouten Taihou - REAL LIFE Bleach

Yamamoto's Ittou Kasou - REAL LIFE Bleach

Yamamoto's Ittou Kasou - REAL LIFE Bleach

Martial arts workout & agility exercises in the Nature

Martial arts workout & agility exercises in the Nature

Behind the scenes

Han Tripod Teleport scroll