示例#1
0
 public void TestOutInCallbacks()
 {
     m_messageText = new StringBuilder();
     m_count       = 0;
     m_outval      = -1;
     using (var cs = new Csound6NetRealtime())
     {
         cs.OutputChannelCallback += TestOutputCallback;
         cs.InputChannelCallback  += TestInputCallback;
         var result = cs.Compile(new string[] { "csdFiles\\SimpleRuntime.csd" });
         Assert.AreEqual(CsoundStatus.Success, result);
         if (result == CsoundStatus.Success)
         {
             while (!cs.PerformKsmps())
             {
                 ;
             }
         }
         cs.Cleanup();
     }
 }
示例#2
0
   /**
    * Example 4 - Using Csound's Performance Thread
    * Example 4.1 - Using Csound in a C# async/await Task for threaded execution
    * 
    * In this example, we use a CsoundPerformanceThread to run Csound in 
    * a native thread.  Using a native thread is important to get the best
    * runtime performance for the audio engine.
    * CsoundPerformanceThread has some convenient methods for handling events,
    * but does not have features for doing regular processing at block boundaries.
    * In general, use CsoundPerformanceThread when the only kinds of communication you
    * are doing with Csound are through events, and not using channels.
    * 
    * Since VS2012, C# programmers have become comfortable with the async/await Task-based
    * paradigm for running background processes.
    * Example 4.1 shows an alternative to running csound in a separate thread (really Task)
    * to achieve the same result as example 4.
    * This approach is very useful in a GUI where a cancel event and a progress dialog
    * would be desireable.
    * This example bypasses these features; later examples will use them.
    */

        public void Example4()
        {
            using (var c = new Csound6NetRealtime())
            {
                c.SetOutputDac(0);      // Set realtime output for Csound
                c.CompileOrc(orc);      // Compile Orchestra from String
                c.ReadScore("i1 0 1");  // Read in Score from String

                c.Start();              // When compiling from strings, this call needed before performing

                // Create a new CsoundPerformanceThread, passing in the Csound object
                var t = new Csound6PerformanceThread(c);
                t.Play();   // starts the thread, which is now running separately from the main thread. This 
                // call is asynchronous and will immediately return back here to continue code
                // execution.
                t.Join();   // Join will wait for the other thread to complete. If we did not call Join(),
                // after t.Play() returns we would immediate move to the next line, c.Stop(). 
                // That would stop Csound without really giving it time to run. 
                c.Stop();   // stops Csound
                c.Cleanup();// clean up Csound; this is useful if you're going to reuse a Csound instance
            }
        }
示例#3
0
        /**
         * Example 4 - Using Csound's Performance Thread
         * Example 4.1 - Using Csound in a C# async/await Task for threaded execution
         *
         * In this example, we use a CsoundPerformanceThread to run Csound in
         * a native thread.  Using a native thread is important to get the best
         * runtime performance for the audio engine.
         * CsoundPerformanceThread has some convenient methods for handling events,
         * but does not have features for doing regular processing at block boundaries.
         * In general, use CsoundPerformanceThread when the only kinds of communication you
         * are doing with Csound are through events, and not using channels.
         *
         * Since VS2012, C# programmers have become comfortable with the async/await Task-based
         * paradigm for running background processes.
         * Example 4.1 shows an alternative to running csound in a separate thread (really Task)
         * to achieve the same result as example 4.
         * This approach is very useful in a GUI where a cancel event and a progress dialog
         * would be desireable.
         * This example bypasses these features; later examples will use them.
         */

        public void Example4()
        {
            using (var c = new Csound6NetRealtime())
            {
                c.SetOutputDac(0);      // Set realtime output for Csound
                c.CompileOrc(orc);      // Compile Orchestra from String
                c.ReadScore("i1 0 1");  // Read in Score from String

                c.Start();              // When compiling from strings, this call needed before performing

                // Create a new CsoundPerformanceThread, passing in the Csound object
                var t = new Csound6PerformanceThread(c);
                t.Play();   // starts the thread, which is now running separately from the main thread. This
                // call is asynchronous and will immediately return back here to continue code
                // execution.
                t.Join();   // Join will wait for the other thread to complete. If we did not call Join(),
                // after t.Play() returns we would immediate move to the next line, c.Stop().
                // That would stop Csound without really giving it time to run.
                c.Stop();    // stops Csound
                c.Cleanup(); // clean up Csound; this is useful if you're going to reuse a Csound instance
            }
        }
示例#4
0
 public void TestPerfTimeChannels()
 {
     m_messageText = new StringBuilder();
     m_count       = 0;
     m_outval      = -1;
     using (var cs = new Csound6NetRealtime())
     {
         var result = cs.Compile(new string[] { "csdFiles\\SimpleRuntime.csd" });
         Assert.AreEqual(CsoundStatus.Success, result);
         if (result == CsoundStatus.Success)
         {
             var bus = cs.GetSoftwareBus();
             while (!cs.PerformKsmps())
             {
                 double[] samps   = bus["achan1"] as double[];
                 double[] sampInv = new double[samps.Length];
                 if (cs.ScoreTime <= 0.1)
                 {
                     foreach (double samp in samps)
                     {
                         Assert.IsTrue(samp == 0.0);
                     }
                     bool hasPvs = bus.HasChannel("0");
                     if (hasPvs)
                     {
                         object o = bus["0"];
                     }
                 }
                 else if (cs.ScoreTime == 0.2)
                 {
                     double prev = -1.0;
                     for (int i = 0; i < 26; i++)
                     {
                         Assert.IsTrue(samps[i] > prev);
                         prev = samps[i];
                     }
                     for (int i = 26; i < 75; i++)
                     {
                         Assert.IsTrue(prev > samps[i]);
                         prev = samps[i];
                     }
                     for (int i = 0; i < sampInv.Length; i++)
                     {
                         sampInv[i] = -samps[i];
                     }
                     bus["achan2"] = sampInv;
                 }
                 else if (cs.ScoreTime == 0.3)
                 {
                     double[] samp2 = bus["achan2"] as double[];
                     double[] samp3 = bus["achan3"] as double[]; //instrument will have put samp2 into achan3 during 0.2 second; now available in 0.3 sec
                     for (int i = 0; i < samp3.Length; i++)
                     {
                         Assert.AreEqual(samp2[i], samp3[i]);
                     }
                 }
             }
         }
         cs.Cleanup();
     }
 }