Beispiel #1
0
        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());
            }
        }
Beispiel #2
0
        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());
            }
        }