PC Speaker: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(create See also section)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 27:
When the PIT interrupts you, you need to program PIT timer 2 so that it puts the PC Speaker in the "out" position for a fraction of 60 microseconds. For 8-bit audio, the number of microseconds can be calculated like this:
 
<sourcesyntaxhighlight lang="C">
microseconds = (sample * 60) / 255;
</syntaxhighlight>
</source>
 
== Sample Code ==
This will work on real hardware and in QEMU if it started with <code>-audiodev pa,id=speaker -machine pcspk-audiodev=speaker</code>. The code also changes the PIT timer 2 frequency, so you will have to reset that when you're done "beep"ing :)
<sourcesyntaxhighlight lang="c">
//Play sound using built-in speaker
static void play_sound(uint32_t nFrequence) {
Line 66:
//set_PIT_2(old_frequency);
}
</syntaxhighlight>
</source>
 
== See Also ==