public double FrequencyAt(double t, RunningOptions options) { double f1 = Frequency1.ToHertz(options), f2 = IsSweep ? Frequency2.ToHertz(options) : f1; double duration = double.IsNaN(Duration) ? options.defaultDuration.TotalSeconds : Duration; var f = f1 + (f2 - f2) * t / duration; if (options.frequencyModulation) { f += options.fmAmplitudeHz * triangleWave(2.0 * Math.PI * t * options.fmFrequency); } return(f); }
public IEnumerable <Command> Commands(RunningOptions options) { double duration = double.IsNaN(Duration) ? options.defaultDuration.TotalSeconds : Duration; TimeSpan remaining = TimeSpan.FromSeconds(duration); Waveform w = Waveform1; if (w == Waveform.Default) { w = options.defaultWaveform; } yield return(new Command(new SetWaveform(w), double.NaN, w, double.NaN, remaining)); if (IsSweep || options.isModulated) { double f1 = Frequency1.ToHertz(options), f2 = IsSweep ? Frequency2.ToHertz(options) : f1; double numberOfSteps = duration / stepDuration.TotalSeconds; for (int i = 0; i < numberOfSteps; ++i) { double f = FrequencyAt(i * stepDuration.TotalSeconds, options); double a = AmplitudeAt(i * stepDuration.TotalSeconds, options); if (options.amplitideModulation) { yield return(new Command(new SetAmplitude(a), f, w, a, remaining)); } yield return(new Command(new SetFrequency(f, stepDuration), f, w, a, remaining -= stepDuration)); } } else { double f = Frequency1.ToHertz(options); double a = AmplitudeAt(0, options); yield return(new Command(new SetFrequency(f, TimeSpan.FromSeconds(1)), f, w, a, TimeSpan.FromSeconds(duration))); for (double t = duration - 1; t > 0; t -= 1) { yield return(new Command(new Noop(TimeSpan.FromSeconds(1)), f, w, a, TimeSpan.FromSeconds(t))); } } }