C++语言程序能让电脑直发出特定频率的声音吗?

C++语言程序能让电脑直发出特定频率的声音吗?,第1张

beep() 可以发出特定频率的声音,用电脑内的“蜂鸣器”发音,不能设置音量。
#include <stdioh>
#include <stdlibh>
#include <windowsh>
main()
{
Beep(523,500);Beep(587,500);Beep(659,500);Beep(698,500);Beep(784,500);
Beep(880,500);Beep(980,500);Beep(1060,500);
Sleep(500);
Beep(523,500);Beep(587,500);
Beep(659,500);Beep(698,500);Beep(784,500);
}
---
播放 wav音乐, avi 可以直接调用函数。VC++ 编译器 带有相应的库。
例如 avi:
#include <Vfwh>
#pragma comment (lib, "Vfw32lib")
h_wnd2 = MCIWndCreate(hwnd,NULL,0,"sylvtwtavi");
MCIWndPlay(h_wnd2);
播放 wav音乐:
#include <mmsystemh>
#pragma comment (lib, "winmmlib")
PlaySound (TEXT("D:\\xyz\\zzdwav"), NULL, SND_ASYNC | SND_NODEFAULT);
===
MP3格式 要自己解码。

windowsh 的 Beep 函数可以发音。下面是 多来米法少。
如果你要同 键盘 键 联系起来,可以自己 添加判断 条件,如果 按某键则对应某声音(频率,发音时间长度)。
#include <stdioh>
#include <stdlibh>
#include <windowsh>
main()
{
Beep(523,500);
Beep(587,500);
Beep(659,500);
Beep(698,500);
Beep(784,500);
Beep(880,500);
Beep(980,500);
Beep(1060,500);
Sleep(500);
Beep(523,500);
Beep(587,500);
Beep(659,500);
Beep(698,500);
Beep(784,500);
}

Ah 夜が更けたら YO GA FU KE TA RA
Ah 迎来深夜时
どこからともなく DO KO KA RA TO MO NA KU
好像从哪里
ざわめく Night city ZA WA ME KU
传来骚动 Night city
Hey listen,
Nanana Whistle beep beep
お祭り(みたいに) Busy zy zy O MA TSU RI MI TAI(其实是TA I ,但是最好连读起来) NI
祭典(一般的气氛)
聴いたことない Music KI I TA KO TO NA I
从未听过的 Music
NEON と月の Spotlight NE ON TO TSU KI
NEON和月光Spotlight
DJ, Turn up! Yeah
Everybody take it easy
そうじゃないと损じゃない SOU(SO U,也是连读起来) JA NA I TO SON(宋的发音) JA NA I?
不放松岂不是损失?
1,2,3 and just Break it down!
Party night さあ beep beep 騒ごう SA WA GOU (连读 够的发音)
Party night 来吧 beep beep 躁起来
集まって Bui Bui 踊ろう A TSU MATTE(妈-忒的发音,中间有个促音) O DO ROU
集合吧 Bui Bui 跳舞吧
Boom, Boom, Boom
Bang, Bang, Bang, Bang
Nanana Make it pop, pop
夜通し ぶっ飞ばして朝まで YO DO O SHI BUTTO(不-头的发音,中间有个促音) BA SHI TE A SA MA DE
通宵达旦 一直闹到清晨
Get ya, Get ya, Get ya, Get ya, Get ya CRUNK!!!!
上がりたきゃ Put ya hands in the air (Hey) A GA RI TA KYA
能上的话就上来吧 Put ya hands in the air (Hey)
游びたいなら叫べ “We don't care”(Hey) A SO BI TAI NA RA SA KE BE
想玩的话就喊出来 “We don't care”(Hey)
(Hoot Hoot) Bring it on, Bring it on
(Hoot Hoot) Here we go, Here we go
最新のSound このままBurn up SAI SHIN NO SOUND KO NO MA MA
最新的Sound 就这样Burn up
Gotta make you bounce baby 今すぐGet up I MA SU GU get up
Gotta make you bounce baby 趁现在Get up

