diff --git a/Assets/03-Readme SpatialiseScene.txt b/Assets/03-Readme SpatialiseScene.txt index e3cf216..989ae05 100644 --- a/Assets/03-Readme SpatialiseScene.txt +++ b/Assets/03-Readme SpatialiseScene.txt @@ -1,15 +1,40 @@ SpatialiseScene Notes --------------------- -This scene demonstrates how to spatialise PD patches within Unity. Due to the -way Unity spatialises sound, this is a slightly involved process. +This scene demonstrates a couple of methods for spatialising Pure Data patches +in Unity. + + +OculusSpatializer Plugin Method +------------------------------- + +This is the simplest method of spatialising patches in Unity. It requires the +following steps: + +For the project: +1.) Edit -> Project Settings... -> Audio. +2.) Set Spatializer Plugin to OculusSpatializer. + +For each Audio Source in the scene: +1.) Toggle 'Spatialize' and 'Spatialize Post Effect' on. + +In testing it, the OculusSpatializer plugin seems to attenuate the sound quite +aggressively, so an alternative approach is also included. + + +Alternative Method +------------------ + +This method makes use of Unity's default audio spatialisation framework. It is a +bit more involved than the OculusSpatializer approach, but doesn't attenuate the +sound as aggressively. The first thing to note is that, by default, Unity only spatialises AudioSources. It won't apply spatialisation to any other audio producing Components (like LibPdInstance). In order to get around that limitation, we'll need to cheat the system a bit. -After adding an AudioSource and LibPdInstance to a GameObject in your scene, the -steps you'll need to take to spatialise your PD patch are: +After adding an AudioSource and LibPdInstance to a GameObject in your scene, +the steps you'll need to take to spatialise your PD patch are: 1.) Set the AudioSource's AudioClip to the included SpatialiserFix.wav file. 2.) Set the AudioSource to Play On Awake and Loop. @@ -18,23 +43,5 @@ steps you'll need to take to spatialise your PD patch are: your patch before feeding it to the dac~ object. This process will ensure that the spatialisation applied to the AudioSource gets -applied to the output of your patch. See FilteredNoise.pd for more information. - - -Conversely, if you don't want to apply any spatialisation to your patch, you -don't need to do any of the aforementioned steps. - - -Alternative Approach --------------------- -An alternative, less-involved approach is to use Unity's OculusSpatializer -plugin. When I tested it, this seemed to apply some odd filtering to the sound, -so it's not used in this project, but you may prefer this approach. - -To use the OculusSpatializer plugin, the steps are: - -1.) Edit -> Project Settings... -> Audio. -2.) Set Spatializer Plugin to OculusSpatializer. - -This will spatialise all audio for you, without any need for the aforementioned -SpatialiserFix file and adc~ object in each patch. +applied to the output of your patch. See FilteredNoise-ADC.pd for more +information. diff --git a/Assets/04-Readme Unity2LibPdScene.txt b/Assets/04-Readme Unity2LibPdScene.txt index 0da81b6..e33cb6a 100644 --- a/Assets/04-Readme Unity2LibPdScene.txt +++ b/Assets/04-Readme Unity2LibPdScene.txt @@ -14,18 +14,18 @@ When called, SendBang() and SendFloat() will both send a bang or a float Steps necessary for sending a bang to a patch: 1.) In your patch, add a receive object, and give it a name (e.g. receive test). -2.) In the C# script you will use to trigger the bang, call SendBang() with the - name of the receive object as its parameter - (e.g. pdPatch.SendBang("test");). +2.) In the C# script you will use to trigger the bang, call SendBang() with + the name of the receive object as its parameter + (e.g. pdPatch.SendBang("test");). Steps necessary for sending a float to a patch: 1.) In your patch, add a receive object, and give it a name (e.g. receive test). 2.) In the C# script you will use to trigger the float, call SendFloat() with - the name of the receive object as its first parameter, and the float value - you want to send as its second parameter - (e.g. pdPatch.SendFloat("test", 1.0f);). + the name of the receive object as its first parameter, and the float value + you want to send as its second parameter + (e.g. pdPatch.SendFloat("test", 1.0f);). More examples of sending data to LibPd will be added in future. Until then you diff --git a/Assets/Scenes/Unity2LibPdScene.unity b/Assets/Scenes/Unity2LibPdScene.unity index 08c966f..e67b7cb 100644 --- a/Assets/Scenes/Unity2LibPdScene.unity +++ b/Assets/Scenes/Unity2LibPdScene.unity @@ -971,6 +971,68 @@ MonoBehaviour: patchDir: /StreamingAssets/PdAssets/Unity2LibPdPatches/ patch: {fileID: 102900000, guid: 7341d6c8b5ae80f4b9c3e55c68de573e, type: 3} pipePrintToConsole: 0 + pureDataEvents: + Bang: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Float: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringFloatEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Symbol: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringStringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + List: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Message: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringStringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + midiEvents: + MidiNoteOn: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiControlChange: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiProgramChange: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiPitchBend: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiAftertouch: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiPolyAftertouch: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiByte: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null --- !u!82 &1103632481 AudioSource: m_ObjectHideFlags: 0 @@ -980,14 +1042,14 @@ AudioSource: m_Enabled: 1 serializedVersion: 4 OutputAudioMixerGroup: {fileID: 0} - m_audioClip: {fileID: 8300000, guid: 0dcf45c10555ee943b10c474b1d1fee2, type: 3} + m_audioClip: {fileID: 0} m_PlayOnAwake: 1 m_Volume: 1 m_Pitch: 1 - Loop: 1 + Loop: 0 Mute: 0 - Spatialize: 0 - SpatializePostEffects: 0 + Spatialize: 1 + SpatializePostEffects: 1 Priority: 128 DopplerLevel: 1 MinDistance: 1 @@ -1354,6 +1416,68 @@ MonoBehaviour: patchDir: /StreamingAssets/PdAssets/Unity2LibPdPatches/ patch: {fileID: 102900000, guid: 131d5aebbccdcfb4cb9e49d9daf8227c, type: 3} pipePrintToConsole: 0 + pureDataEvents: + Bang: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Float: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringFloatEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Symbol: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringStringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + List: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Message: + m_PersistentCalls: + m_Calls: [] + m_TypeName: StringStringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + midiEvents: + MidiNoteOn: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiControlChange: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiProgramChange: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiPitchBend: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiAftertouch: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiPolyAftertouch: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + MidiByte: + m_PersistentCalls: + m_Calls: [] + m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null --- !u!82 &1212949217 AudioSource: m_ObjectHideFlags: 0 @@ -1363,14 +1487,14 @@ AudioSource: m_Enabled: 1 serializedVersion: 4 OutputAudioMixerGroup: {fileID: 0} - m_audioClip: {fileID: 8300000, guid: 0dcf45c10555ee943b10c474b1d1fee2, type: 3} + m_audioClip: {fileID: 0} m_PlayOnAwake: 1 m_Volume: 1 m_Pitch: 1 - Loop: 1 + Loop: 0 Mute: 0 - Spatialize: 0 - SpatializePostEffects: 0 + Spatialize: 1 + SpatializePostEffects: 1 Priority: 128 DopplerLevel: 1 MinDistance: 1 diff --git a/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/BangExample.pd b/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/BangExample.pd index c7e4d41..5f9be10 100644 --- a/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/BangExample.pd +++ b/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/BangExample.pd @@ -1,13 +1,7 @@ -#N canvas 481 50 704 553 10; -#X obj 35 195 adc~; -#X obj 6 190 cnv 16 60 80 empty empty Spatialise_Output 40 -12 0 16 --260584 -66577 0; +#N canvas 481 50 704 424 10; #X obj 6 107 cnv 16 162 60 empty empty Amplitude_Envelope 24 -12 0 16 -179694 -66577 0; -#X obj 14 253 dac~; -#X obj 32 194 adc~; -#X obj 14 230 *~; -#X obj 39 230 *~; +#X obj 14 187 dac~; #X obj 14 18 osc~ 440; #X obj 14 148 *~; #X obj 84 134 vline~; @@ -15,10 +9,6 @@ #X msg 131 119 0 10; #X obj 131 65 receive VolumeDown; #X obj 84 46 receive VolumeUp; -#X text 70 206 See FilteredNoise.pd in; -#X text 70 217 the Spatialisation scene; -#X text 71 228 for an explanation of; -#X text 70 238 this structure.; #X text 5 1 Sine Oscillator; #X text 83 27 These receive objects are how we receive; #X text 200 39 signals from our Unity; @@ -28,15 +18,11 @@ #X text 193 84 VolumeDown will trigger; #X text 258 95 a ramp of the; #X text 194 106 oscillator's amplitude.; -#X connect 4 0 5 1; -#X connect 4 1 6 1; -#X connect 5 0 3 0; -#X connect 6 0 3 1; -#X connect 7 0 8 0; +#X connect 2 0 3 0; +#X connect 3 0 1 0; +#X connect 3 0 1 1; +#X connect 4 0 3 1; +#X connect 5 0 4 0; +#X connect 6 0 4 0; +#X connect 7 0 6 0; #X connect 8 0 5 0; -#X connect 8 0 6 0; -#X connect 9 0 8 1; -#X connect 10 0 9 0; -#X connect 11 0 9 0; -#X connect 12 0 11 0; -#X connect 13 0 10 0; diff --git a/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/FloatExample.pd b/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/FloatExample.pd index 81075de..03fff1a 100644 --- a/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/FloatExample.pd +++ b/Assets/StreamingAssets/PdAssets/Unity2LibPdPatches/FloatExample.pd @@ -1,10 +1,5 @@ -#N canvas 365 101 635 495 10; -#X obj 68 152 cnv 16 54 80 empty empty Spatialisation_Output 32 -12 -0 16 -260584 -66577 0; -#X obj 73 214 dac~; -#X obj 91 155 adc~; -#X obj 73 191 *~; -#X obj 98 190 *~; +#N canvas 365 101 635 374 10; +#X obj 73 164 dac~; #X obj 7 111 osc~; #X obj 73 125 *~; #X obj 91 57 vline~; @@ -20,21 +15,13 @@ #X text 137 66 applies to both the; #X text 136 77 oscillator's frequency \,; #X text 136 88 and its amplitude.; -#X text 125 166 See FilteredNoise.pd in; -#X text 124 175 the Spatialisation scene; -#X text 125 185 for an explanation of; -#X text 124 195 this structure.; -#X connect 2 0 3 1; -#X connect 2 1 4 1; -#X connect 3 0 1 0; -#X connect 4 0 1 1; -#X connect 5 0 6 0; -#X connect 6 0 3 0; +#X connect 1 0 2 0; +#X connect 2 0 0 0; +#X connect 2 0 0 1; +#X connect 3 0 5 0; +#X connect 3 0 6 0; +#X connect 4 0 1 0; +#X connect 5 0 2 1; #X connect 6 0 4 0; -#X connect 7 0 9 0; -#X connect 7 0 10 0; -#X connect 8 0 5 0; -#X connect 9 0 6 1; -#X connect 10 0 8 0; -#X connect 11 0 7 0; -#X connect 12 0 11 0; +#X connect 7 0 3 0; +#X connect 8 0 7 0; diff --git a/docs/images/screenshot-spatialisation.jpg b/docs/images/screenshot-spatialisation.jpg index 6d0e4ef..4feda75 100644 Binary files a/docs/images/screenshot-spatialisation.jpg and b/docs/images/screenshot-spatialisation.jpg differ diff --git a/docs/images/screenshot-spatialisation.png b/docs/images/screenshot-spatialisation.png index 93f80ea..6fe326e 100644 Binary files a/docs/images/screenshot-spatialisation.png and b/docs/images/screenshot-spatialisation.png differ