C语言发声函数

Python076

C语言发声函数,第1张

TC 试:

#include<dos.h>

#include<conio.h>

#include<stdlib.h>

/* this founction plays sound until hit any key */

void mysound()

{

long freq

while(!kbhit()){/* while no keyboard hit, play sound */

for(freq=200Lfreq<2000Lfreq+=200L){

sound(freq)/*play freq sound*/

delay(200)/*delay 200ms*/

}

}

nosound()/* stop playing */

}

void main()

{

mysound()

}

---------------

VC++ 试:

#include <stdio.h>

#include <stdlib.h>

#include <windows.h>

main()

{

Beep(523,500)

Beep(587,500)

Beep(659,500)

Beep(698,500)

Beep(784,500)

Sleep(500)

Beep(523,500)

Beep(587,500)

Beep(659,500)

Beep(698,500)

Beep(784,500)

}

------

wintc 试验上两个。

按英文。

scanf --- 由 scan 和 f 组成。 scan 扫描的意思,普通话音“斯看”,f 按字母读音 “爱夫”,f 是 formated (有格式)缩写。连读“斯看-爱夫”。

printf --- 由 print 和 f 组成。print 打印,普通话音 扑林特,其中扑 不带韵母地发音。 f 按字母读音 “爱夫”,f 是 formated (有格式)缩写。连读 扑林特-爱夫

gets -- 由 get 和 s 组成。 get 取得的意思,普通话音“盖特”,其中特 不带韵母地发音. s 按字母读音. s -- strings 缩写。

fscanf -- 由f , scan 和 f 组成。两个f 分别按字母读音 “爱夫。连读“爱夫-斯看-爱夫”。

其他类推。

函数void sound(unsigned frequency)

以指定频率打开PC扬声器

nosound :关闭PC扬声器

原型为: void nosound(void)

delay 用于将程序的执行暂停一段时间(毫秒)

原型为:void delay(unsigned milliseconds)

如delay(5000)表示延迟5秒

sound()函数用于让pc喇叭发声,nosound()函数用于使正在发声的pc喇叭静音。要使程序中的发声的具体方法,是调用sound()函数并延迟一定时间,然后使用nosound()函数静音,具体语句实现方法举例如下:

sound(100)

delay(100)

nosound()

它们三个都在“dos.h”里面,

至于d(x,y,z)应该是程序员自己定义的函数,我没见过。