2 using System.Collections.Generic;
3 using System.Globalization;
6 using Microsoft.Xna.Framework;
21 private float frequency;
26 " Pulse: periodically sends out a signal of 1." +
27 " Sawtooth: sends out a periodic wave that increases linearly from 0 to 1." +
28 " Sine: sends out a sine wave oscillating between -1 and 1." +
29 " Square: sends out a signal that alternates between 0 and 1." +
30 " Triangle: sends out a wave that alternates between increasing linearly from -1 to 1 and decreasing from 1 to -1.",
31 alwaysUseInstanceValues:
true)]
41 get {
return frequency; }
46 frequency = MathHelper.Clamp(value, 0.0f, 240.0f);
61 if (frequency <= 0.0f)
return;
64 float pulseInterval = 1.0f / frequency;
65 while (phase >= pulseInterval)
68 phase -= pulseInterval;
72 phase = (phase + deltaTime * frequency) % 1.0f;
73 item.
SendSignal(phase.ToString(CultureInfo.InvariantCulture),
"signal_out");
76 phase = (phase + deltaTime * frequency) % 1.0f;
80 phase = (phase + deltaTime * frequency) % 1.0f;
81 item.
SendSignal(Math.Sin(phase * MathHelper.TwoPi).ToString(CultureInfo.InvariantCulture),
"signal_out");
84 phase = (phase + deltaTime * frequency) % 1.0f;
85 float output = 4.0f * MathF.Abs(MathUtils.PositiveModulo(phase - 0.25f, 1.0f) - 0.5f) - 1.0f;
86 item.
SendSignal(output.ToString(CultureInfo.InvariantCulture),
"signal_out");
93 switch (connection.
Name)
98 if (
float.TryParse(signal.
value, NumberStyles.Float, CultureInfo.InvariantCulture, out newFrequency))
104 case "set_outputtype":
107 if (Enum.TryParse(signal.
value, out newOutputType))
void SendSignal(string signal, string connectionName)
The base class for components holding the different functionalities of the item
OscillatorComponent(Item item, ContentXElement element)
override void ReceiveSignal(Signal signal, Connection connection)
override void Update(float deltaTime, Camera cam)