Пример #1
0
        public static float EaseInOut(double linearStep, EasingType type)
        {
            switch (type)
            {
            case EasingType.Step:
                return(linearStep < 0.5 ? 0 : 1);

            case EasingType.Linear:
                return((float)linearStep);

            case EasingType.Sine:
                return(Sine.EaseInOut(linearStep));

            case EasingType.Quadratic:
                return(Power.EaseInOut(linearStep, 2));

            case EasingType.Cubic:
                return(Power.EaseInOut(linearStep, 3));

            case EasingType.Quartic:
                return(Power.EaseInOut(linearStep, 4));

            case EasingType.Quintic:
                return(Power.EaseInOut(linearStep, 5));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown EasingType");
            }
        }
Пример #2
0
        public static void Test(Controller autd)
        {
            var config = new SilencerConfig();

            autd.Send(config);

            const double x = Controller.DeviceWidth / 2;
            const double y = Controller.DeviceHeight / 2;
            const double z = 150;

            var center = new Vector3d(x, y, z);

            var g1 = new Focus(center);
            var g2 = new GSPAT();

            g2.Add(center + new Vector3d(30.0, 0.0, 0.0), 1.0);
            g2.Add(center - new Vector3d(30.0, 0.0, 0.0), 1.0);

            var gain = new Grouped(autd);

            gain.Add(0, g1);
            gain.Add(1, g2);
            var mod = new Sine(150); // AM sin 150 Hz

            autd.Send(mod, gain);
        }
Пример #3
0
 private void Update()
 {
     if (isActive)
     {
         timetoswitch -= Time.deltaTime;
         float     num           = 1f - timetoswitch / timeperswing;
         float     num2          = (float)Sine.EaseInOut((double)num, (double)lastPos.x, (double)(destination.x - lastPos.x), 1.0);
         float     num3          = (float)Sine.EaseInOut((double)num, (double)lastPos.y, (double)(destination.y - lastPos.y), 1.0);
         Transform transform     = base.transform;
         float     x             = num2;
         float     y             = num3;
         Vector3   localPosition = base.transform.localPosition;
         transform.localPosition = new Vector3(x, y, localPosition.z);
         if (!(timetoswitch > 0f))
         {
             base.transform.localPosition = destination;
             if (remainingcount > 0 || infinite)
             {
                 timetoswitch = timeperswing;
                 UpdateShake();
                 remainingcount--;
             }
             else
             {
                 isActive = false;
                 base.transform.localPosition = srcPos;
             }
         }
     }
 }
Пример #4
0
    // Start is called before the first frame update
    void Start()
    {
        // make "mySignal" so demo works initially
        Signal mySignal = new Sine(440, 500) * new ASR(0.1, 0.1, 0.1);

        Library.SaveSignal(mySignal, "mySignal");
    }
 // Static void method with same signature as "Main" is always
 // file base name:
 //
 /// <summary>
 /// VTK test Main method
 /// </summary>
 public static void vtkImplicitFunctionSubclassTest(string[] args)
 {
     using (Sine s1 = new Sine())
     {
       System.Console.Error.WriteLine(s1.ToString());
     }
 }
Пример #6
0
        public static float EaseInOut(double linearStep, EasingType type)
        {
            switch (type)
            {
            case EasingType.Step:
                return(linearStep < 0.5 ? 0 : 1);

            case EasingType.Linear:
                return((float)linearStep);

            case EasingType.Sine:
                return(Sine.EaseInOut(linearStep));

            case EasingType.Quadratic:
                return(Power.EaseInOut(linearStep, 2));

            case EasingType.Cubic:
                return(Power.EaseInOut(linearStep, 3));

            case EasingType.Quartic:
                return(Power.EaseInOut(linearStep, 4));

            case EasingType.Quintic:
                return(Power.EaseInOut(linearStep, 5));
            }
            throw new NotImplementedException();
        }
Пример #7
0
        public void CalculateTest(double firstValue, double expected)
        {
            var calculator   = new Sine();
            var actualResult = calculator.Calculate(firstValue);

            Assert.AreEqual(expected, actualResult, 0.001);
        }
