Example #1
0
        public void SaveHarmonicsContainerInValidStateWhenItstateHasChangedSinceHarmonicDeletedEvent()
        {
            var main           = new HarmonicsContainer();
            var testObj        = new TestObject(main);
            var newActiveIndex = 2;

            testObj.newActiveIndex = newActiveIndex;

            main.ActiveHarmonicChanged += testObj.OnActiveHarmonicChanged;
            main.HarmonicDeleted       += testObj.ChangeHarmonicSelectedIndexOnHarmonicDeleted;
            var h = new Harmonic();

            main.AddNewHarmonic(h);
            main.AddNewHarmonic(h);
            main.AddNewHarmonic(h);
            main.DeleteActiveHarmonic(2);

            Assert.IsTrue(testObj.IsEventHarmonicDeletedInvoked);
            Assert.AreEqual(testObj.deletedIndex, 2);

            Assert.IsTrue(testObj.ExceptionWasThrownInSelectActiveHarmonicMethod);

            Assert.IsTrue(testObj.IsEventActiveHarmonicChangedInvoked);
            Assert.AreEqual(testObj.activeIndex, 1);
            Assert.IsFalse(main.IsEmpty());
        }
Example #2
0
        public static List <NoteLib.Note> GenerateNotesFrom(IScore score)
        {
            Harmonic[] harmonics = new Harmonic[]
            {
                new Harmonic(1.0f, 1.0f, 0.3f),
                new Harmonic(0.4f, 3.0f, 0.3f),
                new Harmonic(0.03f, 8f, 0.1f)
            };

            Instrument          bells     = new Instrument(harmonics, 44100);
            List <NoteLib.Note> notes     = new List <NoteLib.Note>();
            int firstQuarterBeatOfMeasure = 0;

            foreach (Measure m in score.MeasuresWithRepeats)
            {
                foreach (INote note in m.Notes)
                {
                    float pitch    = 88 - note.Pitch;
                    float duration = note.Duration / 4.0f + Overlap;
                    float start    = (note.Offset + firstQuarterBeatOfMeasure) / 4.0f;
                    notes.Add(new NoteLib.Note(bells, 0.3f, pitch, start, duration));
                }
                firstQuarterBeatOfMeasure += m.QuarterBeatsPerBar;
            }
            return(notes);
        }
Example #3
0
 public HarmonicData(Harmonic harmonic)
 {
     Type      = harmonic.Type;
     Amplitude = harmonic.Amplitude;
     Frequency = harmonic.Frequency;
     Phase     = harmonic.Phase;
 }
Example #4
0
        public void SetFrequency_HarmonicPropertiesChangedAfterSetFrequencyWithNullObserver()
        {
            IHarmonic harmonic = new Harmonic();

            harmonic.SetFrequency(10);

            Assert.AreEqual(10, harmonic.GetFrequency());
        }
Example #5
0
        public void SetPhase_HarmonicPropertiesChangedAfterSetPhaseWithNullObserver()
        {
            IHarmonic harmonic = new Harmonic();

            harmonic.SetPhase(10);

            Assert.AreEqual(10, harmonic.GetPhase());
        }
Example #6
0
        public void SetHarmonicKind_HarmonicPropertiesChangedAfterSetHarmonicKindWithNullObserver()
        {
            IHarmonic harmonic = new Harmonic();

            harmonic.SetHarmonicKind(HarmonicKind.Sin);

            Assert.AreEqual(HarmonicKind.Sin, harmonic.GetHarmonicKind());
        }
Example #7
0
        public void TickTock()
        {
            var roi = new Harmonic(1, 0, 90);

            roi.Tick();
            Assert.Equal(1, roi.End.X, 1);
            Assert.Equal(0, roi.End.Y, 1);
        }
Example #8
0
 // Use this for initialization
 void Start()
 {
     harmonic         = GetComponent <Harmonic>();
     boid             = GetComponent <Boid>();
     initialBoidSpeed = boid.maxSpeed;
     initialAmplitude = harmonic.amplitude;
     initialSpeed     = harmonic.speed;
     StartCoroutine("VaryWiggleInterval");
 }
Example #9
0
        public void SetAmplitude_ObserverPropertiesChangedAfterSetAmplitude()
        {
            IHarmonic harmonic         = new Harmonic();
            var       harmonicObserver = new HarmonicObserver();

            harmonic.SetObserver(harmonicObserver);
            harmonic.SetAmplitude(10);

            Assert.IsTrue(harmonicObserver.PropertiesChanged);
        }
Example #10
0
        public void SetHarmonicKind_ObserverPropertiesChangedAfterSetHarmonicKind()
        {
            IHarmonic harmonic         = new Harmonic();
            var       harmonicObserver = new HarmonicObserver();

            harmonic.SetObserver(harmonicObserver);
            harmonic.SetHarmonicKind(HarmonicKind.Sin);

            Assert.IsTrue(harmonicObserver.PropertiesChanged);
        }
