Beepで音楽
.NET2.0でBeepがサポートされ、しかも周波数も指定できるのでちょっと演奏させてみました。
#region Using directives using System; using System.Collections.Generic; using System.Text; #endregion namespace ConsoleApplication1 { enum SCALE { C = 0, D = 2, E = 4, F = 5, G = 7, A = 9, B = 11, } class Program { static int Frequency(int octave, SCALE scale) { // 等分平均律なのでちょっと音程が違・・・わない模様(^^; return (int)(440 * Math.Pow(2.0, ( (octave - 5) * 12 + (int)scale + 3) / 12.0)); } static void Main(string[] args) { int tempo = 120; int note4 = 60 * 1000 / tempo; int note8 = note4 / 2; int note2 = note4 * 2; int note1 = note4 * 4; // かえるのうた・・・じゃなくてジーザスのアレ Console.Beep(Frequency(4, SCALE.C), note8); Console.Beep(Frequency(4, SCALE.D), note8); Console.Beep(Frequency(4, SCALE.E), note2); Console.Beep(Frequency(4, SCALE.F), note4); Console.Beep(Frequency(4, SCALE.E), note4); Console.Beep(Frequency(4, SCALE.D), note8); Console.Beep(Frequency(4, SCALE.C), note8); Console.Beep(Frequency(4, SCALE.E), note2); } } }
ジーザスの重要な攻略ヒントですね。<今どきの人は知らんって。(^^;
あと、音階を計算で求めているので、微妙に音程が外れてます。そんなことないとフォローをいただく。やねうらおさんありがとー。わたしゃ、音楽は苦手で・・・(^^;