예제 #1
0
        public void PlayAllNotes() {

            const int totalIterations = 1000;
            const int delayInSecondsBetweenAudioSnippets = 5;
            var notes = new MusicalNotes();
            var setOfTones = new NoteUtility(_toneProvider);
            var frequencies = notes.GetAllFrequencies();

            for (var i = 0; i < totalIterations; i++) {
                var intervalBoundaries = NumberUtilities.GetRandomInterval(0, 24, 12, _random);
                var frequency0 = frequencies[intervalBoundaries[0]];
                var frequency1 = frequencies[intervalBoundaries[1]];

                setOfTones.PlayNote(notes.GetNoteFromIndex(intervalBoundaries[0]));
                setOfTones.PlayNote(notes.GetNoteFromIndex(intervalBoundaries[1]));
                Console.WriteLine(frequency0);
                Console.WriteLine(frequency1);
                Console.WriteLine(frequency1 - frequency0);

                Thread.Sleep(delayInSecondsBetweenAudioSnippets * 1000);
                setOfTones.PlayNote(notes.GetNoteFromIndex(intervalBoundaries[0]));
                setOfTones.PlayNote(notes.GetNoteFromIndex(intervalBoundaries[1]));
                Thread.Sleep(delayInSecondsBetweenAudioSnippets * 1000);

                var semitoneCount = intervalBoundaries[1] - intervalBoundaries[0];
                var spokenInterval = Intervals.GetInterval(semitoneCount);

                _synth.Speak(spokenInterval);
                Thread.Sleep(delayInSecondsBetweenAudioSnippets * 1000);
            }
        }
예제 #2
0
        public void FrequencyCanBeGotViaIndex() {
            TraceExecutingMethod();
            var notes = new MusicalNotes();
            var frequency = notes.GetNoteFromIndex(KnownIndexForFrequency).Frequency;
            Assert.AreEqual(TestFrequency, frequency);

        }
예제 #3
0
 public void GettingFrequencyViaNonValidIndexThrowsException() {
     TraceExecutingMethod();
     var notes = new MusicalNotes();
     try {
         var dummy = notes.GetNoteFromIndex(999).Frequency;
     }
     catch (KeyNotFoundException e) {
         Assert.AreEqual("No MusicalNote found with an index of [999]", e.Message);
         throw;
     }
 }
예제 #4
0
        public void PlayIntervalsAndConfirmTheirNameNoSound() {

            const int totalIterations = 1000;
            const int sectionCount = 5;
            var iterationsPerSection = totalIterations/sectionCount;

            var notes = new MusicalNotes();
            var upperLimit = notes.GetAllNotes().Count - 1;
            var directionTally = new Dictionary<int, int> {
                {(int) NumberUtilities.Direction.Ascending, 0},
                {(int) NumberUtilities.Direction.Descending, 0}
            };

            for (var i = 0; i < totalIterations; i++) {
                // do a break so that the listener has time to consolidate a bit
                if (i == 0) {
                    Debug.WriteLine($"Section 1");
                } else 
                if (i%iterationsPerSection == 0) {
                    Debug.WriteLine($"Section {i/iterationsPerSection + 1}");
                }
                //we want substantially more ascending than descending:
                var currentDirectionType = i%3 == 0 ? NumberUtilities.Direction.Random : NumberUtilities.Direction.Ascending;

                var interval = NumberUtilities.GetRandomInterval(0, upperLimit, 12, RandomInterval, currentDirectionType);
                notes.GetNoteFromIndex(interval[0]);
                notes.GetNoteFromIndex(interval[1]);
                directionTally[(int) NumberUtilities.GetDirection(interval)]++;
            }

            Debug.WriteLine(directionTally[0]);
            Debug.WriteLine(directionTally[1]);
        }