private short senseResistor; // in mOhms #endregion Fields #region Constructors public Booster( bool ledToVcc, Cpu.Pin pinEnable, Cpu.Pin pinEnableLED, Cpu.AnalogChannel pinSense, Cpu.Pin pinOverloadLED, short senseResistor, int currentThreshould, Cpu.Pin pinGenerator, uint[] idleTimings ) { portEnable = new OutputPort(pinEnable, false); portEnableLED = new OutputPort(pinEnableLED, ledToVcc); this.ledToVcc = ledToVcc; portOverloadLED = new OutputPort(pinOverloadLED, ledToVcc); portSense = new AnalogInput(pinSense); portSense.Scale = 3300; this.senseResistor = senseResistor; this.currentThreshould = currentThreshould; new Timer(TimerCurrent_Tick, null, 0, checkOverloadPeriod); portGenerator = new SignalGenerator((Cpu.Pin)pinGenerator, false, MaxTimingsCount); this.idleTimings = idleTimings; //new Thread(GeneratorWork) { Priority = ThreadPriority.AboveNormal }.Start(); new Timer(TimerGenerator, null, 0, 2); }
private bool PreInit(object sender, EventArgs e) { BlinkingLed = new SignalGenerator(EMX.Pin.IO17, false, 2); Blink(100); OneWireBus = new OneWire(new OutputPort(EMX.Pin.IO26, false)); return true; }
public void ImpulseSignalGeneratorWithFrequencyZeroTest() { // Arrange var impulseSignalOffset = 3; var impulseSignalAmplitude = 1; var impulseSignalFrequency = 0; var impulseSignalLength = 5; // Act var impulseSignalGenerator = SignalGenerator.Impulse(impulseSignalOffset, impulseSignalFrequency, impulseSignalAmplitude, impulseSignalLength); // Assert Assert.IsNotNull(impulseSignalGenerator); CollectionAssert.AllItemsAreNotNull(impulseSignalGenerator); Assert.That(impulseSignalGenerator.Length, Is.EqualTo(impulseSignalLength)); Assert.That(impulseSignalGenerator[impulseSignalOffset], Is.EqualTo(impulseSignalAmplitude)); }
// Clean DriverOut private void Cleanup() { if (driverOut != null) { driverOut.Stop(); } if (wg != null) { wg = null; } if (driverOut != null) { driverOut.Dispose(); } }
public void SineSignalGeneratorTest() { // Arrange var sampleRate = 44100; var frequency = 1000; var amplitude = 1; var phase = 0; var length = 5; // Act var sineSignalGenerator = SignalGenerator.Sine(sampleRate, frequency, phase, amplitude, length); // Assert Assert.IsNotNull(sineSignalGenerator); CollectionAssert.AllItemsAreNotNull(sineSignalGenerator); Assert.That(sineSignalGenerator.Length, Is.EqualTo(length)); }
public void FourierRadix2MatchesNaiveOnRealSine(FourierOptions options) { var dft = new DiscreteFourierTransform(); var samples = SignalGenerator.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16); VerifyMatchesNaiveComplex( samples, 12, s => dft.NaiveForward(s, options), s => dft.Radix2Forward(s, options)); VerifyMatchesNaiveComplex( samples, 12, s => dft.NaiveInverse(s, options), s => dft.Radix2Inverse(s, options)); }
public void FourierRadix2MatchesNaiveOnRandom([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options) { var dft = new DiscreteFourierTransform(); var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, 0x80); VerifyMatchesNaiveComplex( samples, 1e-12, s => dft.NaiveForward(s, options), s => dft.Radix2Forward(s, options)); VerifyMatchesNaiveComplex( samples, 1e-12, s => dft.NaiveInverse(s, options), s => dft.Radix2Inverse(s, options)); }
public MainWindow() { frqLog = Math.Log10(fMax / fMin); // Init Audio driverOut = new WaveOut(); driverOut.DesiredLatency = 100; wave = new ADSRSignalGenerator(); osc1 = new SignalGenerator(); osc2 = new SignalGenerator(); osc3 = new SignalGenerator(); driverOut.Init(wave); envEnabled = false; // Init UI InitializeComponent(); }
public void FourierBluesteinMatchesNaiveOnRealSineNonPowerOfTwo(FourierOptions options) { var dft = new DiscreteFourierTransform(); var samples = SignalGenerator.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 14); VerifyMatchesNaiveComplex( samples, 12, s => dft.NaiveForward(s, options), s => dft.BluesteinForward(s, options)); VerifyMatchesNaiveComplex( samples, 12, s => dft.NaiveInverse(s, options), s => dft.BluesteinInverse(s, options)); }
public void FourierBluesteinMatchesNaiveOnRandomPowerOfTwo(FourierOptions options) { var dft = new DiscreteFourierTransform(); var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x80); VerifyMatchesNaiveComplex( samples, 10, s => dft.NaiveForward(s, options), s => dft.BluesteinForward(s, options)); VerifyMatchesNaiveComplex( samples, 10, s => dft.NaiveInverse(s, options), s => dft.BluesteinInverse(s, options)); }
private void btnReproducirSeñal_Click(object sender, RoutedEventArgs e) { var sampleRate = 44100; var channelCount = 1; var seconds = 10; signalGenerator = new SignalGenerator(sampleRate, channelCount); signalGenerator.Type = SignalGeneratorType.Sin; signalGenerator.Frequency = 750; signalGenerator.Gain = 0.5; var offsetProvider = new OffsetSampleProvider(signalGenerator); offsetProvider.TakeSamples = sampleRate * seconds * channelCount; output = new WaveOutEvent(); output.Init(signalGenerator); output.Play(); }
private void btn_lasos_Click(object sender, RoutedEventArgs e) { var sampleRate = 44100; var channelCount = 1; float seconds = 0.3f; signalGenerator = new SignalGenerator(sampleRate, channelCount); signalGenerator.Type = SignalGeneratorType.Sin; signalGenerator.Frequency = 1864; signalGenerator.Gain = 0.5; var offsetProvider = new OffsetSampleProvider(signalGenerator); offsetProvider.TakeSamples = (int)(sampleRate * seconds * channelCount); output = new WaveOutEvent(); output.Init(offsetProvider); output.Play(); }
private void ReproducirNota(int frecuencia) { var sampleRate = 44100; var channelCount = 1; var seconds = 1; signalGenerator = new SignalGenerator(sampleRate, channelCount); signalGenerator.Type = SignalGeneratorType.Sin; signalGenerator.Frequency = frecuencia; var offsetProvider = new OffsetSampleProvider(signalGenerator); offsetProvider.TakeSamples = sampleRate * seconds * channelCount; output = new WaveOutEvent(); output.Init(offsetProvider); output.Play(); }
public void FourierRadix2MatchesNaiveOnRandom(FourierOptions options) { var dft = new DiscreteFourierTransform(); var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x80); VerifyMatchesNaiveComplex( samples, 1e-12, s => dft.NaiveForward(s, options), s => dft.Radix2Forward(s, options)); VerifyMatchesNaiveComplex( samples, 1e-12, s => dft.NaiveInverse(s, options), s => dft.Radix2Inverse(s, options)); }
public void FourierDefaultTransformSatisfiesParsevalsTheorem([Values(0x1000, 0x7FF)] int count) { var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, count); var timeSpaceEnergy = (from s in samples select s.MagnitudeSquared()).Mean(); var work = new Complex[samples.Length]; samples.CopyTo(work, 0); // Default -> Symmetric Scaling Transform.FourierForward(work); var frequencySpaceEnergy = (from s in work select s.MagnitudeSquared()).Mean(); Assert.AreEqual(timeSpaceEnergy, frequencySpaceEnergy, 1e-12); }
public void NaiveMatchesDft([Values(HartleyOptions.Default, HartleyOptions.AsymmetricScaling, HartleyOptions.NoScaling)] HartleyOptions hartleyOptions, [Values(FourierOptions.Default, FourierOptions.AsymmetricScaling, FourierOptions.NoScaling)] FourierOptions fourierOptions) { var dht = new DiscreteHartleyTransform(); var samples = SignalGenerator.Random(x => x, _uniform, 0x80); VerifyMatchesDft( samples, 1e-5, false, s => Transform.FourierForward(s, fourierOptions), s => dht.NaiveForward(s, hartleyOptions)); VerifyMatchesDft( samples, 1e-5, true, s => Transform.FourierInverse(s, fourierOptions), s => dht.NaiveInverse(s, hartleyOptions)); }
public SignalGeneratorViewModel() { //SIGNAL GENERATOR TEST signalGenerator = new SignalGenerator(); //Leave default for now but add option to change... maybe globally? signalGenerator.Frequency = Frequency; signalGenerator.Gain = Amplitude; signalGenerator.Type = SignalGeneratorType.Sin; //Wave player - TODO: move to mixer module or something waveOut = new WaveOut(); waveOut.Init(signalGenerator); StartStopWaveCommand = new RelayCommand(StartPauseWave); //Start values Frequency = 440; Amplitude = 2f; }
/// <summary> /// Plays sine wave sound with specified frequency and duration /// </summary> /// <param name="frequency">Sine wave frequency</param> /// <param name="duration">Sound play duration</param> public static void PlaySine(float frequency, float duration) { SignalGenerator generator = new SignalGenerator(44800, 2) { Frequency = frequency, Gain = 0.05, Type = SignalGeneratorType.Sin }; var samples = generator.Take(TimeSpan.FromSeconds(duration)); using (var wo = new WaveOutEvent()) { wo.Init(samples); wo.Play(); while (wo.PlaybackState == PlaybackState.Playing) { System.Threading.Thread.Sleep(10); } } }
public void PlayPianoMusic(SignalGenerator generator, int num, bool state) { using (var wo = new WaveOutEvent()) { wo.Init(generator); wo.Play(); while (wo.PlaybackState == PlaybackState.Playing) { //Thread.Sleep(100); if (PButton1_State == false) { wo.Stop(); break; } } wo.Stop(); } }
public void NaiveMatchesDft(HartleyOptions hartleyOptions, FourierOptions fourierOptions) { var dht = new DiscreteHartleyTransform(); var samples = SignalGenerator.Random(x => x, GetUniform(1), 0x80); VerifyMatchesDft( samples, 1e-5, false, s => Transform.FourierForward(s, fourierOptions), s => dht.NaiveForward(s, hartleyOptions)); VerifyMatchesDft( samples, 1e-5, true, s => Transform.FourierInverse(s, fourierOptions), s => dht.NaiveInverse(s, hartleyOptions)); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Spline_interpolation">Spline interpolation</seealso> public void Run() { // 1. Generate 10 samples of the function x*x-2*x on interval [0, 10] Console.WriteLine(@"1. Generate 10 samples of the function x*x-2*x on interval [0, 10]"); double[] points; var values = SignalGenerator.EquidistantInterval(TargetFunction, 0, 10, 10, out points); Console.WriteLine(); // 2. Create akima spline interpolation var method = new AkimaSplineInterpolation(points, values); Console.WriteLine(@"2. Create akima spline interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", ((IInterpolation)method).SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", ((IInterpolation)method).SupportsDifferentiation); Console.WriteLine(); // 5. Differentiate at point 5.2 Console.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2)); Console.WriteLine(); // 6. Integrate at point 5.2 Console.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2)); Console.WriteLine(); // 7. Interpolate ten random points and compare to function results Console.WriteLine(@"7. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 10] var point = rng.NextDouble() * 10; Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }
public void HartleyDefaultNaiveSatisfiesParsevalsTheorem(int count) { var samples = SignalGenerator.Random(x => x, _uniform, count); var timeSpaceEnergy = (from s in samples select s * s).Mean(); var work = new double[samples.Length]; samples.CopyTo(work, 0); // Default -> Symmetric Scaling var dht = new DiscreteHartleyTransform(); work = dht.NaiveForward(work, HartleyOptions.Default); var frequencySpaceEnergy = (from s in work select s * s).Mean(); Assert.AreEqual(timeSpaceEnergy, frequencySpaceEnergy, 1e-12); }
public Track(string[][] progression, string[] rhythm, double duration, double octiveMultiplier) { this.progression = progression; this.rhythm = rhythm; this.duration = duration; foreach (string note in frequencies.Keys) { SignalGenerator gen = new SignalGenerator() { Gain = note != "REST" ? 0.025 : 0.0, Frequency = frequencies[note] * octiveMultiplier, Type = SignalGeneratorType.Sin }; WaveOutEvent wo = new WaveOutEvent(); wo.Init(gen); wouts[note] = wo; } }
public void FourierDefaultTransformIsReversible() { var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x7FFF); var work = new Complex[samples.Length]; samples.CopyTo(work, 0); Transform.FourierForward(work); Assert.IsFalse(work.ListAlmostEqual(samples, 6)); Transform.FourierInverse(work); AssertHelpers.ListAlmostEqual(samples, work, 10); Transform.FourierInverse(work, FourierOptions.Default); Assert.IsFalse(work.ListAlmostEqual(samples, 6)); Transform.FourierForward(work, FourierOptions.Default); AssertHelpers.ListAlmostEqual(samples, work, 10); }
private static WaveStream CreatePcmTestStream() { var outFormat = new WaveFormat(8000, 16, 1); const int durationInSeconds = 5; var sg = new SignalGenerator(outFormat.SampleRate, outFormat.Channels) { Frequency = 1000, Gain = 0.25, Type = SignalGeneratorType.Sin }; var sp = sg.ToWaveProvider16(); byte[] data = new byte[outFormat.AverageBytesPerSecond * durationInSeconds]; var bytesRead = sp.Read(data, 0, data.Length); Assert.AreEqual(bytesRead, data.Length); return(new RawSourceWaveStream(new MemoryStream(data), outFormat)); }
private void testoutput_Click(object sender, EventArgs e) { var sine5Seconds = new SignalGenerator() { Gain = 0.2, Frequency = 500 }.Take(TimeSpan.FromSeconds(5)); using (var wo = new WaveOutEvent()) { Console.WriteLine("Play sound"); wo.DeviceNumber = 0; wo.Init(sine5Seconds); wo.Play(); while (wo.PlaybackState == PlaybackState.Playing) { Thread.Sleep(500); } } }
public void Play() { var sine20Seconds = new SignalGenerator() { Gain = 1, Frequency = 17500, Type = SignalGeneratorType.Sin }.Take(TimeSpan.FromSeconds(2)); using (var wo = new WaveOutEvent()) { wo.Init(sine20Seconds); wo.Play(); while (wo.PlaybackState == PlaybackState.Playing) { Thread.Sleep(500); } } }
public GeneratorPanel() { // Const Log10FmaxFMin = Math.Log10(FMax / FMin); // Panel Init InitializeComponent(); this.Disposed += new EventHandler(GeneratorPanel_Disposed); // Init Audio driverOut = new WaveOut(); driverOut.DesiredLatency = 100; //driverOut = new AsioOut(0); wg = new SignalGenerator(); // Par Default Frq 1200Hz cmbFrq.SelectedIndex = 0; cmbPrecisionFrq.SelectedIndex = 2; tbFrq.Value = 12; // 1200Hz tbToFrq(); // Par Default Frq End 2000Hz cmbFrqEnd.SelectedIndex = 0; cmbPrecisionFrqEnd.SelectedIndex = 2; tbFrqEnd.Value = tbFrqEnd.Maximum; tbToFrqEnd(); // comboBox Type cmbType.DataSource = Enum.GetValues(typeof(SignalGeneratorType)); cmbType.SelectedIndex = 0; // Par Default Gain -20dB tbGain.Value = -20; tbToGain(); // Par Default SweepSeconds tbSweepLength.Value = 10; tbToSweepLength(); // Init Driver Audio driverOut.Init(wg); StartStopEnabled(); }
public SimpleOscillationDemoCommand() { wasapiOut = new WasapiOut(); signalGenerator = new SignalGenerator(sampleRate, channels); signalGenerator.Frequency = frequency; signalGenerator.Gain = gain; wasapiOut.Init(signalGenerator); CommandRespiratory cr = new CommandRespiratory(); cr.AddCommand("play", typeof(PlayCommand), (string[] param) => new PlayCommand(wasapiOut)); cr.AddCommand("stop", typeof(StopCommand), (string[] param) => new StopCommand(wasapiOut)); cr.AddCommand("setvolume", typeof(SetVolumeCommand), (string[] param) => new SetVolumeCommand(param, signalGenerator)); cr.AddCommand("setfreq", typeof(SetFrequencyCommand), (string[] param) => new SetFrequencyCommand(param, signalGenerator)); cd = new CommandDirector(cr); cd.Title = "Simple Oscillation"; }
public void start(int freq) { var signalGenerator = new SignalGenerator() { Gain = 0.2, Frequency = freq, Type = SignalGeneratorType.Sin }; using (var wo = new WaveOutEvent()) { wo.Init(signalGenerator); wo.Play(); while (wo.PlaybackState == PlaybackState.Playing) { System.Threading.Thread.Sleep(500); } } }
/// <summary> /// Verify if is reversible complex. /// </summary> /// <param name="count">Samples count.</param> /// <param name="maximumError">Maximum error value.</param> /// <param name="forward">Forward delegate.</param> /// <param name="inverse">Inverse delegate.</param> private void VerifyIsReversibleComplex( int count, double maximumError, Func <Complex[], Complex[]> forward, Func <Complex[], Complex[]> inverse) { var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, count); var work = new Complex[samples.Length]; samples.CopyTo(work, 0); work = forward(work); Assert.IsFalse(work.AlmostEqualListWithError(samples, maximumError)); work = inverse(work); AssertHelpers.AlmostEqualList(samples, work, maximumError); }
/// <summary> /// Verify if is reversible real. /// </summary> /// <param name="count">Samples count.</param> /// <param name="maximumError">Maximum error value.</param> /// <param name="forward">Forward delegate.</param> /// <param name="inverse">Inverse delegate.</param> private void VerifyIsReversibleReal( int count, double maximumError, Func <double[], double[]> forward, Func <double[], double[]> inverse) { var samples = SignalGenerator.Random(x => x, GetUniform(1), count); var work = new double[samples.Length]; samples.CopyTo(work, 0); work = forward(work); Assert.IsFalse(work.AlmostEqualListWithError(samples, maximumError)); work = inverse(work); AssertHelpers.AlmostEqualList(samples, work, maximumError); }