震惊!!C++居然可以发出声音!

11 篇文章 0 订阅

一点都不震惊

当然我们还是要闲聊一下C++是怎么从处理数据转行到音乐的。

一 函数叫啥

C++里发出声音的函数叫Beep()。

咋用呢>>Beep(1200,100)就可以发出滴的声音。

二 度娘解释

第一个数指定要发出的频率。

指定发音的时长(毫秒)。

三 你真的看懂了吗

我打赌你没看懂。我都看不懂

唯一的问题就出在频率上,所以我们不用管它。

我们只用知道啥是do re mi fa sol la si就行(还等什么,出门右转百度见)

当我们知道音调时就可以用C++来听音乐了(当然是全损音乐)

四 音乐!!!

首先我们把do到si的数值写下来:

#include <cstdio>
#include <windows.h>
#define qdo 262//q前缀为低音,1后缀为高音,s前缀为半音阶
#define qre 294
#define qmi 330
#define qfa 349
#define qso 392
#define qla 440
#define qsi 494
#define do 523
#define re 578
#define mi 659
#define fa 698
#define so 784
#define la 880
#define si 988
#define do1 1046
#define re1 1175
#define mi1 1318
#define fa1 1480
#define so1 1568
#define la1 1760
#define si1 1976
#define sqdo 277
#define sqre 311
#define sqfa 370
#define sqso 415
#define sqla 466
#define sdo 554
#define sre 622
#define sfa 740
#define sso 831
#define sla 932
#define sdo1 1046
#define sre1 1245
#define sfa1 1480
#define sso1 1661
#define sla1 1865

接下来就是声音了,do re mi 就这么写↓↓

Beep(do,100);
Beep(re,100);
Beep(mi,100);

于是我们就可以用C++编音乐了。

如果有人懒的话来听听这个↓↓

#include <cstdio>
#include <windows.h>
#define qdo 262
#define qre 294
#define qmi 330     //q前缀为低音,1后缀为高音,s前缀为半音阶
#define qfa 349
#define qso 392
#define qla 440
#define qsi 494
#define do 523
#define re 578
#define mi 659
#define fa 698
#define so 784
#define la 880
#define si 988
#define do1 1046
#define re1 1175
#define mi1 1318
#define fa1 1480
#define so1 1568
#define la1 1760
#define si1 1976
#define sqdo 277
#define sqre 311
#define sqfa 370
#define sqso 415
#define sqla 466
#define sdo 554
#define sre 622
#define sfa 740
#define sso 831
#define sla 932
#define sdo1 1046
#define sre1 1245
#define sfa1 1480
#define sso1 1661
#define sla1 1865

int main()
{

    int pai = 400,ban = 200,ting = 128;
    Beep(la,ban);Beep(si,ban);Sleep(ting);
    Beep(do1,pai+ban);Beep(si,ban);Sleep(ting);Beep(do1,pai);Sleep(ting);Beep(mi1,pai);Sleep(ting);
    Beep(si,3*pai);Sleep(ting);Beep(mi,ban);Beep(mi,ban);
    Beep(la,ban+pai);Beep(so,ban);Sleep(ting);Beep(la,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(so,2*pai);Sleep(ting);Sleep(pai);Beep(mi,ban);Sleep(ting/2);Beep(mi,ban);Sleep(ting/2);
    Beep(fa,pai+ban);Beep(mi,ban);Sleep(ting);Beep(fa,ban);Beep(do1,ban+pai);Sleep(ting);
    Beep(mi,2*pai);Sleep(ting);Sleep(ban);Beep(do1,ban);Sleep(ting/2);Beep(do1,ban);Sleep(ting/2);Beep(do1,ban);Sleep(ting/2);
    Beep(si,ban+pai);Beep(sfa,ban);Sleep(ting);Beep(sfa,pai);Beep(si,pai);Sleep(ting);
    Beep(si,2*pai);Sleep(ting);Sleep(pai);Beep(la,ban);Beep(si,ban);Sleep(ting);
    Beep(do1,pai+ban);Beep(si,ban);Sleep(ting);Beep(do1,pai);Sleep(ting);Beep(mi1,pai);Sleep(ting);
    Beep(si,2*pai);Sleep(ting);Sleep(pai);Beep(mi,ban);Sleep(20);Beep(mi,ban);Sleep(ting);
    Beep(la,pai+ban);Beep(so,ban);Sleep(ting);Beep(la,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(so,3*pai);Sleep(ting+ban);Beep(mi,ban);Sleep(ting/2);
    Beep(fa,pai);Sleep(ting);Beep(do1,ban);Beep(si,ban);Sleep(20);Beep(si,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(re1,ban);Sleep(20);Beep(re1,ban);Sleep(20);Beep(mi1,ban);Sleep(ting/2);Beep(do1,pai);Sleep(ting+pai);
    Beep(do1,pai);Beep(si,ban);Sleep(ting);Beep(la,ban);Sleep(20);Beep(la,ban);Sleep(ting);Beep(si,pai);Sleep(ting);Beep(sso,pai);Sleep(ting);
    Beep(sso,2*pai);Sleep(ting+pai);Beep(do1,ban);Beep(re1,ban);Sleep(ting);
    Beep(mi1,pai+ban);Beep(re1,ban);Sleep(ting);Beep(mi1,pai);Sleep(ting);Beep(fa1,pai);Sleep(ting);
    Beep(re1,2*pai);Sleep(pai+ting);Beep(so,ban);Sleep(20);Beep(so,ban);Sleep(ting);
    Beep(do1,ban);Beep(si,ban);Sleep(ting);Beep(do1,pai);Sleep(ting);Beep(mi1,pai);Sleep(ting);
    Beep(mi1,2*pai);Sleep(ting+2*pai);
    Beep(la,ban);Beep(si,ban);Sleep(ting);Beep(do1,pai);Sleep(ting);Beep(si,pai);Sleep(ting);Beep(re1,ban);Sleep(20);Beep(re1,ban);Sleep(ting);
    Beep(do1,pai+ban);Beep(so,ban);Sleep(20);Beep(so,pai);Sleep(pai+ting);
    Beep(fa1,pai);Sleep(ting);Beep(mi1,pai);Sleep(ting);Beep(re1,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(mi1,4*pai);
    Beep(mi1,pai*2);Sleep(pai+ting);Beep(mi1,pai);Sleep(ting);
    Beep(la1,2*pai);Sleep(ting);Beep(so1,pai);Sleep(ting);Beep(so1,pai);Sleep(ting);
    Beep(mi1,ban);Sleep(ting/2);Beep(re1,ban);Sleep(ting);Beep(do1,pai);Sleep(ting+ban);Beep(do1,ban);Sleep(ting);
    Beep(re1,pai);Sleep(ting);Beep(do1,ban);Beep(re1,ban);Sleep(20);Beep(re1,ban);Sleep(ting);Beep(so1,pai);Sleep(ting);
    Beep(mi1,2*pai);Sleep(ting+pai);Beep(mi,pai);Sleep(ting);
    Beep(la1,2*pai);Sleep(ting);Beep(so1,2*pai);Sleep(ting);
    Beep(mi1,ban);Beep(re1,ban);Sleep(ting);Beep(do1,2*pai);Sleep(ting+ban);Beep(do1,ban);Sleep(ting);
    Beep(re1,pai);Sleep(ting);Beep(do1,ban);Beep(re1,ban);Sleep(20);Beep(re1,ban);Sleep(ting);Beep(si,pai);Sleep(ting);
    Beep(la,2*pai);Sleep(ting);Beep(la,ban);Beep(si,ban);
    Beep(do1,pai+ban);Beep(si,ban);Sleep(ting);Beep(do1,pai);Sleep(ting);Beep(mi1,pai);Sleep(ting);
    Beep(si,3*pai);Sleep(ting);Beep(mi,ban);Beep(mi,ban);
    Beep(la,ban+pai);Beep(so,ban);Sleep(ting);Beep(la,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(so,2*pai);Sleep(ting);Sleep(pai);Beep(mi,ban);Sleep(ting/2);Beep(mi,ban);Sleep(ting/2);
    Beep(fa,pai+ban);Beep(mi,ban);Sleep(ting);Beep(fa,ban);Beep(do1,ban+pai);Sleep(ting);
    Beep(mi,2*pai);Sleep(ting);Sleep(ban);Beep(do1,ban);Sleep(ting/2);Beep(do1,ban);Sleep(ting/2);Beep(do1,ban);Sleep(ting/2);
    Beep(si,ban+pai);Beep(sfa,ban);Sleep(ting);Beep(sfa,pai);Beep(si,pai);Sleep(ting);
    Beep(si,2*pai);Sleep(ting);Sleep(pai);Beep(la,ban);Beep(si,ban);Sleep(ting);
    Beep(do1,pai+ban);Beep(si,ban);Sleep(ting);Beep(do1,pai);Sleep(ting);Beep(mi1,pai);Sleep(ting);
    Beep(si,2*pai);Sleep(ting);Sleep(pai);Beep(mi,ban);Sleep(20);Beep(mi,ban);Sleep(ting);
    Beep(la,pai+ban);Beep(so,ban);Sleep(ting);Beep(la,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(so,3*pai);Sleep(ting+ban);Beep(mi,ban);Sleep(ting/2);
    Beep(fa,pai);Sleep(ting);Beep(do1,ban);Beep(si,ban);Sleep(20);Beep(si,pai);Sleep(ting);Beep(do1,pai);Sleep(ting);
    Beep(re1,ban);Sleep(20);Beep(re1,ban);Sleep(20);Beep(mi1,ban);Sleep(ting/2);Beep(do1,pai);Sleep(ting+pai);
    Beep(la,4*pai);
    Sleep(1000);

}

请各位音乐大佬高抬贵手别喷跑调

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值