Пример #8
0
 private void OnAttachedToHand(Hand hand)
 {
     hadInterpolation = this.rigidbody.interpolation;
     bracelet         = hand.GetBracelet();
         Signal sig   =  new Sine(100)   * new Envelope(0.1, 0.1);
         bracelet.tactors.VibrateAll(sig);
 }
 // Static void method with same signature as "Main" is always
 // file base name:
 //
 /// <summary>
 /// VTK test Main method
 /// </summary>
 public static void vtkImplicitFunctionSubclassTest(string[] args)
 {
     using (Sine s1 = new Sine())
     {
         System.Console.Error.WriteLine(s1.ToString());
     }
 }
Пример #10
0
        public void GenerateWaveformCurrentSource()
        {
            var sine      = new Sine();
            var generator = new CurrentSourceGenerator();

            var parameters = new ParameterCollection
            {
                new ValueParameter("1"), // pin
                new ValueParameter("0"), // pin
                new BracketParameter()
                {
                    Name       = "sine",
                    Parameters = new ParameterCollection()
                    {
                        new ValueParameter("0"),
                        new ValueParameter("1"),
                        new ValueParameter("2000"),
                    },
                },
            };

            var context = Substitute.For <ICircuitContext>();

            context.WaveformReader.Supports("sine", context).Returns(true);
            context.WaveformReader.Generate(Arg.Any <string>(), Arg.Any <ParameterCollection>(), Arg.Any <ICircuitContext>()).Returns(sine);

            var entity = generator.Generate("i1", "i1", "i", parameters, context);

            Assert.NotNull(entity);
            Assert.IsType <CurrentSource>(entity);
        }
Пример #11
0
        public static void UnaryOperationsWithDifferentOperatorsAreNotEqual()
        {
            var op1 = new Negation(One);
            var op2 = new Sine(One);

            Assert.True(op1 != op2);
            Assert.True(op2 != op1);
        }
Пример #12
0
        // normally one seperates ui and engine, as the other experiments do, but here I did it the fast way.
        public WaveAudio viblab_Generate()
        {
            WaveAudio w;

            // get source
            if (this.vibLab_chkSound.Checked)
            {
                if (this.m_vibLab_filename == null)
                {
                    MessageBox.Show("You haven't opened a sound."); return(null);
                }
                //I think we already loaded this. So it's kind of wasteful. Too tired to fix this though.

                w = new WaveAudio(this.m_vibLab_filename);
            }
            else
            {
                double freq = (this.vibLab_source_bar.Value / 100.0) * 440 + 100;
                w = new Sine(freq, 0.7).CreateWaveAudio(20.0);
            }
            if (vibLab_panel1.Visible)
            {
                if (vibLab_chkTrem1.Checked)
                {
                    w = Effects.Tremolo(w, this.vibLab_valueFreq1, this.vibLab_valueWidth1);
                }
                else
                {
                    w = Effects.Vibrato(w, this.vibLab_valueFreq1, this.vibLab_valueWidth1);
                }
            }
            if (vibLab_panel2.Visible)
            {
                if (vibLab_chkTrem2.Checked)
                {
                    w = Effects.Tremolo(w, this.vibLab_valueFreq2, this.vibLab_valueWidth2);
                }
                else
                {
                    w = Effects.Vibrato(w, this.vibLab_valueFreq2, this.vibLab_valueWidth2);
                }
            }
            if (vibLab_panel3.Visible)
            {
                if (vibLab_chkTrem3.Checked)
                {
                    w = Effects.Tremolo(w, this.vibLab_valueFreq3, this.vibLab_valueWidth3);
                }
                else
                {
                    w = Effects.Vibrato(w, this.vibLab_valueFreq3, this.vibLab_valueWidth3);
                }
            }

            return(w);
        }
