Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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
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.
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.