Question and Answer Database FAQ2007C.txt Creating different frequency sounds from win95 / winnt Category :Windows API Platform :All Product :C++Builder 1.x Question: I want to be able to make the system beeper make pitched sounds from my windows application, this needs to work in both windows NT and 95. How can this be accomplished? Answer: In WindowsNT is is easy, use the Beep() Windows API call, however in Windows 95 this api function is only a little less than useful, you will need to directly access the hardware. this is demonstrated in the following code: The first parameter is the frequency (in Hertz) of the pitch, the second is the duration in milliseconds of the sound. The first part of this function sets the pit and turns the speaker on, the second part (after the Windows API Sleep() call) turns the speaker off. This code WILL NOT work in Winnt, so you must use the Beep() API call for that. //--------------------------------------------------------------------------- void BeepSound(unsigned short pitch, int duration) \{ asm mov bx, pitch asm mov ax, 34DDh asm mov dx, 0012h asm cmp dx, bx asm jnb stop asm div bx asm mov bx, ax asm in al, 61h asm test al, 3 asm jne j1 asm or al, 3 asm out 61h, al asm mov al, 0B6h asm out 43h, al j1: asm mov al, bl asm out 42h, al asm mov al, bh asm out 42h, al stop: ; Sleep(duration); asm in al,61H asm and al, 0fcH asm out 61H, al \} //--------------------------------------------------------------------------- 7/2/98 10:32:32 AM
Last Modified: 30-MAR-00