Example #11
0
        public void CantGetHarmonicFromEmptyListByIndexAndThrowsException()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();
            var h       = new Harmonic();

            Assert.ThrowsException <IndexOutOfRangeException>(() => main.GetHarmonicByIndex(0));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.GetHarmonicByIndex(-1));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.GetHarmonicByIndex(1));
        }
Example #12
0
        public SingleToneSignal(Harmonic harmonic)
        {
            this.harmonic = harmonic;

            double PeriodToTime = (1 * 2 * Math.PI) / harmonic.Freq;

            Step        = PeriodToTime / PointOnPeriod;
            LeftBorder  = PeriodToTime / -2;
            RightBorder = PeriodToTime / 2;
        }
Example #13
0
        public void SetFrequency_ObserverPropertiesChangedAfterSetFrequency()
        {
            IHarmonic harmonic         = new Harmonic();
            var       harmonicObserver = new HarmonicObserver();

            harmonic.SetObserver(harmonicObserver);
            harmonic.SetFrequency(10);

            Assert.IsTrue(harmonicObserver.PropertiesChanged);
        }
Example #14
0
        public void ChainHarmonics()
        {
            var roi = new Harmonic(1, 0, 1);

            roi.AddHarmonic(1, 0, 1).AddHarmonic(1, 0, 1);
            Assert.NotSame(roi.SubHarmonic.ParentHarmonic, roi.SubHarmonic.SubHarmonic);
            Assert.Null(roi.ParentHarmonic);
            Assert.Equal(roi.SubHarmonic.Origin, roi.End);
            Assert.Equal(roi.SubHarmonic.SubHarmonic.Origin, roi.SubHarmonic.End);
            Assert.Equal(new Point(0, 3), roi.SubHarmonic.SubHarmonic.End);
        }
Example #15
0
        public void CanGetHarmonicFromNonEmptyListByIndexAndReturnHarmonic()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();
            var h       = new Harmonic();

            main.AddNewHarmonic(h);
            var h1 = main.GetHarmonicByIndex(0);

            Assert.AreEqual(h1, h);
        }
Example #16
0
        public void CantGetHarmonicFromNonEmptyListByIndexIfIndexLessThan0OrEqualsOrMoreThanCountAndThrowsException()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();
            var h       = new Harmonic();

            main.AddNewHarmonic(h);

            Assert.ThrowsException <IndexOutOfRangeException>(() => main.GetHarmonicByIndex(-1));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.GetHarmonicByIndex(1));
        }
Example #17
0
        public void GetValueByTime_CreateDefaultHarmonic_GetZeroByAnyTime(double t)
        {
            // Arrange
            var harmonic = new Harmonic();

            // Act
            double result = harmonic.GetValueByTime(t);

            // Assert
            Assert.True(DoubleUtils.EqualsDoubles(0, result));
        }
Example #18
0
        public void CantSelectHarmonicByIndexFromEmptyListAndThrowsException()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();
            var h       = new Harmonic();

            main.ActiveHarmonicChanged += testObj.OnActiveHarmonicChanged;
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.SelectHarmonicByIndex(0));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.SelectHarmonicByIndex(-1));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.SelectHarmonicByIndex(1));
        }
Example #19
0
        //Modulated balanced (Envelope)
        public PM(List <Harmonic> harmonics, Harmonic carrier, double K)
        {
            this.harmonics = harmonics;
            Carrier        = carrier;
            this.K         = K;
            GFreq          = harmonics.MinimalNonZeroFreq();
            double PeriodToTime = (1 * 2 * Math.PI) / GFreq;

            Step        = PeriodToTime / PointOnPeriod;
            LeftBorder  = PeriodToTime / -2;
            RightBorder = PeriodToTime / 2;
        }
Example #20
0
 // Use this for initialization
 void Start()
 {
     if (boid != null)
     {
         harmonic = boid.GetComponent <Harmonic>();
         if (harmonic != null)
         {
             initialAmplitude = harmonic.amplitude;
             theta            = harmonic.theta;
         }
     }
 }
Example #21
0
        public void CanCreateSinHarmonicWith1ParametersAnd0PhaseByDefault()
        {
            var   hType      = HarmonicType.Sin;
            float hAmplitude = 1;
            float hFrequency = 1;
            float hPhase     = 0;
            var   h          = new Harmonic();

            Assert.AreEqual(h.Type, hType);
            Assert.AreEqual(h.Amplitude, hAmplitude);
            Assert.AreEqual(h.Frequency, hFrequency);
            Assert.AreEqual(h.Phase, hPhase);
        }
Example #22
0
        public void CantSelectHarmonicByIndexFromNonEmptyListIfIndexLessThan0OrEqualsToOrMoreThanCountAndThrowsException()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();
            var h       = new Harmonic();

            main.AddNewHarmonic(h);
            main.ActiveHarmonicChanged += testObj.OnActiveHarmonicChanged;
            main.SelectHarmonicByIndex(0);

            Assert.ThrowsException <IndexOutOfRangeException>(() => main.SelectHarmonicByIndex(-1));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.SelectHarmonicByIndex(1));
        }
