Example #1
0
        public void PlayIntervalsAndConfirmTheirName() {

            const int totalIterations = 10;
            const int sectionCount = 2;
            const int iterationsPerSection = totalIterations / sectionCount;
            const int secondsToSleep = 5;
            var notes = new MusicalNotes();
            var setOfTones = new NoteUtility(_toneProvider);
            var upperLimit = notes.GetAllNotes().Count - 1;

            SpeakIntroduction();
            for (var i = 0; i < totalIterations; i++) {
                // do a break so that the listener has time to consolidate a bit
                if (i % iterationsPerSection == 0) {
                    _synth.Speak($"This is; Musical Intervals: Section {i / iterationsPerSection + 1}");
                }
                //we want substantially more ascending than descending intervals - this spread gives about 80%:
                var currentDirectionType = i % 3 == 0 ? NumberUtilities.Direction.Random : NumberUtilities.Direction.Ascending;
                var interval = NumberUtilities.GetRandomInterval(0, upperLimit, 12, _random, currentDirectionType);

                if (i < (totalIterations/2)) {
                    // play the voice/piano versions...
                    setOfTones.PlayIntervalWithCommentary(interval, secondsToSleep, "Emm", true);
                }
                else {
                    setOfTones.PlayIntervalWithCommentary(interval, secondsToSleep);
                }
            }


        }
Example #2
0
        public void FrequencyCanBeGotViaSequence() {
            TraceExecutingMethod();
            var notes = new MusicalNotes();
            var frequency = notes.GetNoteFromSequence(KnownSequenceForFrequency).Frequency;
            Assert.AreEqual(TestFrequency, frequency);

        }
Example #3
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);
            }
        }
Example #4
0
 public void EachFrequencyInTheCollectionsNaturalOrderIsHigherThanThePrevious() {
     var notes = new MusicalNotes();
     var previousFrequency = 0;
     foreach (var frequency in notes.GetAllFrequencies()) {
         Console.WriteLine(frequency);
         Assert.IsTrue(frequency > previousFrequency, 
             $"The current frequency {frequency} is not higher than the previous frequency {previousFrequency}");
         previousFrequency = frequency;
     }
 }
Example #5
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;
     }
 }
Example #6
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]);
        }