用c语言编曲

来源:互联网 发布:数控铣床编程动漫图案 编辑:程序博客网 时间:2024/04/28 07:58
Frequency in hertz (semitones above or below middle C)Octave →
Note ↓
012345678910C16.352 (−48)32.703 (−36)65.406 (−24)130.81 (−12)261.63 (±0)523.25 (+12)1046.5 (+24)2093.0 (+36)4186.0 (+48)8372.0 (+60)16744.0 (+72)C/D17.324 (−47)34.648 (−35)69.296 (−23)138.59 (−11)277.18 (+1)554.37 (+13)1108.7 (+25)2217.5 (+37)4434.9 (+49)8869.8 (+61)17739.7 (+73)D18.354 (−46)36.708 (−34)73.416 (−22)146.83 (−10)293.66 (+2)587.33 (+14)1174.7 (+26)2349.3 (+38)4698.6 (+50)9397.3 (+62)18794.5 (+74)E/D19.445 (−45)38.891 (−33)77.782 (−21)155.56 (−9)311.13 (+3)622.25 (+15)1244.5 (+27)2489.0 (+39)4978.0 (+51)9956.1 (+63)19912.1 (+75)E20.602 (−44)41.203 (−32)82.407 (−20)164.81 (−8)329.63 (+4)659.26 (+16)1318.5 (+28)2637.0 (+40)5274.0 (+52)10548.1 (+64)21096.2 (+76)F21.827 (−43)43.654 (−31)87.307 (−19)174.61 (−7)349.23 (+5)698.46 (+17)1396.9 (+29)2793.8 (+41)5587.7 (+53)11175.3 (+65)22350.6 (+77)F/G23.125 (−42)46.249 (−30)92.499 (−18)185.00 (−6)369.99 (+6)739.99 (+18)1480.0 (+30)2960.0 (+42)5919.9 (+54)11839.8 (+66)23679.6 (+78)G24.500 (−41)48.999 (−29)97.999 (−17)196.00 (−5)392.00 (+7)783.99 (+19)1568.0 (+31)3136.0 (+43)6271.9 (+55)12543.9 (+67)25087.7 (+79)A/G25.957 (−40)51.913 (−28)103.83 (−16)207.65 (−4)415.30 (+8)830.61 (+20)1661.2 (+32)3322.4 (+44)6644.9 (+56)13289.8 (+68)26579.5 (+80)A27.500 (−39)55.000 (−27)110.00 (−15)220.00 (−3)440.00 (+9)880.00 (+21)1760.0 (+33)3520.0 (+45)7040.0 (+57)14080.0 (+69)28160.0 (+81)B/A29.135 (−38)58.270 (−26)116.54 (−14)233.08 (−2)466.16 (+10)932.33 (+22)1864.7 (+34)3729.3 (+46)7458.6 (+58)14917.2 (+70)29834.5 (+82)B30.868 (−37)61.735 (−25)123.47 (−13)246.94 (−1)493.88 (+11)987.77 (+23)1975.5 (+35)3951.1 (+47)7902.1 (+59)15804.3 (+71)31608.5 (+83)

上表来自维基百科,争取以后看懂



关键函数:Beep,Sleep(包含于头文件windows.h)


两只老虎:

#include <stdio.h>#include <windows.h>const int BASE = 500;int note[8] = {0, 440, 494, 554, 587, 659, 740, 830};int main(){    FILE *music = fopen("two tiger.txt", "r");    int num; double note_mul, time_mul;    while(~fscanf(music, "%d%lf%lf", &num, note_mul, &time_mul))        Beep(note[num] * note_mul, BASE * time_mul);    system("pause");}

每个音有三个参数:音高,高音低音,音符长短

BASE是一拍的时间,单位是ms


two tiger.txt :

1 1 1   2 1 1   3 1 1   1 1 11 1 1   2 1 1   3 1 1   1 1 13 1 1   4 1 1   5 1 23 1 1   4 1 1   5 1 25 1 0.75   6 1 0.25   5 1 0.75   4 1 0.25   3 1 1   1 1 15 1 0.75   6 1 0.25   5 1 0.75   4 1 0.25   3 1 1   1 1 11 1 1   5 1 1   1 1 2 1 1 1   5 1 1   1 1 2


求解释:

有些音发不出来,感觉和读入速度有关,直接把文件内容写到源代码里效果有所改善






1 0