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); } }
// 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); }
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); }
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); } } }
// 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); // } }
public void Process(float[] output, int ticks) { if (LibPD.Process(ticks, new float[0], output) == 0 && BufferReady != null) { BufferReady(this, new BufferReadyEventArgs(output)); } }
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; }
public static void closePatch() { LibPD.Release(); while (loader.FreeLibrary(SDllHandle)) { } }
public PdOperation(string filePath) { _patchHandle = LibPD.OpenPatch(filePath); LibPD.Bang += LibPD_Bang; LibPD.Subscribe(DoneReceiver); LibPD.OpenAudio(0, 2, SampleRate); LibPD.ComputeAudio(true); }
public static void loadPatch() { SDllHandle = LoadLibrary("libpdcsharp.dll"); LibPD.ReInit(); LibPD.OpenAudio(2, 3, 44100); SPatch = LibPD.OpenPatch(@"..\..\test_csharp.pd"); LibPD.ComputeAudio(true); }
public void SubscribeDebug() { LibPD.Subscribe("Debug"); LibPD.Bang += ReceiveDebugBang; LibPD.Float += ReceiveDebugFloat; LibPD.Symbol += ReceiveDebugSymbol; LibPD.List += ReceiveDebugList; LibPD.Message += ReceiveDebugMessage; }
void OnDestroy() { LibPD.Bang -= ReceiveDebugBang; LibPD.Float -= ReceiveDebugFloat; LibPD.Symbol -= ReceiveDebugSymbol; LibPD.List -= ReceiveDebugList; LibPD.Message -= ReceiveDebugMessage; LibPD.Unsubscribe("Debug"); }
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(); } }
// Close patch and release Pd on quit void OnApplicationQuit() { // Unsubscribe Pd print object. LibPD.Print -= ReceivePrint; closePatch(SPatch); LibPD.Release(); islibpdready = false; }
/// <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); } }
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)); }
void Dispose(bool isDisposing) { LibPD.Unsubscribe(DoneReceiver); LibPD.ComputeAudio(false); if (_patchHandle > 0) { LibPD.ClosePatch(_patchHandle); } }
// 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)); }
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; }
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)); }
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; }
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); }
public void Close(params string[] patchesName) { foreach (string patchName in patchesName) { if (patches.ContainsKey(patchName)) { LibPD.ClosePatch(patches[patchName]); patches.Remove(patchName); } } }
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); } } }
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")); }
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)); }
void OpenAudio() { if (LibPD.OpenAudio(2, 2, sampleRate) == 0) { initialized = true; } else { Logger.LogError("Failed to start LibPD."); } }
/// <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); }
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); } }