forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
133 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Sys = Cosmos.System; | ||
using System.Threading; | ||
|
||
namespace BeepDemo | ||
{ | ||
public class Kernel: Sys.Kernel | ||
{ | ||
protected override void BeforeRun() | ||
{ | ||
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back."); | ||
} | ||
protected override void Run() | ||
{ | ||
Console.WriteLine("Run 'Mary Had a Little Lamb'? "); | ||
string ans = Console.ReadLine(); | ||
if (ans.ToLower() == "y" || ans.ToLower() == "yes") | ||
{ | ||
BeepTest.Main(); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Default beep:"); | ||
Console.Beep(); | ||
// Does the follwing: Console.Beep((int)Sys.Notes.Default (800 hertz), (int)Sys.Durations.Default (200 milliseconds) ); | ||
} | ||
} | ||
} | ||
class BeepTest | ||
{ | ||
public static void Main() | ||
{ | ||
// Declare the first few notes of the song, "Mary Had A Little Lamb". | ||
Note[] Mary = | ||
{ | ||
new Note(Tone.B, Duration.QUARTER), | ||
new Note(Tone.A, Duration.QUARTER), | ||
new Note(Tone.GbelowC, Duration.QUARTER), | ||
new Note(Tone.A, Duration.QUARTER), | ||
new Note(Tone.B, Duration.QUARTER), | ||
new Note(Tone.B, Duration.QUARTER), | ||
new Note(Tone.B, Duration.HALF), | ||
new Note(Tone.A, Duration.QUARTER), | ||
new Note(Tone.A, Duration.QUARTER), | ||
new Note(Tone.A, Duration.HALF), | ||
new Note(Tone.B, Duration.QUARTER), | ||
new Note(Tone.D, Duration.QUARTER), | ||
new Note(Tone.D, Duration.HALF) | ||
}; | ||
// Play the song | ||
Play(Mary); | ||
} | ||
|
||
// Play the notes in a song. | ||
protected static void Play(Note[] tune) | ||
{ | ||
foreach (Note n in tune) | ||
{ | ||
if (n.NoteTone == Tone.REST) | ||
{ | ||
Thread.Sleep((int)n.NoteDuration); | ||
} | ||
else | ||
{ | ||
Console.Beep((int)n.NoteTone, (int)n.NoteDuration); | ||
} | ||
} | ||
} | ||
|
||
// Define the frequencies of notes in an octave, as well as | ||
// silence (rest). | ||
protected enum Tone | ||
{ | ||
REST = 0, | ||
GbelowC = 196, | ||
A = 220, | ||
Asharp = 233, | ||
B = 247, | ||
C = 262, | ||
Csharp = 277, | ||
D = 294, | ||
Dsharp = 311, | ||
E = 330, | ||
F = 349, | ||
Fsharp = 370, | ||
G = 392, | ||
Gsharp = 415, | ||
} | ||
|
||
// Define the duration of a note in units of milliseconds. | ||
protected enum Duration | ||
{ | ||
WHOLE = 1600, | ||
HALF = WHOLE / 2, | ||
QUARTER = HALF / 2, | ||
EIGHTH = QUARTER / 2, | ||
SIXTEENTH = EIGHTH / 2, | ||
} | ||
|
||
// Define a note as a frequency (tone) and the amount of | ||
// time (duration) the note plays. | ||
protected struct Note | ||
{ | ||
Tone toneVal; | ||
Duration durVal; | ||
|
||
// Define a constructor to create a specific note. | ||
public Note(Tone frequency, Duration time) | ||
{ | ||
toneVal = frequency; | ||
durVal = time; | ||
} | ||
|
||
// Define properties to return the note's tone and duration. | ||
public Tone NoteTone { get { return toneVal; } } | ||
public Duration NoteDuration { get { return durVal; } } | ||
} | ||
} | ||
/* | ||
This example produces the following results: | ||
This example plays the first few notes of "Mary Had A Little Lamb" | ||
through the computer PC Speaker. | ||
*/ | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters