Exemplo n.º 1
0
        void OnAudioFilterRead(float[] data, int channels)
        {
            if (dataPtr == IntPtr.Zero)
            {
                dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
                dataPtr    = dataHandle.AddrOfPinnedObject();
            }

            if (PDGainManager.soundNameVoice.Count > 0 && !readerSwitch)
            {
                readerSwitch = true;
                pdPlayer.communicator.SendValue("UReaderSwitch", 1);
            }
            else if (PDGainManager.soundNameVoice.Count == 0 && readerSwitch)
            {
                readerSwitch = false;
                pdPlayer.communicator.SendValue("UReaderSwitch", 0);
            }

            if (pdPlayer.bridge.initialized)
            {
                pdPlayer.communicator.WriteArray("UMasterReceive", dataSum);
                LibPD.Process(pdPlayer.bridge.ticks, dataPtr, dataPtr);
            }
        }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Vector3 v3Velocity = rb.velocity;

        thisVelocity = v3Velocity.y;

        if (thisVelocity - lastVelocity > 0)
        {
            bounceMoment = true;
        }
        else
        {
            bounceMoment = false;
        }



        if (bounceMoment)
        {
            LibPD.SendFloat("bounce", 1);
            bounceMoment = false;
            lastVelocity = -1;
        }
        lastVelocity = thisVelocity;

        float sphereY = GameObject.Find("Sphere").transform.position.y;

        LibPD.SendFloat("pitchOffset", sphereY);
    }
Exemplo n.º 3
0
    public void floatArrayToPD(float[] arrayInput)
    {
        //LibPD.SendList ("testing", 10,1);

        float[] array = new float[1024 * 2];



        for (int i = 0; i < 1024; i++)  //i++)	{

        {
            if (i % 2 == 0)
            {
                int idx = i / 2;

                array[idx * 2] = idx;

                array[idx * 2 + 1] = (Mathf.Cos(arrayInput[idx * 20000 / 1024]));        // - Mathf.Cos(1-lastArray[idx*20000/1024]);
            }
        }

        System.Array.Copy(arrayInput, lastArray, 1024);         //arrayInput.Length);



        object[] objectArray = new object[2048];
        System.Array.Copy(array, objectArray, 2048);         //array.Length);



        //print (objectArray.Length);//array[6] + " " + array[7]);

        LibPD.SendList("params", objectArray);
    }
Exemplo n.º 4
0
    void OnCollisionEnter(Collision collision)
    {
        if (enabled)
        {
            //Debug.Log("dur: "+dur+" - amp: "+ vel+" - note: "+ (nota*2+60));
            Placa p = collision.collider.GetComponent <Placa>();
            //Debug.Log (p.note);
            if (p != null)
            {
                LibPD.SendFloat("dur" + index, dur * emisor.art * 1000);
                //LibPD.SendFloat ("envOut"+index, (dur-(dur*emisor.art)) * 1000);
                LibPD.SendFloat("vel" + index, 127 * vel * 1f);
                LibPD.SendFloat("har" + index, emisor.har);
                LibPD.SendFloat("modIn" + index, emisor.iMod);
                LibPD.SendFloat("note" + index, p.note);

                if (emisor.decay > 0)
                {
                    vel *= emisor.decay;
                    gameObject.transform.localScale = new Vector3(vel * 0.5f, vel * 0.5f, vel * 0.5f);
                }

                material.color = Color.white;
                //LibPD.SendBang ("play");
                Invoke("ResetColor", dur);
            }
        }
    }
Exemplo n.º 5
0
//	sends all the non controlled randomised parameters to the various receivers in pd
    void send_init_parameters()
    {
//		LibPD.SendFloat ("volume", 0.7f);

        for (int i = 0; i < instrument_genome.filter_gen.Length; i++)
        {
            LibPD.SendFloat(instrument_genome.filter [i], instrument_genome.filter_gen [i]);
        }

        for (int i = 0; i < instrument_genome.env_gen.Length; i++)
        {
            LibPD.SendFloat(instrument_genome.env [i], instrument_genome.env_gen [i]);
        }

        for (int i = 0; i < instrument_genome.metro_gen.Length; i++)
        {
            LibPD.SendFloat(instrument_genome.metro [i], instrument_genome.metro_gen [i]);
        }

//		check if the user is controlling the frequency of the instrument_genome
//		if (instrument_genome.metro_on == 1) {
//			LibPD.SendFloat ("metro-on", 1);
//
//		} else {
//			LibPD.SendFloat ("metro-on", 0);
//		}
    }
Exemplo n.º 6
0
 public void Process(float[] output, int ticks)
 {
     if (LibPD.Process(ticks, new float[0], output) == 0 && BufferReady != null)
     {
         BufferReady(this, new BufferReadyEventArgs(output));
     }
 }
