static void Test_PartialProvider_DoS() { var format = new WaveFormat { bytesPerSample = 2, //1, // performing same as 16 sampleRate = 44100, //22050, channels = 1 }; using (var engine = new WaveEngine(format, bufferLengthMs: 60)) { var partialProvider = new PartialProvider(); engine.SetSampleProvider(partialProvider); // Init engine.Play(); int i = 0; while (engine.IsPlaying()) { double freqHz = 440.0 + (i++) * 10; partialProvider.AddPartial(freqHz, 100, 60000, 0.05f, -2f); partialProvider.FlushPartials(); Thread.Sleep(50); } Debug.WriteLine("Ending. Provider status: {0}", (object)partialProvider.FormatStatus()); } }
public static void PlayBuffer(byte[] fullDataBuffer, WaveFormat format) { #if DEBUG Debug.WriteLine("PlayBuffer of {0}:\n{1}", format, format.FormatBuffer(fullDataBuffer)); #endif var provider = new BufferSampleProvider(fullDataBuffer); // wrap the buffer for engine using (var engine = new WaveEngine(format)) { engine.SetSampleProvider(provider); engine.Play(waitForEnd: true); //engine.Play(); //Thread.Sleep(5000); } }
static void Test_SineWaveProvider() { using (var engine = new WaveEngine()) { var sampleProvider = new SineWaveProvider() { Gain = 0.5, Frequency = 440.0, DurationsMs = 5000, }; engine.SetSampleProvider(sampleProvider); #if true engine.Play(waitForEnd: true); #else engine.Play(); Thread.Sleep(2000); #endif } }
static void Test_PartialProvider() { var format = new WaveFormat { bytesPerSample = 2, sampleRate = 44100, channels = 1 }; using (var engine = new WaveEngine(format, bufferLengthMs: 60)) { var partialProvider = new PartialProvider(); engine.SetSampleProvider(partialProvider); // Initialize called partialProvider.AddFrequency(440.0 * 2, 2000, 0.5f); //partialProvider.AddPartial(440.0 * 2, 100, 2000, 0.5f, -2f); partialProvider.FlushPartials(); engine.Play(); Thread.Sleep(3000); Debug.WriteLine("Ending. Provider status: {0}", (object)partialProvider.FormatStatus()); } }
static void Test_PartialProvider_Piano() { var format = new WaveFormat { bytesPerSample = 2, sampleRate = 44100, //sampleRate = 22050, channels = 1, }; string harmonicity = "Barlow"; Rational[] subgroup = Rational.ParseRationals("2.3.5.11"); Partial[] partials = MakePartials(harmonicity, subgroup, 15); Debug.WriteLine("Subgroup {0}", Rational.FormatRationals(subgroup)); foreach (Partial p in partials) { Debug.WriteLine("Partial {0} harm: {1}", p.rational, p.harmonicity); } using (var engine = new WaveEngine(format, bufferLengthMs: 30, restartOnFailure: true)) { var partialProvider = new PartialProvider(); engine.SetSampleProvider(partialProvider); engine.Play(); Console.WriteLine("1-9 to play note\nEsc to exit"); while (true) { bool playing = true; while (true) { playing = engine.IsPlaying(); if (!playing) { break; } if (Console.KeyAvailable) { break; } Thread.Sleep(1); // sleep here } if (!playing) { break; } var k = Console.ReadKey(true); if (k.Key == ConsoleKey.Escape) { break; // engine stopped on dispose } else if (ConsoleKey.D1 <= k.Key && k.Key <= ConsoleKey.D9) { int n = (int)k.Key - (int)ConsoleKey.D1 + 1; // 1..9 var r = new Rational(1 + n, 2); // 2/2, 3/2, 4/2, 5/2,.. if (k.Modifiers.HasFlag(ConsoleModifiers.Shift)) { r *= 4; } if (k.Modifiers.HasFlag(ConsoleModifiers.Control)) { r /= 4; } //AddNote(partialProvider, r); AddNote(partialProvider, r.ToCents(), partials); } } Debug.WriteLine("Ending. Provider status: {0}", (object)partialProvider.FormatStatus()); } }