Example #1
0
    /// <summary>
    /// Sets the note based on a text note eg. F#
    /// and the octave number.
    /// </summary>
    /// <param name="octave">Octave note is to be played from (0-7)</param>
    /// <param name="note">String note. eg. C or F# or Bb</param>
    private void SetFrequency(int octave, string note)
    {
        // get the frequency
        float frequency = NoteFrequencies.GetFrequency(octave, note);

        // if the note was valid
        if (frequency != 0.0f)
        {
            _frequency  = frequency;
            _octave     = octave;
            _noteLetter = note;
        }
        else // otherwise default to middle C
        {
            _frequency  = NoteFrequencies.GetFrequency(4, "c");
            _octave     = 4;
            _noteLetter = "c";
        }
    }
Example #2
0
 /// <summary>
 /// Play a musical note for given duration
 /// </summary>
 /// <param name="i">Frequency provided by NoteFrequencies enum.</param>
 /// <param name="duration">Time in milliseconds to play sound for.</param>
 public static void PlayNote(NoteFrequencies i, int duration)
 {
     Console.Beep((int)i, duration);
 }