用C语言弹奏一首《梦中的婚礼》吧!

用C语言弹奏一首《梦中的婚礼》吧!

好像音不太准233,B站链接
本来是按着谱子来的,但是发现节拍虽然按照谱子来的,但是实际上不是...

很喜欢的一首曲子,第一次看见钢琴听到的就是这首曲子,一直一直都特别喜欢。
网站的第三首曲子就是梦中的婚礼,快去听听233

#include<stdio.h>
#include<windows.h>

#define qdo 262 
#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 1460
#define sso1 1661
#define sla1 1865

#define P 4 

#define semibreve 1024*P 
#define minim 512*P     
#define crotchet    256*P
#define quaver    128*P
#define semiquaver    64*P
#define demisemiquaver    32*P
#define hemidemisemiquaver   16*P

//semibreve     全音符 
//minim         二分音符 
//crotchet         四分音符 
//quaver         八分音符 
//semiquaver     十六分音符 
//demisemiquaver 三十二分音符 
//hemidemisemiquaver 六十四分音符 
  
typedef struct 
{
    int freq;   //指定发音的频率,赫兹 
    int duration;//指定发音的时间,毫秒 
    char text[32];//文本内容
}STU;

STU t[]=
    {
        //第1个次拍 
        {0,quaver,""},
        {0,quaver,""},
        {0,quaver,""},
        {0,quaver,""},
        {0,quaver,""},
        {0,quaver,""},
        {0,quaver,""},
        {la, quaver, "la "}, 
        //第2个次拍 
        {la, semiquaver, "la "}, 
        {si, semiquaver, "si "}, 
        {si, semiquaver, "si "}, 
        {do1, semiquaver, "do1 "}, 
        {do1, semiquaver, "do1 "}, 
        {si, semiquaver, "si "}, 
        {si, semiquaver, "si "}, 
        {la, semiquaver, "la "}, 
        {la, semiquaver, "la "}, 
        {mi, semiquaver, "mi "}, 
        {mi, semiquaver, "mi "},
        {do_, semiquaver, "do "}, 
        {do_, semiquaver, "do "}, 
        {qla, semiquaver, "qla "}, 
        {qla, semiquaver, "qla "}, 
        {so, semiquaver, "so \n"}, 
        //第3个次拍 
        {so, semiquaver, "so "}, 
        {fa, semiquaver, "fa "}, 
        {fa, semiquaver, "fa "}, 
        {mi, semiquaver, "mi "}, 
        {fa, semiquaver, "fa "}, 
        {so, semiquaver, "so "}, 
        {fa, quaver, "fa "},
        {fa, crotchet, "fa \n"},
        //第4个次拍 
        {so, semiquaver, "so "}, 
        {so, semiquaver, "so "}, 
        {la, semiquaver, "la "}, 
        {la, semiquaver, "la "}, 
        {si, semiquaver, "si "}, 
        {si, semiquaver, "si "}, 
        {so, semiquaver, "so "}, 
        {so, semiquaver, "so "}, 
        {re, semiquaver, "re "}, 
        {re, semiquaver, "re "},
        {fa, semiquaver, "fa \n"},
        //第5个次拍 
        {fa, semiquaver, "fa "}, 
        {mi, semiquaver, "mi "}, 
        {mi, semiquaver, "mi "}, 
        {re, semiquaver, "re "}, 
        {mi, semiquaver, "mi "}, 
        {fa, semiquaver, "fa "}, 
        {mi, crotchet, "mi\n"},
        
        //第6个次拍          
        {mi, quaver, "mi "}, 
        {qla, semiquaver, "qla "}, 
        {do_, semiquaver, "do "}, 
        {mi, semiquaver, "mi "}, 
        {re, semiquaver, "re "},
        {mi, semiquaver, "mi "},
        
        {qla, quaver, "qla "}, 
        {do_, semiquaver, "do "}, 
        {mi, semiquaver, "mi "}, 
        {re, semiquaver, "re "}, 
        {mi, semiquaver, "mi "}, 
        
        {qla, quaver, "qla "}, 
        {do_, semiquaver, "do "}, 
        {fa, semiquaver, "fa "}, 
        {mi, semiquaver, "mi "}, 
        {fa, semiquaver, "fa "}, 
        
        {qla, quaver, "qla "}, 
        {do_, semiquaver, "do "},
        {fa, semiquaver, "fa "},
        {mi, semiquaver, "mi \n"},
        //第七个次拍 
        {fa, quaver, "fa "},
        {fa, semiquaver, "fa "}, 
        {mi, semiquaver, "mi "}, 
        {fa, semiquaver, "fa "}, 
        {so, semiquaver, "so "}, 
        {so, quaver, "so "}, 
        {so, semiquaver, "so "}, 
        {la, semiquaver, "la "}, 
        {so, semiquaver, "so "}, 
        {la, semiquaver, "la "},
        {mi, crotchet, "mi\n"},
        //第8个次拍 
        {mi1, quaver, "mi1 "}, 
        {la, semiquaver, "la "}, 
        {do1, semiquaver, "do1 "}, 
        {mi1, semiquaver, "mi1 "}, 
        {re1, semiquaver, "re1 "},
        {mi1, semiquaver, "mi1 "},
        
        {la, quaver, "la "}, 
        {do1, semiquaver, "do1 "}, 
        {mi1, semiquaver, "mi1 "}, 
        {re1, semiquaver, "re1 "}, 
        {mi1, semiquaver, "mi1 "}, 
        
        {la, quaver, "la "}, 
        {do1, semiquaver, "do1 "}, 
        {fa1, semiquaver, "fa1 "}, 
        {mi1, semiquaver, "mi1 "}, 
        {sfa1, semiquaver, "sfa1 "}, 
        
        {la, quaver, "la "}, 
        {do1, semiquaver, "do1 "},
        {fa1, semiquaver, "fa1 "},
        {mi1, semiquaver, "mi1 \n"},
        
        //第9个节拍 
        {fa1, quaver, "fa1 "},  
        {fa1, semiquaver, "fa1 "}, 
        {mi1, semiquaver, "mi1 "}, 
        {fa1, semiquaver, "fa1 "}, 
        {sso1, semiquaver, "sso1 "},                //升高半音 
        {so1, quaver, "so1 "}, 
        {so1, semiquaver, "so1 "}, 
        {la1, semiquaver, "la1 "}, 
        {so1, semiquaver, "so1 "}, 
        {la1, semiquaver, "la1 "},
        {mi1, crotchet, "mi1\n"},
    
        //第10个节拍 
        {do1, quaver, "do1 "}, 
        {mi, semiquaver, "mi "}, 
        {mi, semiquaver, "mi "}, 
        {fa, semiquaver, "fa "}, 
        {fa, quaver, "fa "}, 
        {re, semiquaver, "re "}, 
        {re, semiquaver, "re "}, 
        {si, semiquaver, "si "}, 
        {si, quaver, "si "},
        {re, semiquaver, "re "},
        {re, semiquaver, "re "}, 
        {mi, semiquaver, "mi "}, 
        {mi, quaver, "mi "},
        {do_, semiquaver, "do "}, 
        {do_, semiquaver, "do "}, 
        {la, semiquaver, "la "}, 
        {so, semiquaver, "so "}, 
        //第11个节拍 
        {la, quaver, "la "}, 
        {do_, semiquaver, "do "},
        {do_, semiquaver, "do "},
        {re, semiquaver, "re "}, 
        {re, quaver, "re "}, 
        {qsi, semiquaver, "qsi "}, 
        {mi, semiquaver, "mi "}, 
        {re, semiquaver, "re "}, 
        {mi, crotchet, "mi\n"},
        //第12个次拍   
        {do1, quaver, "do1 "}, 
        {do1, semiquaver, "do1 "},  
        {do1, semiquaver,"do1 "},
        {re1, semiquaver, "re1 "}, 
        {re1, quaver, "re1 "}, 
        {do1, semiquaver, "do1 "},
        {si, semiquaver, "si "},
        {la, semiquaver, "la "}, 
        {so, quaver, "so "}, 
        {so, semiquaver, "so "}, 
        {la, semiquaver, "la "}, 
        {so, semiquaver, "so "}, 
        {mi, crotchet, "mi\n"},
        //第13个次拍 
        {do1, quaver, "do1 "}, 
        {do1, semiquaver, "do1 "}, 
        {do1, semiquaver, "do1 "}, 
        {do1,semiquaver,"do1 "},
        {re1, semiquaver, "re1 "}, 
        {re1, quaver, "re1 "}, 
        {do1, semiquaver, "do1 "},
        {si, semiquaver, "si "},
        {la, semiquaver, "la "}, 
        {so, quaver, "so "}, 
        {so, semiquaver, "so "}, 
        {la, semiquaver, "la "}, 
        {so, semiquaver, "so"},
        //第14个次拍 
        {la, semibreve, "la ....\n"},                    
};
int main(void)
{
    int i;
    //结构体数组的长度sizeof(t)/sizeof(STU)得到,总结构体数组大小 / 单个结构体大小
    char c ;
    while(printf("梦中的婚礼,开始播放?Y/N:"),scanf("%c",&c),c=='Y'){
        for (i=0; i<sizeof(t)/sizeof(STU); i++)
        {
            printf("%s",t[i].text);
            Beep(t[i].freq,t[i].duration);
        }        
    }
    return 0;
}
Last modification:June 25th, 2020 at 09:00 pm
如果觉得我的文章对你有用,请随意赞赏

4 comments

  1. Jastry

    都好几天了,咋不更新了

    1. 子不语
      @Jastry

      老史咩0.0

  2. 张鲁腾

    为什么在我电脑上没声音呢,是需要一些插件吗

    1. 子不语
      @张鲁腾

      你的电脑有蜂鸣器吗,应该都会有

Leave a Comment