有恒心,是这个问题的继续
https://bbs.bccn.net/thread-470525-1-1.html
没用过WinIO,可能是个驱动层的应用。
抄一段C代码参考:
//使用WinIO驱动PC喇叭发声
#include "WinIo.h"
#define TIMER_FREQUENCY 1193167 //; 1,193,167 Hz
#define
OCTAVE
2
#define PITCH_C
523
// 523,25 Hz
#define PITCH_Cs
554
// 554,37 Hz
#define PITCH_D
587
// 587,33 Hz
#define PITCH_Ds
622
// 622,25 Hz
#define PITCH_E
659
// 659,25 Hz
#define PITCH_F
698
// 698,46 Hz
#define PITCH_Fs
740
// 739,99 Hz
#define PITCH_G
784
// 783,99 Hz
#define PITCH_Gs
831
// 830,61 Hz
#define PITCH_A
880
// 880,00 Hz
#define PITCH_As
988
// 987,77 Hz
#define PITCH_H
1047
//1046,50 Hz
// We are going to play c-major chord
#define
TONE_1
(TIMER_FREQUENCY/(PITCH_C*OCTAVE))
#define
TONE_2
(TIMER_FREQUENCY/(PITCH_E*OCTAVE))
#define
TONE_3
(PITCH_G*OCTAVE)
void Beep(DWORD pitch) {
DWORD data=0;
//Timer 8253-5 (AT: 8254.2).
data=0xb6;
SetPortVal(0x43,data,1);
data=pitch&0xff;
SetPortVal(0x42,data,1);
data=(pitch>>8)&0xff;
SetPortVal(0x42,data,1);
//speaker on
GetPortVal(0x61,&data,1);
data|=0x03;
SetPortVal(0x61,data,1);
Sleep(30);
//speaker off
GetPortVal(0x61,&data,1);
data&=0xFC;
SetPortVal(0x61,data,1);
}
int main() {
WinIoInit();//调用WinIO初始化函数
for(int i=0;i<10;i++) {
Beep(TONE_1);
Beep(TONE_2);
Beep(TONE_3);
}
WinIoExit();//退出WinIO库
return 0;
}