From: Remi Coulom Newsgroups: comp.os.msdos.djgpp Subject: Re: How to play WAV via PC Speaker ? Date: Wed, 28 May 1997 09:49:25 +0200 Organization: IMAG, Grenoble, France Lines: 35 Message-ID: <338BE385.41C6@ensimag.imag.fr> References: <5mfmo3$l05 AT hatathli DOT csulb DOT edu> <01bc6aa1$855a5560$8941d9cd AT null> NNTP-Posting-Host: amoot.imag.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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