Skip to content

Commit

Permalink
separated listener3d and panner3d
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jvntf authored and therewasaguy committed Aug 15, 2017
1 parent 514c9cd commit 9f4690d
Show file tree
Hide file tree
Showing 11 changed files with 689 additions and 594 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = function(grunt) {
'env': 'src/env',
'delay': 'src/delay',
'effect': 'src/effect',
'spatializer': 'src/spatializer',
'panner3d' : 'src/panner3d',
'listener3d': 'src/listener3d',
'filter': 'src/filter',
'reverb': 'src/reverb',
Expand Down
10 changes: 0 additions & 10 deletions examples/spatial_listening/index.html

This file was deleted.

79 changes: 0 additions & 79 deletions examples/spatial_listening/sketch.js

This file was deleted.

66 changes: 33 additions & 33 deletions examples/spatial_panning/sketch.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
// ====================
// DEMO: P5.Panner3D: use mouseX and mouseY to control panners X and Y
// panners positionZ moves from -10000 to 10000
// DEMO: P5.Panner3D: Moves sound in 3D space from max negative coordinates, to max positive
// ====================


var soundFile;
var panner3d;
var zPos, ZDir;
var description, position;

function preload() {
soundFormats('mp3', 'ogg');
soundFile = loadSound('../files/beat');
soundFile = loadSound('../files/lucky_dragons_-_power_melody');
}

var i;
var factorI;
function setup() {
createCanvas(500, 500);
soundFile.volume = .6;
createCanvas(500, 500, WEBGL);


//disconnect sound file and send it to output via Panner3D
soundFile.disconnect();
panner3d = new p5.Panner3D();
soundFile.connect(panner3d);
soundFile.loop();
zPos = 0;
zDir = 0.5;

description = createDiv('Panner3D: Control the the panners '+
'positionX and positionY with the mouse '+
'positionZ pans from -100 to 100')
position = 'positionX: 0'+'positionY: 0' + 'positionZ: 0';
description = createDiv('Panner3D: The cone symbolizes the soundFile '+
'which is panning the soundin relation to the center of the '+
'canvas');
p2 = createDiv(position);

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

panner1 = new p5.Panner3D();


i = 0;
factorI = 1;
soundFile.disconnect();
soundFile.loop();
soundFile.connect(panner1);
}

function draw() {
background(0);

if (i > 500 || i < -500) {factorI = -1*factorI;}

updateDescription();

push();
translate(i+=factorI*1,i + factorI*1,i + factorI*1);
rotateX(frameCount* 0.01);
rotateY(frameCount* 0.01);
rotateZ(frameCount* 0.01);
cone(100);
pop();

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

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

}

function updateDescription(){
position = 'positionX: '+ panner3d.positionX() +
'<br>positionY: '+ panner3d.positionY() +
'<br>positionZ: '+panner3d.positionZ();
position = 'positionX: '+ panner1.positionX() +
'<br>positionY: '+ panner1.positionY() +
'<br>positionZ: '+ panner1.positionZ();
p2.html(position);
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ <h2>p5.sound
<div><a href="examples/soundFormats">soundFormats</a></div>
<div><a href="examples/soundfileMod_AM">soundfileMod_AM</a></div>
<div><a href="examples/soundfile_playMode">soundfile_playMode</a></div>
<div><a href="examples/spatial_panning">spatial_panning</a></div>
<div><a href="examples/testing_stuff">testing_stuff</a></div>
<div><a href="examples/waveform">waveform</a></div>
<div><a href="examples/waveform_peaks_with_playhead">waveform_peaks_with_playhead</a></div>
Expand Down
Loading

0 comments on commit 9f4690d

Please sign in to comment.