Audio through the PC Speaker

At work, sound comes from inside the computer and has a terrible quality, so I wondered if it used the PC speaker. Years ago when I didn’t have a sound card on a 486 computer, I used a PC speaker driver to play sound.

To my surprise, this driver is still available.

However, I didn’t realize at the time how playing sound through the PC speaker required an interesting hack. You see, the PC speaker could only be put into two states, on and off. So it was easy to make single pitches (which we all did, didn’t we? beep beep) So technically the PC speaker could only generate square waves of various duty cycles. Here’s how the PC speaker is controlled.

Then how was it able to play arbitrary wave files? Well, it turns out 8-bit sound is supposedly generated by pulse code modulation like this, like a light dimmer. The idea is to get “half on” you turn it on half the time. But it really shouldn’t work that way if you think about it, at least not so trivially, since what is being set is the amplitude, not the average power.
(Read the article)