Example #23
0
        public void CanSelectHarmonicByIndexAndThenInvokeActiveHarmonicChangedEvent()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();
            var h       = new Harmonic();

            main.AddNewHarmonic(h);
            main.ActiveHarmonicChanged += testObj.OnActiveHarmonicChanged;
            main.SelectHarmonicByIndex(0);

            Assert.IsTrue(testObj.IsEventActiveHarmonicChangedInvoked);
            Assert.AreEqual(testObj.activeIndex, 0);
        }
Example #24
0
        public void CanCreateCosHarmonic()
        {
            var   hType      = HarmonicType.Cos;
            float hAmplitude = 1;
            float hFrequency = 2;
            float hPhase     = 3;
            var   h          = new Harmonic(hType, hAmplitude, hFrequency, hPhase);

            Assert.AreEqual(h.Type, hType);
            Assert.AreEqual(h.Amplitude, hAmplitude);
            Assert.AreEqual(h.Frequency, hFrequency);
            Assert.AreEqual(h.Phase, hPhase);
        }
Example #25
0
        public void CantRemoveHarmonicFromNotEmptyListByIndexIfIndexLessThen0OrEqualesOrMoreThanCountAndThrowsException()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();

            main.ActiveHarmonicChanged += testObj.OnActiveHarmonicChanged;
            main.HarmonicDeleted       += testObj.OnHarmonicDeleted;
            var h = new Harmonic();

            main.AddNewHarmonic(h);
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.DeleteActiveHarmonic(-1));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.DeleteActiveHarmonic(1));
            Assert.ThrowsException <IndexOutOfRangeException>(() => main.DeleteActiveHarmonic(2));
        }
Example #26
0
        public void Ctor(double amplify, double phase, double freq)
        {
            var roi = new Harmonic(amplify, phase, freq);

            Assert.Equal(amplify, roi.Length);
            Assert.Equal(freq, roi.Freq);
            Assert.Equal(phase, roi.Phase);
            Assert.Equal(amplify, roi.End.Y, 0);
            Assert.Equal(0, roi.End.X, 0);
            Assert.Null(roi.ParentHarmonic);
            Assert.Null(roi.SubHarmonic);
            Assert.Equal(new Point(0, 0), roi.Origin);
            Assert.Single(roi.ListHarmonics());
        }
Example #27
0
        //Modulated balanced (Envelope)
        public SM(List <Harmonic> harmonics, Harmonic carrier, double K, double Kp, bool rightside)
        {
            this.harmonics = harmonics;
            Carrier        = carrier;
            this.K         = K;
            this.Kp        = Kp;
            this.RightSide = rightside;
            GFreq          = harmonics.MinimalNonZeroFreq();
            double PeriodToTime = (1 * 2 * Math.PI) / GFreq;

            Step        = PeriodToTime / PointOnPeriod;
            LeftBorder  = PeriodToTime / -2;
            RightBorder = PeriodToTime / 2;
        }
Example #28
0
        public void CanAddNewHarmonicAndThenInvokeHarmonicAddedAndActiveHarmonicChangedEvents()
        {
            var testObj = new TestObject();
            var main    = new HarmonicsContainer();

            main.HarmonicAdded         += testObj.OnHarmonicAdded;
            main.ActiveHarmonicChanged += testObj.OnActiveHarmonicChanged;

            var h = new Harmonic();

            main.AddNewHarmonic(h);

            Assert.IsTrue(testObj.IsEventHarmonicAddedInvoked);
            Assert.AreEqual(testObj.addedIndex, 0);
            Assert.IsTrue(testObj.IsEventActiveHarmonicChangedInvoked);
            Assert.AreEqual(testObj.activeIndex, 0);
        }
Example #29
0
        public void GetValueByTime_DifferentTestData_GetExpectedValue(
            double amplitude,
            HarmonicType harmonicType,
            double frequency,
            double t,
            double phase,
            double expected)
        {
            // Arrange
            var harmonic = new Harmonic(amplitude, frequency, phase, harmonicType);

            // Act
            double result = harmonic.GetValueByTime(t);

            // Assert
            Assert.True(DoubleUtils.EqualsDoubles(expected, result));
        }
Example #30
0
    static int Main()
    {
        CritInteger.MaxAndMin();
        Write("\n\n");
        epsilon.Machine();
        Write("\n\n");
        Harmonic.sum_float();
        Write("\n\n");
        Harmonic.sum_double();
        Write("\n\n");
        WriteLine("Checking my approximation function with tau=1e-9 and epsilon=1e-9 for 2 and 2.000000002");
        bool bool_val = isequal.approx(2, 2.000000002);

        Write($"{bool_val}\n");
        WriteLine("Checking my approximation function with tau=1e-9 and epsilon=1e-9 for 2 and 2.0000000002");
        bool_val = isequal.approx(2, 2.0000000002);
        Write($"{bool_val}\n");
        return(0);
    }
Example #31
0
 public void AddTone(Harmonic.WaveType type, bool smooth, float frequency, float amplitude)
 {
     Harmonic tone = new Harmonic(this);
     tone.Type = type;
     tone.Sine.SmoothTransition = smooth;
     tone.Frequency = frequency;
     tone.Amplitude = amplitude;
     Layers.Add(tone);
 }