Skip to content

Commit 9f4690d

Browse files
jvntftherewasaguy
authored andcommitted
separated listener3d and panner3d
fixed orientation methods replaced 'spatializer' with 'listener' in listener3d.js added maxDist methods, .dispose() to panner3d spatial_panning ex with 3d objects, added .set() to panner3d added example to index.html
1 parent 514c9cd commit 9f4690d

File tree

11 files changed

+689
-594
lines changed

11 files changed

+689
-594
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = function(grunt) {
7979
'env': 'src/env',
8080
'delay': 'src/delay',
8181
'effect': 'src/effect',
82-
'spatializer': 'src/spatializer',
82+
'panner3d' : 'src/panner3d',
8383
'listener3d': 'src/listener3d',
8484
'filter': 'src/filter',
8585
'reverb': 'src/reverb',

examples/spatial_listening/index.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/spatial_listening/sketch.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

examples/spatial_panning/sketch.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
// ====================
2-
// DEMO: P5.Panner3D: use mouseX and mouseY to control panners X and Y
3-
// panners positionZ moves from -10000 to 10000
2+
// DEMO: P5.Panner3D: Moves sound in 3D space from max negative coordinates, to max positive
43
// ====================
54

65

76
var soundFile;
87
var panner3d;
9-
var zPos, ZDir;
108
var description, position;
119

1210
function preload() {
1311
soundFormats('mp3', 'ogg');
14-
soundFile = loadSound('../files/beat');
12+
soundFile = loadSound('../files/lucky_dragons_-_power_melody');
1513
}
1614

15+
var i;
16+
var factorI;
1717
function setup() {
18-
createCanvas(500, 500);
19-
soundFile.volume = .6;
18+
createCanvas(500, 500, WEBGL);
19+
2020

21-
//disconnect sound file and send it to output via Panner3D
22-
soundFile.disconnect();
23-
panner3d = new p5.Panner3D();
24-
soundFile.connect(panner3d);
25-
soundFile.loop();
26-
zPos = 0;
27-
zDir = 0.5;
28-
29-
description = createDiv('Panner3D: Control the the panners '+
30-
'positionX and positionY with the mouse '+
31-
'positionZ pans from -100 to 100')
32-
position = 'positionX: 0'+'positionY: 0' + 'positionZ: 0';
21+
description = createDiv('Panner3D: The cone symbolizes the soundFile '+
22+
'which is panning the soundin relation to the center of the '+
23+
'canvas');
3324
p2 = createDiv(position);
3425

3526
description.position(550,0).size(400,50);
3627
p2.position(550,50);
3728

29+
panner1 = new p5.Panner3D();
30+
31+
32+
i = 0;
33+
factorI = 1;
34+
soundFile.disconnect();
35+
soundFile.loop();
36+
soundFile.connect(panner1);
3837
}
3938

4039
function draw() {
4140
background(0);
41+
42+
if (i > 500 || i < -500) {factorI = -1*factorI;}
43+
4244
updateDescription();
45+
46+
push();
47+
translate(i+=factorI*1,i + factorI*1,i + factorI*1);
48+
rotateX(frameCount* 0.01);
49+
rotateY(frameCount* 0.01);
50+
rotateZ(frameCount* 0.01);
51+
cone(100);
52+
pop();
4353

44-
//Pan the sound in the Z direction
45-
if (zPos > 50 || zPos < -50) {
46-
zDir = -zDir;
47-
}
48-
zPos += zDir;
54+
//pan the sound along with the cone
55+
panner1.set(i*10,i*10,i*10);
4956

50-
//Position the sound in 3 dimensions
51-
panner3d.position( max(min(25*(mouseX-width/2),6500),-6500),
52-
max(min(25*(mouseY-width/2),6500),-6500),
53-
max(min(200*zPos,10000),-10000));
54-
ellipse(width/2, height/2, 20, 20);
55-
fill(255,0,0);
56-
ellipse(mouseX, mouseY, 20,20)
5757

5858
}
5959

6060
function updateDescription(){
61-
position = 'positionX: '+ panner3d.positionX() +
62-
'<br>positionY: '+ panner3d.positionY() +
63-
'<br>positionZ: '+panner3d.positionZ();
61+
position = 'positionX: '+ panner1.positionX() +
62+
'<br>positionY: '+ panner1.positionY() +
63+
'<br>positionZ: '+ panner1.positionZ();
6464
p2.html(position);
6565
}

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ <h2>p5.sound
6767
<div><a href="examples/soundFormats">soundFormats</a></div>
6868
<div><a href="examples/soundfileMod_AM">soundfileMod_AM</a></div>
6969
<div><a href="examples/soundfile_playMode">soundfile_playMode</a></div>
70+
<div><a href="examples/spatial_panning">spatial_panning</a></div>
7071
<div><a href="examples/testing_stuff">testing_stuff</a></div>
7172
<div><a href="examples/waveform">waveform</a></div>
7273
<div><a href="examples/waveform_peaks_with_playhead">waveform_peaks_with_playhead</a></div>

0 commit comments

Comments
 (0)