Exemplo n.º 7
0
        public virtual void testPrint()
        {
            var msgs = new string[] {
                "print: bang\n",
                "print: 0\n",
                "print: 42\n",
                "print: symbol",
                " ",
                "don't panic",
                "\n",
            };

            var i = 0;

            LibPDPrint del = delegate(string text) {
                Assert.AreEqual(msgs [i++], text);
            };

            LibPD.Print += del;

            LibPD.SendBang("foo");
            LibPD.SendFloat("foo", 0);
            LibPD.SendFloat("foo", 42);
            LibPD.SendSymbol("foo", "don't panic");

            Assert.AreEqual(msgs.Length, i);

            LibPD.Print -= del;
        }
Exemplo n.º 8
0
        public static void closePatch()
        {
            LibPD.Release();

            while (loader.FreeLibrary(SDllHandle))
            {
            }
        }
Exemplo n.º 9
0
 public PdOperation(string filePath)
 {
     _patchHandle = LibPD.OpenPatch(filePath);
     LibPD.Bang  += LibPD_Bang;
     LibPD.Subscribe(DoneReceiver);
     LibPD.OpenAudio(0, 2, SampleRate);
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 10
0
        public static void loadPatch()
        {
            SDllHandle = LoadLibrary("libpdcsharp.dll");
            LibPD.ReInit();

            LibPD.OpenAudio(2, 3, 44100);
            SPatch = LibPD.OpenPatch(@"..\..\test_csharp.pd");
            LibPD.ComputeAudio(true);
        }
Exemplo n.º 11
0
 public void SubscribeDebug()
 {
     LibPD.Subscribe("Debug");
     LibPD.Bang    += ReceiveDebugBang;
     LibPD.Float   += ReceiveDebugFloat;
     LibPD.Symbol  += ReceiveDebugSymbol;
     LibPD.List    += ReceiveDebugList;
     LibPD.Message += ReceiveDebugMessage;
 }
Exemplo n.º 12
0
 void OnDestroy()
 {
     LibPD.Bang    -= ReceiveDebugBang;
     LibPD.Float   -= ReceiveDebugFloat;
     LibPD.Symbol  -= ReceiveDebugSymbol;
     LibPD.List    -= ReceiveDebugList;
     LibPD.Message -= ReceiveDebugMessage;
     LibPD.Unsubscribe("Debug");
 }
Exemplo n.º 13
0
 void OnTriggerEnter(Collider c)
 {
     if (c.gameObject.transform.tag == "Enemy")
     {
         LibPD.SendMessage("BoomPos", "float", (this.transform.position.x - 20) / 40);
         LibPD.SendMessage("BoomBang", "bang");
         Explode();
     }
 }
Exemplo n.º 14
0
    // Close patch and release Pd on quit
    void OnApplicationQuit()
    {
        // Unsubscribe Pd print object.
        LibPD.Print -= ReceivePrint;

        closePatch(SPatch);
        LibPD.Release();
        islibpdready = false;
    }
Exemplo n.º 15
0
 /// <summary>
 /// Let libPd compute data, while the CircularBuffer has less than _minBuffer bytes available.
 /// </summary>
 void RefillBuffer()
 {
     while (_circularBuffer.Count < _minBuffer)
     {
         // Compute audio. Take care of the array sizes for audio in and out.
         LibPD.Process(Ticks, new float[0], _buffer);
         _circularBuffer.Write(PcmFromFloat(_buffer), 0, _buffer.Length * 4);
     }
 }
Exemplo n.º 16
0
 public void Receive(string sendName, MessageReceiveCallback messageReceiver, bool asynchronous = false)
 {
     if (!sendNameMessageReceiverDict.ContainsKey(sendName))
     {
         LibPD.Subscribe(sendName);
         sendNameMessageReceiverDict[sendName] = new List <PureDataMessageReceiver>();
     }
     sendNameMessageReceiverDict[sendName].Add(new PureDataMessageReceiver(sendName, messageReceiver, asynchronous, pureData));
 }
Exemplo n.º 17
0
 void Dispose(bool isDisposing)
 {
     LibPD.Unsubscribe(DoneReceiver);
     LibPD.ComputeAudio(false);
     if (_patchHandle > 0)
     {
         LibPD.ClosePatch(_patchHandle);
     }
 }
Exemplo n.º 18
0
    // lengthDest: set the array size in the patch
    // we consider it mandatory by convention
    // we do not rely on the [arraysize] object as it is not part of Pd core
    public void LoadClip(string name, AudioClip clip, string lengthDest)
    {
        var data = new float[clip.samples * 2];

        clip.GetData(data, 0);
        // Set PD array size
        Debug.Log("Pd send float: " + LibPD.LibPD_SendFloat(pdIndex, lengthDest, data.Length));
        // Fill it with sample data
        Debug.Log("Pd write array: " + LibPD.LibPD_WriteArray(pdIndex, name, data, data.Length));
    }
Exemplo n.º 19
0
    void Start()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        Screen.orientation = ScreenOrientation.Landscape;
#endif

        // subscribing to receive
        LibPD.Subscribe("note");
        LibPD.Float += receiveFloat;
    }
 public void SubscribeDebug()
 {
     LibPD.Subscribe("Debug");
     LibPD.Subscribe("Command");
     LibPD.Bang    += ReceiveBang;
     LibPD.Float   += ReceiveFloat;
     LibPD.Symbol  += ReceiveSymbol;
     LibPD.List    += ReceiveList;
     LibPD.Message += ReceiveMessage;
 }
