'=========================================================================== ' Subject: PC SPEAKER DIGITAL SOUND Date: Unknown Date (00:00) ' Author: Edward Schlunder Code: TEXT ' Origin: PC,SPEAKER,DIGITAL,SOUND Packet: SOUND.ABC '=========================================================================== > I'm trying to write some code that plays audio files (VOC, SND, etc.) > through the PC speaker. The audio data I'm working with is 8 bits, > and the PC speaker is only a one bit device. Here's what I'm doing: Nice try, but the PC's Internal Speaker can do about 6 bits. It just takes a little figuring out.. If you set up the PIT correctly, it can be really easy! Here, let me help you.. I'm writing a book on sound and stuff. It will be really cool. It's gonna include information on programming all the sound cards available, such as the SB, AdLib, and GUS. It's also gonna talk about doing some stuff on the Internal speaker, so I've been writing a section on getting different volumes on the PC's Internal Speaker. The book isn't finished by far, but, the part about playing digital sound on the internal speaker is *almost* finished. I'll post this pre-release of BWSB for you.. ___O_/____________________| SNIP |_____________________O_/___ O \ | HERE | O \ > Volume < Some programmers have discovered that they can create different volume settings on the speaker. This is done by giving the speaker +5v and then quickly giving it 0v. Because the speaker is rather slow to responding to the power (when compared to the computer's logic), it does not go fully out, like it should when given +5v. By making the speaker go out only so much and then pulling it back in, we can have different volumes by changing the amount of time that the speaker can move. This sounds like a very timely task, and it is, if you program the speaker directly. Using the PIT to drive the speaker makes the task MUCH easier (not to mention much easier to program!). To do this, we must setup the PIT to do some certain little things. To set it up for doing different volumes, we do the following (Basic source code): OUT &H43, &HB6 'Setup to make no sound OUT &H42, &HFF OUT &H42, 0 OUT &H43, &H90 'Setup to interrupt on terminal 'count OneShot = INP(&H61) OR 3 'Puts the speaker in one shot mode OUT &H61, OneShot After this has been done, any values sent to port 42h tell the PIT what volume the speaker should be at. The speaker, however, has an upper limit to the volume which isn't very loud. The upper limit is 64, any values above that can cause distortion. Lets see what this is doing. The values that you give to port 42h are really telling the PIT how long to delay in between toggles of the speaker. With really small delays, the speaker is moved back in before it can get totally out. This is a quiet noise. With larger delays, the speaker can go completely out before being pulled back in. This creates a loud noise. Now, if you specify a large volume level, the speaker will go completely out, but the PIT will still be delaying.. The PIT will eventually pull it back, but obviously, this will be no louder than a value between 64 and 255. Infact, it could be softer, the extended delays would slow down the number of vibrations it makes, making less noise (I'm not sure about this idea).. This the distortion I had talked about earlier. After you are finished using the speaker in different volumes (usually at the end of your program), you should set the PIT back the way it was before, so that other programs will run correctly. If you don't do this, any tone made by an other program will continue on, never stopping because of your program. This is very annoying for the user, you have to reboot usually to make the tone stop. This is what is necessary to reset the PIT: OUT &H43, &HB6 OneShot = INP(&H61) AND &HFC OUT &H61, OneShot