Skip to content

Instantly share code, notes, and snippets.

@AlonAm
Created February 8, 2016 09:06
Show Gist options
  • Save AlonAm/db30a44ac997b4b04299 to your computer and use it in GitHub Desktop.
Save AlonAm/db30a44ac997b4b04299 to your computer and use it in GitHub Desktop.
Simple Signal Generator
class SignalGenerator
{
long startTime = Stopwatch.GetTimestamp();
long ticksPerSecond = Stopwatch.Frequency;
float amplitude = 1f;
float frequency = 1f;
float phase = 1f;
float offset = 0f;
public float GetValue()
{
float time = (float)(Stopwatch.GetTimestamp() - startTime) / ticksPerSecond'
return GetValue(time);
}
public float GetValue(float time)
{
var t = frequency * time + phase;
var value = (float)Math.Sin(2f * Math.PI * t);
return amplitude * value + offset;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment