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.
Of course the PC speaker, even though it can only be given signals to drive it to two states, doesn’t just make square waves, since it has mechanical impedance. In fact it is a low-pass filter. So the true problem, which any decent PC speaker driver should solve, is given a target signal to be reproduced and an impulse response of the PC speaker, find the input signal (subject to restriction to two values, say, -1 and 1), that when filtered by the PC speaker gives the least error from the target signal. This probably is not given by the simple modulation scheme. On the other hand, is the two-value restriction costly? What is the minimum and maximum amount of error that results?
There must be a paper on this. On the other hand, I’m not sure that any existing PC speaker driver implements anything like this. Here is the code for one of them, but it looks too short to be doing anything sophisticated.