/// <summary> /// Playes a musical note at the speaker. /// </summary> /// <param name="musicalNote">The musical note to be played.</param> /// <param name="duration">The time duration in milliseconds for which to play the note.</param> public static void Play(MusicalNote musicalNote, int duration) { double frequency = GetFrequency(musicalNote); int frequencyInteger = Convert.ToInt32(frequency); Console.Beep(frequencyInteger, duration); }
public SongEvent(float occursAt, int voiceNumber, float volume, MusicalNote note) { OccursAt = occursAt; VoiceNumber = voiceNumber; Note = note; Volume = volume; }
public virtual List <IMusicalNote> GetMusicalNotes(float[] pFft) { var notes = new List <IMusicalNote>(); for (int i = 1; i < pFft.Length - 1; i++) { //if (pFft[i] < 0.0005f) if (pFft[i] < 0.025f) { continue; } //calculate the frequence relative to position "i" in FFT var frequence = (i * 44100.0f) / pFft.Length; //Low cut in 96,89941Hz if (frequence <= 96.89941f) { continue; } //check if pFft[i] is a local maximum if ((pFft[i] > pFft[i - 1]) && (pFft[i] > pFft[i + 1])) { var note = new MusicalNote(frequence, pFft[i]); notes.Add(note); } } return(notes); }
public void AdvanceLevel() { LevelNumber++; if (LevelNumber >= 59) { WinGame(); return; } var octave = CurrentNote.Octave; var index = MusicalScale.NoteOrder.IndexOf(CurrentNote.Name); index--; if (index < 0) { index += 12; octave--; } var newPitch = MusicalScale.NoteOrder[index]; CurrentNote = new MusicalNote(newPitch, octave, NoteTimbre.Ah); StartLevel(); }
public void Operator_Greater_Ok() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = new MusicalNote("A#4"); Assert.IsTrue(b > a); Assert.IsFalse(a > b); }
public void Operator_LessOrEqual_OneNull() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = null; Assert.IsFalse(a <= b); Assert.IsFalse(b <= a); }
public void Operator_LessOrEqual_Equal() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = new MusicalNote("A4"); Assert.IsTrue(a <= b); Assert.IsTrue(b <= a); }
public void Operator_Less_Ok() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = new MusicalNote("A#4"); Assert.IsTrue(a < b); Assert.IsFalse(b < a); }
public void Operator_Equal_JustOneNull() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = null; Assert.IsFalse(a == b); Assert.IsFalse(b == a); }
public void Operator_Equal_BothNull() { MusicalNote a = null; MusicalNote b = null; Assert.IsTrue(a == b); Assert.IsTrue(b == a); }
public void Operator_Equal_Ok() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = new MusicalNote("A4"); Assert.IsTrue(a == b); Assert.IsTrue(b == a); }
protected sealed override void OnNoteStart(ENoteColour aNoteColour, MusicalNote note) { if (aNoteColour == noteColour) { Activate(note); m_isActive = true; } }
protected sealed override void OnNoteStop(ENoteColour aNoteColour, MusicalNote note) { if (aNoteColour == noteColour) { Deactivate(note); m_isActive = false; } }
public void Operator_GreaterOrEqual_Equal() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = new MusicalNote("A4"); Assert.IsTrue(b >= a); Assert.IsTrue(a >= b); }
public void Operator_Equal_Different() { MusicalNote a = new MusicalNote("A4"); MusicalNote b = new MusicalNote("A#4"); Assert.IsTrue(a != b); Assert.IsTrue(b != a); }
public static void PlayNote(MusicalNote note, MusicalNoteValue duration, uint bpm) { uint Return1 = 0; uint Return2 = 0; uint Return3 = 0; uint Return4 = 0; Call(Kernel.Shared.SystemCalls.PlayNote, (uint)note, (uint)duration, bpm, ref Return1, ref Return2, ref Return3, ref Return4); }
public void MusicalNote_Octave_NegativeOk() { var octaves = -3; var note = new MusicalNote("A3"); var note2 = note.Octave(octaves); Assert.AreEqual(note.Value, note2.Value); Assert.AreEqual(note.Number + octaves, note2.Number); }
protected override void Awake() { base .Awake(); /* * var chooser = new ProbabilityChooser<int>(); * chooser.AddItem(0, 0.1f); * chooser.AddItem(1, 0.2f); * chooser.AddItem(2, 0.3f); * chooser.AddItem(3, 0.4f); * * int[] chosens = new int[4]; * * for(int i = 0;i < 10000;i++) * { * int chosen = chooser * .ChooseItem(); * * chosens[chosen]++; * } * * * Debug * .Log($"0 had probability of 0.1 and was chosen {chosens[0]} times"); * * * Debug * .Log($"1 had probability of 0.2 and was chosen {chosens[1]} times"); * * * Debug * .Log($"2 had probability of 0.3 and was chosen {chosens[2]} times"); * * * Debug * .Log($"3 had probability of 0.4 and was chosen {chosens[3]} times"); */ LevelNumber = 0; BackgroundSprites = Resources .LoadAll <Sprite>("Images/UI/beachsunset"); SongComposer composer = new SongComposer(); SongPlayer.SongFinished += SongPlayer_SongFinished; CurrentNote = new MusicalNote("C", 5, NoteTimbre.Ah); SetSingerState(false); StartLevel(); }
public void MusicalNote_A4_ById() { var note = new MusicalNote("A4"); Assert.AreEqual("A4", note.ToString()); Assert.AreEqual(NoteValue.A, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(440.0f, note.Frequence); Assert.AreEqual(0f, note.Cents); }
public int PlayNote(MusicalNote note) { int voice = m_instrument.PlayNote(note); if (voice == -1) { UnityEngine.Debug.Log("Failed to play note, err: " + m_instrument.GetLastErrorMessage()); } return(voice); }
public bool PlayNote(ENoteColour colour, MusicalNote note) { int voice = m_instrumentSource.StartNote(note); bool success = voice != -1; if (success) { SetPlayingVoice(colour, voice); m_events.playerNoteStartEvent.Invoke(colour, note); } return(success); }
public void MusicalNote_ContructFromStringId() { { var note = new MusicalNote("A4"); Assert.AreEqual("A4", note.ToString()); Assert.AreEqual(NoteValue.A, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(440.0f, note.Frequence); Assert.AreEqual(0f, note.Cents); } { var note = new MusicalNote("C5"); Assert.AreEqual("C5", note.ToString()); Assert.AreEqual(NoteValue.C, note.Value); Assert.AreEqual(5, note.Number); Assert.AreEqual(523.25116f, note.Frequence); Assert.AreEqual(0f, note.Cents); } { var note = new MusicalNote("D8"); Assert.AreEqual("D8", note.ToString()); Assert.AreEqual(NoteValue.D, note.Value); Assert.AreEqual(8, note.Number); Assert.AreEqual(4698.63623f, note.Frequence); Assert.AreEqual(0f, note.Cents); } { var note = new MusicalNote("Bb4"); Assert.AreEqual("Bb4", note.ToString()); Assert.AreEqual(NoteValue.Bb, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(466.1637573f, note.Frequence); Assert.AreEqual(0f, note.Cents); } { var note = new MusicalNote("A#4"); Assert.AreEqual("Bb4", note.ToString()); Assert.AreEqual(NoteValue.Bb, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(466.1637573f, note.Frequence); Assert.AreEqual(0f, note.Cents); } }
public void AllC() { var note3 = new MusicalNote("C3"); var note4 = new MusicalNote("C4"); var note5 = new MusicalNote("C5"); var note6 = new MusicalNote("C6"); var note7 = new MusicalNote("C7"); Assert.AreEqual(note3.NoteColor(), note4.NoteColor()); Assert.AreEqual(note4.NoteColor(), note5.NoteColor()); Assert.AreEqual(note5.NoteColor(), note6.NoteColor()); Assert.AreEqual(note6.NoteColor(), note7.NoteColor()); }
void TriggerNoteStart(ENoteColour colour, MusicalNote note) { // Pass info to the StateMachine through the Animator. m_animator.SetInteger("NoteColour", (int)colour); m_animator.SetInteger("NoteTone", note.tone); m_animator.SetFloat("NoteVolume", (float)note.volume); m_animator.SetFloat("NotePanning", (float)note.panning); // Triggering the transition to the Playing state! m_animator.ResetTrigger("TNoteStopped"); m_animator.SetTrigger("TNoteStarted"); m_pressedColours.Add(colour); }
public void MusicalNote_FromStringUnvalid(string a) { MusicalNote?obj = null; try { obj = new MusicalNote(a, 0); } catch (ArgumentException e) { } Assert.AreEqual(null, obj); }
public void MusicalNote_FromStringValid(string a) { MusicalNote?obj = null; try { obj = new MusicalNote(a, 0); } catch (ArgumentException e) { } Assert.AreEqual("A4: 440", obj.ToString()); }
public void MusicalNote_CheckFrequencyUnvalid(float a) { MusicalNote?obj = null; try { obj = new MusicalNote("A4", a, 0); } catch (ArgumentException e) { } Assert.AreEqual(null, obj); }
static void Main() { MusicalNote n = new MusicalNote(); //n.ImportToBinary(3, 2, 4, true, true, false, false, 0, 0); Console.WriteLine(n.AsEncoded()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); }
public void MusicalNote_NotePreciseNotes() { float diferenceBetween_A_Bb = 26.1637573f; //Positive Cents { var note = new MusicalNote(440.0f + diferenceBetween_A_Bb); Assert.AreEqual("Bb4", note.ToString()); Assert.AreEqual(NoteValue.Bb, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(440.0f + diferenceBetween_A_Bb, note.Frequence); Assert.AreEqual(0f, note.Cents); } //Positive Cents { var difference = 20; var note = new MusicalNote(440.0f + diferenceBetween_A_Bb / difference); Assert.AreEqual("A4", note.ToString()); Assert.AreEqual(NoteValue.A, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(440.0f, note.Frequence); Assert.AreEqual(100 / difference, note.Cents); } //Negative Cents { var difference = -20; var note = new MusicalNote(440.0f + diferenceBetween_A_Bb / difference); Assert.AreEqual("A4", note.ToString()); Assert.AreEqual(NoteValue.A, note.Value); Assert.AreEqual(4, note.Number); Assert.AreEqual(440.0f, note.Frequence); Assert.AreEqual(100 / difference, note.Cents); } //Oitave 2*freq(A4) => A5 { var note = new MusicalNote(440.0f * 2); Assert.AreEqual("A5", note.ToString()); Assert.AreEqual(NoteValue.A, note.Value); Assert.AreEqual(5, note.Number); Assert.AreEqual(440.0f * 2, note.Frequence); Assert.AreEqual(0, note.Cents); } }
/// <summary> /// /// </summary> /// <returns>true on success, false on failure.</returns> public bool StopNote(ENoteColour colour) { int voice = GetPlayingVoice(colour); Assert.IsTrue(voice >= 0 && voice < m_instrumentSource.GetNumberVoices()); MusicalNote note = m_instrumentSource.GetNote(voice); bool success = m_instrumentSource.StopNote(voice); if (success) { UnsetPlayingVoice(colour); m_events.playerNoteStopEvent.Invoke(colour, note); } return(success); }
public void PlayNote(MusicalNote note, MusicalNoteValue duration, uint bpm) { uint dur_ms = (uint)duration * 60 * 1000 / (bpm * 16); if (note == MusicalNote.Silent) { Wait(dur_ms); } else { PlaySound((int)note); Wait(dur_ms); MuteSound(); } }