Пример #13
0
        public void InOutInverse_InputInRange_ReturnsExpectedValue()
        {
            Ease  ease = new Sine();
            float y    = 0.6f;

            float expected = 0.5641f;
            float actual   = ease.InOutInverse(y);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #14
0
        public void InOut_InputAboveRange_ReturnsDestination()
        {
            Ease  ease = new Sine();
            float x    = 1.5f;

            float expected = ease.Scale.Y;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #15
0
    public void Vibrate()
    {
        if (!enabled)
        {
            return;
        }
        var sig = new Sine(f0) * new ASR(0.1, 0.1, 0.1);

        hub.session.Play((int)channel, sig);
    }
Пример #16
0
        public void InOutInverse_InputAboveRange_ReturnsDestination()
        {
            Ease  ease = new Sine();
            float y    = 1.6f;

            float expected = ease.Scale.X;
            float actual   = ease.InOutInverse(y);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #17
0
        public void In_InputBelowRange_ReturnsOrigin()
        {
            Ease  ease = new Sine();
            float x    = -0.5f;

            float expected = 0;
            float actual   = ease.In(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #18
0
        public void InInverse_InputBelowRange_ReturnsOrigin()
        {
            Ease  ease = new Sine();
            float y    = -0.6f;

            float expected = 0;
            float actual   = ease.InInverse(y);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #19
0
        public void InOut_InputInRange_ReturnsExpectedValue()
        {
            Ease  ease = new Sine();
            float x    = 0.6f;

            float expected = 0.6545f;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #20
0
    static void Main(string[] args)
    {
        Session s = new Session();

        s.Open();

        // Sequences allow to you order multiple Signals in time.

        // Most simply, you can concatenate two or more signals:
        Signal sigA = new Sine(440) * new ASR(1, 1, 1);
        Signal sigB = new Square(440) * new ADSR(1, 1, 1, 1);

        Sequence seq1 = new Sequence();

        seq1.Push(sigA).Push(sigB);

        Console.WriteLine(sigA.length); // 3 s
        Console.WriteLine(sigB.length); // 4 s
        Console.WriteLine(seq1.length); // 7 s

        s.PlayAll(seq1);
        Sleep(seq1.length);

        // You can also add delay, pause, and fade with scalar values:
        Sequence seq2 = new Sequence();

        seq2.Push(1).Push(sigA).Push(2).Push(sigB).Push(-1).Push(sigA); // 1 s delay, 2 s pause, 1 s fade

        Console.WriteLine(seq2.length);                                 //12 s

        s.PlayAll(seq2);
        Sleep(seq2.length);

        // Of course, Sequences of Sequences is possible:
        Sequence seq3 = new Sequence();

        seq3.Push(seq1).Push(seq2);     // note this will also modify seq1
        Console.WriteLine(seq3.length); // 19, we won't play this one :)

        // The << operator inserts a Signal at the Sequence head position,
        // and then moves it forward or backward. You can get/set the head position
        // manually for the next << operation:

        Console.WriteLine(seq2.head);             // 12
        seq2.head = 2;                            // set back to 2
        seq2.Push(new Noise() * new Envelope(1)); // 1 s of noise starts at the 2 second mark

        // You can accomplish the same thing with the insert function
        seq2.Insert(new Noise() * new Envelope(1), 4); // 1 s of noise starts at the 4 second mark

        s.PlayAll(seq2);
        Sleep(seq2.length); // still 12 s long because the inserted noise didn't extend its length

        s.Dispose();
    }
Пример #21
0
        /// =================================================
        /// <summary>
        /// Creates the neural network with the given configuration
        /// </summary>
        ///
        /// <returns></returns>
        public Cerebro Build()
        {
            if (this.inputNeurons <= 0)
            {
                throw new System.InvalidOperationException(
                          $"The input neuron count is invalid: {this.inputNeurons}"
                          );
            }

            if (this.layerConfigs.Count == 0)
            {
                throw new System.InvalidOperationException("The layer configuration is empty");
            }

            Layer[] layers          = new Layer[this.layerConfigs.Count];
            int     lastNeuronCount = this.inputNeurons;

            for (int i = 0; i < this.layerConfigs.Count; i++)
            {
                LayerConfig config = this.layerConfigs[i];

                IActivator activator;
                switch (config.type)
                {
                case LayerType.Sine:
                    activator = new Sine();
                    break;

                case LayerType.Tanh:
                    activator = new Tanh();
                    break;

                case LayerType.Sigmoid:
                default:
                    activator = new Sigmoid();
                    break;
                }

                layers[i]       = new Layer(lastNeuronCount, config.neuronCount, activator);
                lastNeuronCount = config.neuronCount;
            }

            Cerebro net = new Cerebro(layers);

            if (this.genome != null)
            {
                net.SetGenome(this.genome);
            }
            else
            {
                net.Initialize(this.weightsBiasAmplitude);
            }

            return(net);
        }
Пример #22
0
        public void InInverse_ChangedScaleInputBelowRange_ReturnsOrigin()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Sine(scale);
            float  y     = -1;

            float expected = 0;
            float actual   = ease.InInverse(y);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #23
0
        public void InOutInverse_ChangedScaleInputAboveRange_ReturnsDestination()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Sine(scale);
            float  y     = 6.1f;

            float expected = ease.Scale.X;
            float actual   = ease.InOutInverse(y);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #24
0
        public void InInverse_ChangedScaleInputInRange_ReturnsExpectedValue()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Sine(scale);
            float  y     = 2.5f;

            float expected = 2.414f;
            float actual   = ease.InInverse(y);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #25
0
        public void InOut_ChangedScaleInputInRange_ReturnsExpectedValue()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Sine(scale);
            float  x     = 2.5f;

            float expected = 4.148f;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #26
0
        public void Out_ChangedScaleInputBelowRange_ReturnsOrigin()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Sine(scale);
            float  x     = -1.1f;

            float expected = 0;
            float actual   = ease.Out(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #27
0
        public void Out_ChangedScaleInputAboveRange_ReturnsDestination()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Sine(scale);
            float  x     = 11.1f;

            float expected = ease.Scale.Y;
            float actual   = ease.Out(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Пример #28
0
    private static void sine_transform_test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SINE_TRANSFORM_TEST01 demonstrates that the transform is its own inverse.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 February 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       i;
        const int n = 10;

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("SINE_TRANSFORM_TEST01:");
        Console.WriteLine("  SINE_TRANSFORM_DATA does a sine transform of data");
        Console.WriteLine("  defined by a vector.");
        Console.WriteLine("");
        Console.WriteLine("  Demonstrate that the transform is its own inverse.");
        Console.WriteLine("  Let R be a random N vector.");
        Console.WriteLine("  Let S be the transform of D.");
        Console.WriteLine("  Let T be the transform of E.");
        Console.WriteLine("  Then R and T will be equal.");

        double[] r = UniformRNG.r8vec_uniform_01_new(n, ref seed);
        double[] s = Sine.sine_transform_data(n, r);
        double[] t = Sine.sine_transform_data(n, s);

        Console.WriteLine("");
        Console.WriteLine("     I      R(I)        S(I)        T(I)");
        Console.WriteLine("");

        for (i = 0; i < n; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + r[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + s[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + t[i].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Пример #29
0
    private void OnTriggerEnter(Collider other)
    {
        var try_bc = other.gameObject.GetComponent <BraceletCollider>();

        if (try_bc)
        {
            bc = try_bc;
            bc.bracelet.tactors.SpatialEnable();
            bc.bracelet.tactors.SpatialVolume(0);
            Signal sig = new Sine(175) * new Sine(fan.bladeSpeed) + new Noise() * 0.1;
            bc.bracelet.tactors.SpatialVibrate(sig);
        }
    }
Пример #30
0
        public void ToTaylorExpansion_2()
        {
            var sine = new Sine {
                Aparam = 2, Bparam = 0
            };

            var expansion = sine.ToTaylorExpansion(5).ToList();

            expansion.Should().HaveCount(4);
            expansion.Select(s => s.PolynomialDegree).Should().ContainInOrder(1, 3, 5, 0);
            expansion.Select(s => s.LittleODegree).Should().ContainInOrder(0, 0, 0, 5);
            expansion.Select(s => s.Coefficient).Should().ContainInOrder(2.0, -8.0 / 6, 32.0 / 120, 1.0);
        }
Пример #31
0
 void OnCollisionEnter(Collision col)
 {
     if (col.gameObject.layer == 14 && (UnityEngine.Time.time - lastHitTime) > audioCoolDownTime)
     {
         audioSource.PlayRandom(hitSounds);
         lastHitTime = UnityEngine.Time.time;
         if (bracelet)
         {
             Signal sig = new Sine(175) * new ExponentialDecay();
             bracelet.tactors.VibrateAll(sig);
         }
     }
 }
Пример #32
0
 // Use this for initialization
 void Start()
 {
     Camera.main.audio.PlayOneShot(makecube, .3f);
     lastScale = Vector3.zero;
     sine = GetComponent<Sine>();
     sine.gain = 1f;
     emitter = GetComponent<AudioSource>();
     tremPhase = Random.Range(0f,1f);
     targetVolume = 0f;
 }