• 大小: 22KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: C/C++
  • 标签: c  程序  源代码  

资源简介

C语言写的音乐程序,希望大家支持有源代码

资源截图

代码片段和文件信息

/*  HELLO.C -- Hello world */

#include
#include
#include

main()
{
    int rate = 0;/*音长基数*/
    char sound_high[3];/*音高*/
    float sound_long;/*音长*/
    float music[300][2];
    register int i = 0j = 0;


    FILE *fp = fopen(“music.yan““r“); /*读取乐谱*/


    /*读取乐谱失败*/
    if (fp == NULL)
    {
        printf(“ Error!! no fileplease check!“);

    }

    /*读取音长基数*/
    fscanf(fp “%d“ &rate);

    /*读取所有音符*/
    while(!feof(fp))
    {
        fscanf(fp“%s%f“sound_high&sound_long); 

        /*计算音长*/
        music[j++][0] = rate * sound_long;

        /*判断音高*/
        switch ( sound_high[0] )
        {
            case ‘*‘: /*最高音*/
            {
                switch(sound_high[1])
                {
                    case ‘1‘:
                        music[i++][1] = 1046.5;
                        break;

                    case ‘2‘:
                        music[i++][1] = 1174.7;
                        break;
                
                    case ‘3‘:
                        music[i++][1] = 1318.5;
                        break;

                    case ‘4‘:
                        music[i++][1] = 1396.9;
                        break;

                    case ‘5‘:
                        music[i++][1] = 1568.0;
                        break;

                    case ‘6‘:
                        music[i++][1] = 1760;
                        break;

                    case ‘7‘:
                        music[i++][1] = 1975.5;
                        break;
                }
            }

            case ‘h‘: /*高音*/
            {
                switch(sound_high[1])
                {
                    case ‘1‘:
                        music[i++][1] = 523.3;
                        break;

                    case ‘2‘:
                        music[i++][1] = 587.3;
                        break;
                
                    case ‘3‘:
                        music[i++][1] = 659.3;
                        break;

                    case ‘4‘:
                        music[i++][1] = 698.5;
                        break;

                    case ‘5‘:
                        music[i++][1] = 784.0;
                        break;

                    case ‘6‘:
                        music[i++][1] = 880;
                        break;

                    case ‘7‘:
                        music[i++][1] = 987.8;
                        break;
                }
            }

            case ‘m‘: /*中音*/
            {
                switch(sound_high[1])
                {
                    case ‘1‘:
                        music[i++][1] = 262;
                        break;

                    case ‘2‘:
                        music[i++][1] = 296;
                        break;
                
                    case ‘3‘:
                        music[i++][1] = 329.7;
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        347  2010-01-05 11:19  c 音乐程序\music.yan

     文件       4906  2010-01-05 11:51  c 音乐程序\yan.c

     文件      30222  2010-01-05 11:50  c 音乐程序\YAN.EXE

     文件       2194  2010-01-05 11:50  c 音乐程序\YAN.OBJ

     文件       2855  2010-01-05 11:30  c 音乐程序\YAN.PIF

     目录          0  2010-01-05 14:06  c 音乐程序

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

                40524                    6


评论

共有 条评论