Skip to content

Commit ff116c4

Browse files
committed
Updated Unity2Libpd scene to work with OculusSpatializer plugin.
1 parent 9bec3b1 commit ff116c4

7 files changed

Lines changed: 189 additions & 85 deletions

File tree

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
SpatialiseScene Notes
22
---------------------
3-
This scene demonstrates how to spatialise PD patches within Unity. Due to the
4-
way Unity spatialises sound, this is a slightly involved process.
3+
This scene demonstrates a couple of methods for spatialising Pure Data patches
4+
in Unity.
5+
6+
7+
OculusSpatializer Plugin Method
8+
-------------------------------
9+
10+
This is the simplest method of spatialising patches in Unity. It requires the
11+
following steps:
12+
13+
For the project:
14+
1.) Edit -> Project Settings... -> Audio.
15+
2.) Set Spatializer Plugin to OculusSpatializer.
16+
17+
For each Audio Source in the scene:
18+
1.) Toggle 'Spatialize' and 'Spatialize Post Effect' on.
19+
20+
In testing it, the OculusSpatializer plugin seems to attenuate the sound quite
21+
aggressively, so an alternative approach is also included.
22+
23+
24+
Alternative Method
25+
------------------
26+
27+
This method makes use of Unity's default audio spatialisation framework. It is a
28+
bit more involved than the OculusSpatializer approach, but doesn't attenuate the
29+
sound as aggressively.
530

631
The first thing to note is that, by default, Unity only spatialises
732
AudioSources. It won't apply spatialisation to any other audio producing
833
Components (like LibPdInstance). In order to get around that limitation, we'll
934
need to cheat the system a bit.
1035

11-
After adding an AudioSource and LibPdInstance to a GameObject in your scene, the
12-
steps you'll need to take to spatialise your PD patch are:
36+
After adding an AudioSource and LibPdInstance to a GameObject in your scene,
37+
the steps you'll need to take to spatialise your PD patch are:
1338

1439
1.) Set the AudioSource's AudioClip to the included SpatialiserFix.wav file.
1540
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:
1843
your patch before feeding it to the dac~ object.
1944

2045
This process will ensure that the spatialisation applied to the AudioSource gets
21-
applied to the output of your patch. See FilteredNoise.pd for more information.
22-
23-
24-
Conversely, if you don't want to apply any spatialisation to your patch, you
25-
don't need to do any of the aforementioned steps.
26-
27-
28-
Alternative Approach
29-
--------------------
30-
An alternative, less-involved approach is to use Unity's OculusSpatializer
31-
plugin. When I tested it, this seemed to apply some odd filtering to the sound,
32-
so it's not used in this project, but you may prefer this approach.
33-
34-
To use the OculusSpatializer plugin, the steps are:
35-
36-
1.) Edit -> Project Settings... -> Audio.
37-
2.) Set Spatializer Plugin to OculusSpatializer.
38-
39-
This will spatialise all audio for you, without any need for the aforementioned
40-
SpatialiserFix file and adc~ object in each patch.
46+
applied to the output of your patch. See FilteredNoise-ADC.pd for more
47+
information.

Assets/04-Readme Unity2LibPdScene.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ When called, SendBang() and SendFloat() will both send a bang or a float
1414
Steps necessary for sending a bang to a patch:
1515

1616
1.) In your patch, add a receive object, and give it a name (e.g. receive test).
17-
2.) In the C# script you will use to trigger the bang, call SendBang() with the
18-
name of the receive object as its parameter
19-
(e.g. pdPatch.SendBang("test");).
17+
2.) In the C# script you will use to trigger the bang, call SendBang() with
18+
the name of the receive object as its parameter
19+
(e.g. pdPatch.SendBang("test");).
2020

2121

2222
Steps necessary for sending a float to a patch:
2323

2424
1.) In your patch, add a receive object, and give it a name (e.g. receive test).
2525
2.) In the C# script you will use to trigger the float, call SendFloat() with
26-
the name of the receive object as its first parameter, and the float value
27-
you want to send as its second parameter
28-
(e.g. pdPatch.SendFloat("test", 1.0f);).
26+
the name of the receive object as its first parameter, and the float value
27+
you want to send as its second parameter
28+
(e.g. pdPatch.SendFloat("test", 1.0f);).
2929

3030

3131
More examples of sending data to LibPd will be added in future. Until then you

