//Set up the instance of Pure-data void Awake() { if (_instance == null) { _instance = this; DontDestroyOnLoad(gameObject); PD = new Pd(numberOfInputChannel, numberOfOutputChannel, AudioSettings.outputSampleRate); //Uses this to get prints of Pure Data PD.Messaging.Print += delegate(object sender, PrintEventArgs e) { Debug.Log(e.Symbol.Value); }; manager = PD.LoadPatch(APIPath("pdManager.pd")); if (MixerChannel == null) { Debug.LogWarning("Not found mixer channel..."); } createPdMixer(); if (pdDsp) { PD.Start(); } } else if (!Instance.Equals((object)this)) { Destroy(gameObject); } }
public virtual void AudioOnTest() { int blocksize = _pd.BlockSize; int ticks = 2; float[] inBuffer = new float[ticks * _inputs * blocksize]; for (int i = 0; i < inBuffer.Length; i++) { inBuffer [i] = i; } _pd.Start(); float[] outBuffer = new float[ticks * _outputs * blocksize]; _pd.Process(ticks, inBuffer, outBuffer); for (int i = 0; i < outBuffer.Length / 3; i++) { Assert.AreEqual(2 * i, outBuffer [3 * i], 0.0001); Assert.AreEqual(-6 * i, outBuffer [3 * i + 1], 0.0001); Assert.AreEqual(Math.Cos(2 * Math.PI * 440 / 44100 * i), outBuffer [3 * i + 2], 0.0001); } }
/// <summary> /// Sets up communication with libPd. /// </summary> void SetUpPd() { // Init new Pd instance _pd = new Pd(0, 2, SampleRate); // Open Pd patch _patch = _pd.LoadPatch("../../../pd/test.pd"); // Subscribe to receiver _pd.Messaging.Float += Pd_Float; _pd.Messaging.Bind(CursorReceiver); // Start audio _pd.Start(); }
/// <summary> /// Function to change state of process audio. /// </summary> /// <param name="state">True to put available audio, false to disable audio. Default is true.</param> public void Compute(bool state = true) { if (state) { PD.Start(); pdDsp = true; } else { PD.Stop(); pdDsp = false; } }
public virtual void FloatFormattingTest() { using (Patch patch = _pd.LoadPatch(@"../../test_float.pd")) { int blocksize = _pd.BlockSize; int ticks = 2; float[] inBuffer = new float[ticks * _inputs * blocksize]; for (int i = 0; i < inBuffer.Length; i++) { inBuffer [i] = i; } _pd.Start(); float[] outBuffer = new float[ticks * _outputs * blocksize]; _pd.Process(ticks, inBuffer, outBuffer); for (int i = 0; i < outBuffer.Length / 3; i++) { Assert.AreEqual(i, outBuffer [3 * i], 0.0001); Assert.AreEqual(i + 0.5, outBuffer [3 * i + 1], 0.0001); Assert.AreEqual(0, outBuffer [3 * i + 2], 0.0001); } } }
public void Init() { _pd = new Pd(_inputs, _outputs, _sampleRate); _patch = _pd.LoadPatch(@"../../test_csharp.pd"); _pd.Start(); }
public virtual void StartTest() { _pd.Start(); Assert.IsTrue(_pd.IsComputing); }