Ejemplo n.º 1
0
        static void Test_WaveWriter()
        {
            var format = new WaveFormat {
                bytesPerSample = 2,
                sampleRate     = 44100,
                channels       = 1,
            };

            byte[] buffer = new byte[format.bytesPerSample * format.sampleRate]; // for 1 sec

            string file = "test1.wav";

            using (var w = new WaveWriter(format, file))
            {
#if false
                WaveFormat.Clear(buffer);
                w.Write(buffer);
#else
                var provider = new PartialProvider();
                provider.Initialize(format);

                //provider.AddFrequency(440.0, 1500, 0.5f); // without envelope
                provider.AddPartial(440, 100, 2000, 0.5f, -4f);
                provider.FlushPartials();

                while (!provider.IsEmpty())
                {
                    provider.Fill(buffer);
                    w.Write(buffer);
                }
#endif
            }
        }
Ejemplo n.º 2
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());
            }
        }
Ejemplo n.º 3
0
 static void AddNote(PartialProvider pp, double cents, Partial[] partials)
 {
     foreach (Partial p in partials)
     {
         double c     = cents + p.rational.ToCents();
         double hz    = Partials.CentsToHz(c);
         double level = Math.Pow(p.harmonicity, 7.0f);
         pp.AddPartial(
             hz,
             10, (int)(2000 * p.harmonicity),
             (float)(level / partials.Length),
             -4f
             );
     }
     pp.FlushPartials();
 }
Ejemplo n.º 4
0
        static void AddNote(PartialProvider pp, Rational r0)
        {
            string[] rs = new string[] { "1", "2", "3", "4", "81/16", "6" };
            float [] ls = new float [] { 1f, .04f, .8f, .08f, .8f, .1f };

            double c0 = r0.ToCents();

            for (int i = 0; i < rs.Length; ++i)
            {
                Rational r  = Rational.Parse(rs[i]);
                double   c  = c0 + r.ToCents();
                double   hz = Partials.CentsToHz(c);
                pp.AddPartial(
                    hz,
                    10, (int)(2000 * ls[i]),
                    ls[i] * .1f,
                    -4f
                    );
            }
            pp.FlushPartials();
        }
Ejemplo n.º 5
0
        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());
            }
        }