Assets/Scenes/Unity2LibPdScene.unity

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,68 @@ MonoBehaviour:
971971
patchDir: /StreamingAssets/PdAssets/Unity2LibPdPatches/
972972
patch: {fileID: 102900000, guid: 7341d6c8b5ae80f4b9c3e55c68de573e, type: 3}
973973
pipePrintToConsole: 0
974+
pureDataEvents:
975+
Bang:
976+
m_PersistentCalls:
977+
m_Calls: []
978+
m_TypeName: StringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
979+
PublicKeyToken=null
980+
Float:
981+
m_PersistentCalls:
982+
m_Calls: []
983+
m_TypeName: StringFloatEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
984+
PublicKeyToken=null
985+
Symbol:
986+
m_PersistentCalls:
987+
m_Calls: []
988+
m_TypeName: StringStringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
989+
PublicKeyToken=null
990+
List:
991+
m_PersistentCalls:
992+
m_Calls: []
993+
m_TypeName: StringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
994+
PublicKeyToken=null
995+
Message:
996+
m_PersistentCalls:
997+
m_Calls: []
998+
m_TypeName: StringStringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
999+
PublicKeyToken=null
1000+
midiEvents:
1001+
MidiNoteOn:
1002+
m_PersistentCalls:
1003+
m_Calls: []
1004+
m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1005+
PublicKeyToken=null
1006+
MidiControlChange:
1007+
m_PersistentCalls:
1008+
m_Calls: []
1009+
m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1010+
PublicKeyToken=null
1011+
MidiProgramChange:
1012+
m_PersistentCalls:
1013+
m_Calls: []
1014+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1015+
PublicKeyToken=null
1016+
MidiPitchBend:
1017+
m_PersistentCalls:
1018+
m_Calls: []
1019+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1020+
PublicKeyToken=null
1021+
MidiAftertouch:
1022+
m_PersistentCalls:
1023+
m_Calls: []
1024+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1025+
PublicKeyToken=null
1026+
MidiPolyAftertouch:
1027+
m_PersistentCalls:
1028+
m_Calls: []
1029+
m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1030+
PublicKeyToken=null
1031+
MidiByte:
1032+
m_PersistentCalls:
1033+
m_Calls: []
1034+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1035+
PublicKeyToken=null
9741036
--- !u!82 &1103632481
9751037
AudioSource:
9761038
m_ObjectHideFlags: 0
@@ -980,14 +1042,14 @@ AudioSource:
9801042
m_Enabled: 1
9811043
serializedVersion: 4
9821044
OutputAudioMixerGroup: {fileID: 0}
983-
m_audioClip: {fileID: 8300000, guid: 0dcf45c10555ee943b10c474b1d1fee2, type: 3}
1045+
m_audioClip: {fileID: 0}
9841046
m_PlayOnAwake: 1
9851047
m_Volume: 1
9861048
m_Pitch: 1
987-
Loop: 1
1049+
Loop: 0
9881050
Mute: 0
989-
Spatialize: 0
990-
SpatializePostEffects: 0
1051+
Spatialize: 1
1052+
SpatializePostEffects: 1
9911053
Priority: 128
9921054
DopplerLevel: 1
9931055
MinDistance: 1
@@ -1354,6 +1416,68 @@ MonoBehaviour:
13541416
patchDir: /StreamingAssets/PdAssets/Unity2LibPdPatches/
13551417
patch: {fileID: 102900000, guid: 131d5aebbccdcfb4cb9e49d9daf8227c, type: 3}
13561418
pipePrintToConsole: 0
1419+
pureDataEvents:
1420+
Bang:
1421+
m_PersistentCalls:
1422+
m_Calls: []
1423+
m_TypeName: StringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1424+
PublicKeyToken=null
1425+
Float:
1426+
m_PersistentCalls:
1427+
m_Calls: []
1428+
m_TypeName: StringFloatEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1429+
PublicKeyToken=null
1430+
Symbol:
1431+
m_PersistentCalls:
1432+
m_Calls: []
1433+
m_TypeName: StringStringEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1434+
PublicKeyToken=null
1435+
List:
1436+
m_PersistentCalls:
1437+
m_Calls: []
1438+
m_TypeName: StringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1439+
PublicKeyToken=null
1440+
Message:
1441+
m_PersistentCalls:
1442+
m_Calls: []
1443+
m_TypeName: StringStringObjArrEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1444+
PublicKeyToken=null
1445+
midiEvents:
1446+
MidiNoteOn:
1447+
m_PersistentCalls:
1448+
m_Calls: []
1449+
m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1450+
PublicKeyToken=null
1451+
MidiControlChange:
1452+
m_PersistentCalls:
1453+
m_Calls: []
1454+
m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1455+
PublicKeyToken=null
1456+
MidiProgramChange:
1457+
m_PersistentCalls:
1458+
m_Calls: []
1459+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1460+
PublicKeyToken=null
1461+
MidiPitchBend:
1462+
m_PersistentCalls:
1463+
m_Calls: []
1464+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1465+
PublicKeyToken=null
1466+
MidiAftertouch:
1467+
m_PersistentCalls:
1468+
m_Calls: []
1469+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1470+
PublicKeyToken=null
1471+
MidiPolyAftertouch:
1472+
m_PersistentCalls:
1473+
m_Calls: []
1474+
m_TypeName: IntIntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1475+
PublicKeyToken=null
1476+
MidiByte:
1477+
m_PersistentCalls:
1478+
m_Calls: []
1479+
m_TypeName: IntIntEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
1480+
PublicKeyToken=null
13571481
--- !u!82 &1212949217
13581482
AudioSource:
13591483
m_ObjectHideFlags: 0
@@ -1363,14 +1487,14 @@ AudioSource:
13631487
m_Enabled: 1
13641488
serializedVersion: 4
13651489
OutputAudioMixerGroup: {fileID: 0}
1366-
m_audioClip: {fileID: 8300000, guid: 0dcf45c10555ee943b10c474b1d1fee2, type: 3}
1490+
m_audioClip: {fileID: 0}
13671491
m_PlayOnAwake: 1
13681492
m_Volume: 1
13691493
m_Pitch: 1
1370-
Loop: 1
1494+
Loop: 0
13711495
Mute: 0
1372-
Spatialize: 0
1373-
SpatializePostEffects: 0
1496+
Spatialize: 1
1497+
SpatializePostEffects: 1
13741498
Priority: 128
13751499
DopplerLevel: 1
13761500
MinDistance: 1
Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
#N canvas 481 50 704 553 10;
2-
#X obj 35 195 adc~;
3-
#X obj 6 190 cnv 16 60 80 empty empty Spatialise_Output 40 -12 0 16
4-
-260584 -66577 0;
1+
#N canvas 481 50 704 424 10;
52
#X obj 6 107 cnv 16 162 60 empty empty Amplitude_Envelope 24 -12 0
63
16 -179694 -66577 0;
7-
#X obj 14 253 dac~;
8-
#X obj 32 194 adc~;
9-
#X obj 14 230 *~;
10-
#X obj 39 230 *~;
4+
#X obj 14 187 dac~;
115
#X obj 14 18 osc~ 440;
126
#X obj 14 148 *~;
137
#X obj 84 134 vline~;
148
#X msg 84 113 1 10;
159
#X msg 131 119 0 10;
1610
#X obj 131 65 receive VolumeDown;
1711
#X obj 84 46 receive VolumeUp;
18-
#X text 70 206 See FilteredNoise.pd in;
19-
#X text 70 217 the Spatialisation scene;
20-
#X text 71 228 for an explanation of;
21-
#X text 70 238 this structure.;
2212
#X text 5 1 Sine Oscillator;
2313
#X text 83 27 These receive objects are how we receive;
2414
#X text 200 39 signals from our Unity;
@@ -28,15 +18,11 @@
2818
#X text 193 84 VolumeDown will trigger;
2919
#X text 258 95 a ramp of the;
3020
#X text 194 106 oscillator's amplitude.;
31-
#X connect 4 0 5 1;
32-
#X connect 4 1 6 1;
33-
#X connect 5 0 3 0;
34-
#X connect 6 0 3 1;
35-
#X connect 7 0 8 0;
21+
#X connect 2 0 3 0;
22+
#X connect 3 0 1 0;
23+
#X connect 3 0 1 1;
24+
#X connect 4 0 3 1;
25+
#X connect 5 0 4 0;
26+
#X connect 6 0 4 0;
27+
#X connect 7 0 6 0;
3628
#X connect 8 0 5 0;
37-
#X connect 8 0 6 0;
38-
#X connect 9 0 8 1;
39-
#X connect 10 0 9 0;
40-
#X connect 11 0 9 0;
41-
#X connect 12 0 11 0;
42-
#X connect 13 0 10 0;
Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
#N canvas 365 101 635 495 10;
2-
#X obj 68 152 cnv 16 54 80 empty empty Spatialisation_Output 32 -12
3-
0 16 -260584 -66577 0;
4-
#X obj 73 214 dac~;
5-
#X obj 91 155 adc~;
6-
#X obj 73 191 *~;
7-
#X obj 98 190 *~;
1+
#N canvas 365 101 635 374 10;
2+
#X obj 73 164 dac~;
83
#X obj 7 111 osc~;
94
#X obj 73 125 *~;
105
#X obj 91 57 vline~;
@@ -20,21 +15,13 @@
2015
#X text 137 66 applies to both the;
2116
#X text 136 77 oscillator's frequency \,;
2217
#X text 136 88 and its amplitude.;
23-
#X text 125 166 See FilteredNoise.pd in;
24-
#X text 124 175 the Spatialisation scene;
25-
#X text 125 185 for an explanation of;
26-
#X text 124 195 this structure.;
27-
#X connect 2 0 3 1;
28-
#X connect 2 1 4 1;
29-
#X connect 3 0 1 0;
30-
#X connect 4 0 1 1;
31-
#X connect 5 0 6 0;
32-
#X connect 6 0 3 0;
18+
#X connect 1 0 2 0;
19+
#X connect 2 0 0 0;
20+
#X connect 2 0 0 1;
21+
#X connect 3 0 5 0;
22+
#X connect 3 0 6 0;
23+
#X connect 4 0 1 0;
24+
#X connect 5 0 2 1;
3325
#X connect 6 0 4 0;
34-
#X connect 7 0 9 0;
35-
#X connect 7 0 10 0;
36-
#X connect 8 0 5 0;
37-
#X connect 9 0 6 1;
38-
#X connect 10 0 8 0;
39-
#X connect 11 0 7 0;
40-
#X connect 12 0 11 0;
26+
#X connect 7 0 3 0;
27+
#X connect 8 0 7 0;
34.3 KB
Loading
71.6 KB
Loading

0 commit comments

Comments
 (0)