Page 1 of 1

Questions about PC speaker

Posted: Tue Jul 11, 2006 4:35 pm
by earlz
Well I'm trying to add some basic sound and decided to start with the pc speaker but I don't know some stuff so...
1. which IRQ is PIT channel 2
2. I got some code but I don't understand what it does

Code: Select all

     PIT_CHANNEL_2 = $42;
procedure Sound(frequency : word);
var counter : word;
begin

  { Program the PIT chip }
  counter := PIT_FREQ div frequency;
  Port[PIT_CONTROL] := $B6;
  Port[PIT_CHANNEL_2] := Lo(counter);
  Port[PIT_CHANNEL_2] := Hi(counter);

  { Connect the speaker to the PIT }
  Port[SPEAKER_PORT] := Port[SPEAKER_PORT] or 3;
end;
I don't get what that would do, what is counter suppose to be? an alarm or frequency or what?


and I'll have plenty of other questions as I go more through this tutorial

Re:Questions about PC speaker

Posted: Tue Jul 11, 2006 6:09 pm
by Cjmovie
There is no IRQ, only PIC channel 0 is connected to an IRQ. You'll want square wave mode, and the frequency is the sound's frequency. You'll need to use it in conjuction with channel 0 if you want to time sounds or notes.

Re:Questions about PC speaker

Posted: Thu Jul 13, 2006 5:13 am
by Pype.Clicker
no PC speaker code will ever explain how it could possibly produce sound. To get how this is possible, you need to look at the _wiring_ of the PC motherboard (i mean, the very first one):
[tt]
+-------+
| PIT |-----|AND----> Speaker
+-------+ |
Some output bit in the PPI chip
[/tt]

In other words, if you enable the proper output pin on the Programmable Parallel Interface (now replaced with the keyboard controller), the wave signal generated by the PIT goes to the speaker (and you hear the wave). If you instead disable the bit, the speaker receive constant signal (no sound).

By increasing the frequency of the PIT's square wave, you get higher tones and by toggling the "enable" bit faster, you get shorter tones.

Alternatively, you may arrange the PIT so that it always have a "high" output, and have code that synchronize with another clock (e.g. 8Khz IRQ0) so that you send "1-bit samples" by enabling/disabling the gate. That'll produce ugly sound, but that's how you could have speech or Amiga modules played without a Sound Blaster card on ancient PCs.