Mail Archives: djgpp/1997/05/28/04:49:26
Metroid wrote:
>
> I may be mistaken...but I believe the PC speaker is only 1-bit...sound or
> no sound
> of course you can alter the pitch....hmm...anyway...I HAVE heard digitized
> sounds through the PC speaker in the past and to be honest, they sound like
> crap...
> also, it slowed the computer down a lot...
>
That is true the PC speaker is only 1-bit, but you can play 8 bits
samples using the following trick : high frequencies (>20 000 Hz) can
not pass in usual speakers. If you send a high frequency signal to
the speaker, it will be averaged. For instance, a high frequency
square signal oscillating between 0 and 1 gives about the same effect
as a signal of value 1/2. to get a value of 1/3, you can send
100100100100, etc.
The technical details to implement such a technique on a PC are not
trivial. You have to catch the timer interrupt and set it to a high
frequency (very dangerous on a slow machine if the processing you make
is longer than the period ! I experienced this on a 386 sx 16 and got
very nice crashes). Then you can use this timer interrupt to control
the PC speaker trhough the 8054 chip that is attached to it.
The best technique to transform a 8-bits signal (or 16 bits) into
a good sequence of 0 and 1 is error propagation. It is the same
technique that is used to dither images on displays with less colors
than the original image data. I used it and got decent results on my
PC speaker (much better than the speaker.drv from Microsoft, which runs
under Windows and is polluted by other interrupts). Of course, the
quality of the result will depend on the physical properties of your
PC speaker.
Remi
- Raw text -