只要你有乐谱。根据乐理,就可以走在调上。比如:
你可以写一个文件,存储你自己的声音格式:
struct tagSound
{
int frequency; //频率
int soundDelay; //发音时间(单位ms)
int nosoundDelay; //发完音之后暂停的时间(单位ms)
};
1。音符与频率的关系
========低音部分
低1DO:262
#1DO#:277
低2RE:294
#2RE#:311
低3MI:330
低4FA:349
#4FA#:370
低5SO:392
#5SO#:415
低6LA:440
#6LA#:466
低7SI:494
========中音部分=低音X2
中1DO:523 956us FC44;
#1DO#:554 902us
中2RE:578 865us FC9F;
#2RE#:622 803us
中3MI:659 759us FD09;
中4FA:698 716us FD34
#4FA#:740
中5SO:784 638us FD82
#5SO#:831
中6LA:880 568us FDC8
#6LA#:932
中7SI:988 506us FE06
========高音部分=中音X2
高1DO:1046
#1DO#:1109
高2RE:1175
#2RE#:1245
高3MI:1318
高4FA:1480
#4FA#:1480
高5SO:1568
#5SO#:1661
高6LA:1760
#6LA#:1865
高7SI:1976
“#”表示半音,用于上升或下降半个音
2。频率的产生
利用定时器来控制IO口的高低变化实现
周期=1/频率
半周期中断产生IO口电平
定时时间常数按照单片机的方式计算

3。音乐节拍的产生
每个音符用1个字节,字节的高4位代表音符的高低,低4位代表
音符的节拍,如果 1节拍是04秒,则1/4拍就是01秒。
其他节拍为1/4拍的整数倍。

4。节拍与节拍码对照表
节拍 节拍数 节拍数
1 1/4 1/8
2 2/4 2/8
3 3/4 3/8
4 1 1/2
5 5/4 5/8
6 6/4 6/8
8 2 1
A 10/4 5/4
C 3 12/8
F 15/4

曲调 1/4拍的延迟时间 1/8拍的延迟时间
4/4 125ms 62ms
3/4 187ms 94ms
2/4 250ms 125ms
不过,真的好不准。
这样就可以编辑文件了。
送你一个函数:
void MyDelay(long tt) /暂停tt个百分之一秒/
{
struct time now,last;
gettime(&last);
gettime(&now);
while((((nowti_sec-lastti_sec)100+nowti_hund-lastti_hund))<tt)
{
gettime(&now);
}
}
这个函数可以暂停 001tt 秒。
循环使用下面的句子:
Beep(frequency,soundDelay);
MyDelay(nosoundDelay/10);
就可以模拟那个音乐了。
在C语言里可以循环使用:
sound(frequency);
MyDelay(soundDelay/10);
nosound();
MyDelay(nosoundDelay/10);
就可以了

1chinked out
2stone beam||使叮当响出2stone 光线
3有一种东西是那种好像很多人跑马拉松,在衣服前面挂着的那张纸,写着名字或者编号,那个东西叫什么?||A kind of thing is that kind of to seem the many people run a Marathon, hanging in front of the clothes of that paper, write a well-known word perhaps serial number, what does that thing call||A kind of thing is that kind of to seem the many people run a Marathon, hanging in front of the clothes of that paper, write a well-known word perhaps serial number, what does that thing call那个东西也是好像一个小背心,上边写着什么标志,有代表性的。||That thing also is seem a small vest, ascend a side to write what marking, there is representative英文发音是 beep,不过不确定拼写,所以过来问问那个东西叫什么?||That thing also is seem a small vest, ascend a side to write what marking, there is representativeEnglish pronunciation is a beep, however does the indetermination put together to write, so come over to ask that thing to call what怎么拼?


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13210783.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-21
下一篇 2023-06-21

发表评论

登录后才能评论

评论列表(0条)

保存