Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Console BEEP Methods, Notation, and Generation

0.00/5 (No votes)
13 Aug 2012 1  
Hark back to the days of text based adventure games, and simple PC, speaker sound.

Introduction

Hark back to the days of text based adventure games, and simple PC, speaker sound.

Background 

In an effort to learn C#, my first project was a text-based adventure game based on "The Hyperion Project" tutorial from XNA Extreme 101 (3D Buzz).  Along the way, I added a considerable amount of code to further enhance the project -- one of which was the addition of sound. 

I found several examples, some of which were quite good -- unfortunately, most were incomplete, contained incorrect frequencies, and/or lacked any examples.

Obviously, the PC Speaker holds very little relevance in this day-and-age -- nevertheless, I hope that this will be useful to someone out there. 

Note Assignment and Frequencies 

The following represents the complete scale -- however, please be aware that many of the lower notes will be extremely quiet and/or completely inaudible. 

In addition, the commented notes fall below the frequency range of the Beep method (which is between 37Hz and 32767Hz).

   #region ▌Notes Assignment & Frequencies▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
// ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
	/* Outside Frequency Range
	int C0  = (int) 16.35;
	int C0s = (int) 17.32;      // C#0/Db0
	int D0  = (int) 18.35;      
	int D0s = (int) 19.45;      // D#0/Eb0
	int E0  = (int) 20.60;      
	int F0  = (int) 21.83;      
	int F0s = (int) 23.12;      // F#0/Gb0
	int G0  = (int) 24.50;      
	int G0s = (int) 25.96;      // G#0/Ab0
	int A0  = (int) 27.50;      
	int A0s = (int) 29.14;      // A#0/Bb0
	int B0  = (int) 30.87;      
	int C1  = (int) 32.70;      
	int C1s = (int) 34.65;      // C#1/Db1
	int D1  = (int) 36.71;      
	*/
	int D1s = (int) 38.89;      // D#1/Eb1
	int E1  = (int) 41.20;      
	int F1  = (int) 43.65;      
	int F1s = (int) 46.25;      // F#1/Gb1
	int G1  = (int) 49.00;      
	int G1s = (int) 51.91;      // G#1/Ab1
	int A1  = (int) 55.00;      
	int A1s = (int) 58.27;      // A#1/Bb1
	int B1  = (int) 61.74;      
	int C2  = (int) 65.41;      
	int C2s = (int) 69.30;      // C#2/Db2
	int D2  = (int) 73.42;      
	int D2s = (int) 77.78;      // D#2/Eb2
	int E2  = (int) 82.41;      
	int F2  = (int) 87.31;      
	int F2s = (int) 92.50;      // F#2/Gb2
	int G2  = (int) 98.00;
	int G2s = (int) 103.83;     // G#2/Ab24
	int A2  = (int) 110.00;
	int A2s = (int) 116.54;     // A#2/Bb2
	int B2  = (int) 123.47;     
	int C3  = (int) 130.81;
	int C3s = (int) 138.59;     // C#3/Db3
	int D3  = (int) 146.83;     
	int D3s = (int) 155.56;     // D#3/Eb3
	int E3  = (int) 164.81;     
	int F3  = (int) 174.61;     
	int F3s = (int) 185.00;     // F#3/Gb3
	int G3  = (int) 196.00;     
	int G3s = (int) 207.65;     // G#3/Ab3
	int A3  = (int) 220.00;     
	int A3s = (int) 233.08;     // A#3/Bb3
	int B3  = (int) 246.94;
	int C4  = (int) 261.63;     // Middle C <≡══───-─ -
	int C4s = (int) 277.18;     // C#4/Db4
	int D4  = (int) 293.66;     
	int D4s = (int) 311.13;     // D#4/Eb4
	int E4  = (int) 329.63;     
	int F4  = (int) 349.23;     
	int F4s = (int) 369.99;     // F#4/Gb4
	int G4  = (int) 392.00;     
	int G4s = (int) 415.30;     // G#4/Ab4
	int A4  = (int) 440.00;     
	int A4s = (int) 466.16;     // A#4/Bb4
	int B4  = (int) 493.88;     
	int C5  = (int) 523.25;     
	int C5s = (int) 554.37;     // C#5/Db5
	int D5  = (int) 587.33;     
	int D5s = (int) 622.25;     // D#5/Eb5
	int E5  = (int) 659.26;     
	int F5  = (int) 698.46;     
	int F5s = (int) 739.99;     // F#5/Gb5
	int G5  = (int) 783.99;     
	int G5s = (int) 830.61;     // G#5/Ab5
	int A5  = (int) 880.00;     
	int A5s = (int) 932.33;     // A#5/Bb5
	int B5  = (int) 987.77;
	int C6  = (int) 1046.50;
	int C6s = (int) 1108.73;    // C#6/Db6
	int D6  = (int) 1174.66;    
	int D6s = (int) 1244.51;    // D#6/Eb6
	int E6  = (int) 1318.51;    
	int F6  = (int) 1396.91;    
	int F6s = (int) 1479.98;    // F#6/Gb6
	int G6  = (int) 1567.98;    
	int G6s = (int) 1661.22;    // G#6/Ab6
	int A6  = (int) 1760.00;    
	int A6s = (int) 1864.66;    // A#6/Bb6
	int B6  = (int) 1975.53;    
	int C7  = (int) 2093.00;    
	int C7s = (int) 2217.46;    // C#7/Db7
	int D7  = (int) 2349.32;    
	int D7s = (int) 2489.02;    // D#7/Eb7
	int E7  = (int) 2637.02;    
	int F7  = (int) 2793.83;    
	int F7s = (int) 2959.96;    // F#7/Gb7
	int G7  = (int) 3135.96;    
	int G7s = (int) 3322.44;    // G#7/Ab7
	int A7  = (int) 3520.00;    
	int A7s = (int) 3729.31;    // A#7/Bb7
	int B7  = (int) 3951.07;    
	int C8  = (int) 4186.01;    
	int C8s = (int) 4434.92;    // C#8/Db8
	int D8  = (int) 4698.64;    
	int D8s = (int) 4978.03;    // D#8/Eb8
// ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄          
   #endregion  

Note Durations

   #region ▌Note Durations▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
// ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
	int longa   =       4000;   // longa note
	int ddble   =       3000;   // dotted double whole note
	int dble    =       2000;   // double whole note
	int whol    =       1000;   // whole note
	int half    =       500;    // half note
	int qrtr    =       250;    // quarter note
	int eghth   =       125;    // eighth note
	int sxtnth  = (int) 62.50;  // sixteenth note
	int thr2nd  = (int) 31.25;  // thirty-second note
// ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄          
   #endregion 

Sample 

The following is just one of the examples contained in the source code.

Here is my attempt at accurately recreating the Main Theme from the game Space Quest (originally created by Mark Crowe, (C) Sierra Online). 

   #region ▌Sample▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
// ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
 // ┌────────────────────────────────────────────────────┐
 // │ Space Quest                   ~  'Main Theme'      │
 // │ by Mark Crowe                 ~  (C) Sierra Online │
 // │ Recreated by Dustin Halstead                       │
 // └────────────────────────────────────────────────────┘
	Thread.Sleep(500);
	Console.Beep(C5 , 400);
	Console.Beep(C5 , sxtnth);
	Console.Beep(F5 , 600);
	Console.Beep(G5 , half);
	Console.Beep(A5 , half);
	Console.Beep(D6 , 130);
	Console.Beep(C6 , 120);
	Console.Beep(A5s, 150);
	Console.Beep(C6 , whol);
	Thread.Sleep(600);
	Console.Beep(D6 , 130);
	Console.Beep(C6 , 120);
	Console.Beep(A5s, qrtr);
	Console.Beep(C6 , 550);
	Console.Beep(A5s, half);
	Console.Beep(A5 , half);
	Console.Beep(A5 , 140);
	Console.Beep(F5 , 120);
	Console.Beep(A5 , qrtr);
	Console.Beep(G5 , 1250);
	Console.WriteLine("            - ─ -──┤ Press Any Key ├──- ─ -\n");
	Console.ReadLine();
// ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄          
   #endregion 

Special thanks to ... 

The Michigan Technological University (specifically their Physics Department) publication on the Frequencies for equal-tempered scale

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here