Exemplo n.º 21
0
        private int LoadPatch(string patchName)
        {
            string assetsPath = Application.streamingAssetsPath + "/PdAssets/";
            string path       = assetsPath + patchName;

#if UNITY_ANDROID && !UNITY_EDITOR
            path = JavaLoadPatch(path, patchName);
#endif
            return(LibPD.OpenPatch(path));
        }
Exemplo n.º 22
0
 public void SubscribeDebug()
 {
     LibPD.Subscribe("debug");
     LibPD.Subscribe("uaudiosource_fadeout");
     LibPD.Subscribe("uaudiosource_stop");
     LibPD.Bang    += ReceiveBang;
     LibPD.Float   += ReceiveFloat;
     LibPD.Symbol  += ReceiveSymbol;
     LibPD.List    += ReceiveList;
     LibPD.Message += ReceiveMessage;
 }
Exemplo n.º 23
0
 public void Open(params string[] patchesName)
 {
     foreach (string patchName in patchesName)
     {
         string path = GetPatchPath(patchName);
         patches[Path.GetFileName(patchName)] = LibPD.OpenPatch(path);
         pdPlayer.communicator.Initialize();
         pdPlayer.itemManager.Initialize();
     }
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 24
0
 public void Close(params string[] patchesName)
 {
     foreach (string patchName in patchesName)
     {
         if (patches.ContainsKey(patchName))
         {
             LibPD.ClosePatch(patches[patchName]);
             patches.Remove(patchName);
         }
     }
 }
Exemplo n.º 25
0
        public virtual unsafe void testArrayAccess()
        {
            int n = 128;

            Assert.AreEqual(n, LibPD.ArraySize("array1"));

            float[] u = new float[n];
            float[] v = new float[n];
            for (int i = 0; i < n; i++)
            {
                u [i] = i;
            }

            LibPD.WriteArray("array1", 0, u, n);
            LibPD.ReadArray(v, "array1", 0, n);
            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(u [i], v [i], 0);
            }

            fixed(float *vp = v)
            {
                LibPD.ReadArray(&vp [5], "array1", 50, 10);
                for (int i = 0; i < n; i++)
                {
                    if (i < 5 || i >= 15)
                    {
                        Assert.AreEqual(u [i], v [i], 0);
                    }
                    else
                    {
                        Assert.AreEqual(u [i + 45], v [i], 0);
                    }
                }
            }

            fixed(float *up = u)
            {
                LibPD.WriteArray("array1", 10, &up [25], 30);
            }

            LibPD.ReadArray(v, "array1", 0, n);
            for (int i = 0; i < n; i++)
            {
                if (i < 10 || i >= 40)
                {
                    Assert.AreEqual(u [i], v [i], 0);
                }
                else
                {
                    Assert.AreEqual(u [i + 15], v [i], 0);
                }
            }
        }
Exemplo n.º 26
0
 public virtual void testSubscription()
 {
     Assert.False(LibPD.Exists("baz"));
     Assert.False(LibPD.Subscribe(null));
     Assert.True(LibPD.Subscribe("baz"));
     Assert.True(LibPD.Exists("baz"));
     Assert.False(LibPD.Unsubscribe(null));
     Assert.False(LibPD.Unsubscribe(""));
     Assert.True(LibPD.Unsubscribe("baz"));
     Assert.False(LibPD.Exists("baz"));
 }
Exemplo n.º 27
0
        private int OpenPd()
        {
            int bufferSize;
            int noOfBuffers;

            AudioSettings.GetDSPBufferSize(out bufferSize, out noOfBuffers);
            numberOfTicks = bufferSize / LibPD.BlockSize;
            int unitySR = AudioSettings.outputSampleRate;

            return(LibPD.OpenAudio(2, 2, unitySR));
        }
Exemplo n.º 28
0
 void OpenAudio()
 {
     if (LibPD.OpenAudio(2, 2, sampleRate) == 0)
     {
         initialized = true;
     }
     else
     {
         Logger.LogError("Failed to start LibPD.");
     }
 }
Exemplo n.º 29
0
 /// <summary>
 /// Sets up communication with libPd.
 /// </summary>
 void SetUpPd()
 {
     // Open Pd file
     _patchHandle = LibPD.OpenPatch("../../pd/test.pd");
     // Subscribe to receiver
     LibPD.Float += LibPd_Float;
     LibPD.Subscribe(CursorReceiver);
     // Set up audio format for Pd
     LibPD.OpenAudio(0, 2, SampleRate);
     // Start audio
     LibPD.ComputeAudio(true);
 }
Exemplo n.º 30
0
        public void SetOutput(float[] output, int ticks)
        {
            while (LibPD.Process(ticks, new float[0], output) == 0)
            {
                if (BufferReady != null)
                {
                    BufferReady(this, new BufferReadyEventArgs(output));
                }

                Thread.Sleep(999 * BlockSize * ticks / SampleRate);
            }
        }