使扬声器发出警告音

版权声明:原创文章转载时请附上原文链接 https://blog.csdn.net/aniven/article/details/556233

Winnt以上直接使用API
BOOL Beep(

    DWORD dwFreq, // sound frequency, in hertz
    DWORD dwDuration  // sound duration, in milliseconds
   );

函數
void PlayWarningSound(int freq,int delay)
{
    const int scale = 1193180;
    WORD freqTemp = (WORD)(scale/freq);

    asm
    {
        in al,61h;
        or al,3;
        out 61h,al;
        mov al,0xb6;
        out 43h,al;
        movax,freqTemp;
        out 42h,al;
        mov al,ah;
        out 42h,al;
    }
    Sleep ( delay ) ;
    asm 
    {
        in al,0x61;
        and al,0xfc;
        out 0x61,al;
    }
}

//-------------------------------------
函數參數 freq:聲音頻率
        delay:發聲時間

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页