From d81609f0459709959e5cb02c4f7cab335b0a1630 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 11 Nov 2014 11:16:45 -0800 Subject: [PATCH] use hash in place of AudioInjectionOptions in other js files --- examples/clap.js | 8 +++---- examples/drumStick.js | 7 +++++-- examples/editVoxels.js | 8 ++++--- examples/entityBirds.js | 8 +++---- examples/entityScripts/playSoundOnClick.js | 9 ++++---- .../entityScripts/playSoundOnEnterOrLeave.js | 11 +++++----- examples/frisbee.js | 8 +++---- examples/grenadeLauncher.js | 5 +++-- examples/gun.js | 5 +++-- examples/headMove.js | 10 +++------ examples/inWorldTestTone.js | 8 +++---- examples/playSound.js | 11 +++++----- examples/playSoundLoop.js | 10 +++++---- examples/playSoundOrbit.js | 21 +++++++++---------- examples/playSoundWave.js | 9 ++++---- examples/radio.js | 10 +++++---- examples/spaceInvadersExample.js | 13 ++++++------ examples/toyball.js | 15 +++---------- examples/walk.js | 8 ++++--- 19 files changed, 89 insertions(+), 95 deletions(-) diff --git a/examples/clap.js b/examples/clap.js index 9cc79a1c92..bf71f13cea 100644 --- a/examples/clap.js +++ b/examples/clap.js @@ -89,11 +89,11 @@ function maybePlaySound(deltaTime) { } function playClap(volume, position) { - var options = new AudioInjectionOptions(); - options.position = position; - options.volume = 1.0; var clip = Math.floor(Math.random() * numberOfSounds); - Audio.playSound(claps[clip], options); + Audio.playSound(claps[clip], { + position: position, + volume: volume + }); } var FASTEST_CLAP_INTERVAL = 150.0; diff --git a/examples/drumStick.js b/examples/drumStick.js index d0560057c0..1af9ffc3dd 100644 --- a/examples/drumStick.js +++ b/examples/drumStick.js @@ -63,8 +63,11 @@ function checkSticks(deltaTime) { // Waiting for change in velocity direction or slowing to trigger drum sound if ((palmVelocity.y > 0.0) || (speed < STOP_SPEED)) { state[palm] = 0; - var options = new AudioInjectionOptions(); - options.position = Controller.getSpatialControlPosition(palm * 2 + 1); + + var options = { + position: Controller.getSpatialControlPosition(palm * 2 + 1); + } + if (strokeSpeed[palm] > 1.0) { strokeSpeed[palm] = 1.0; } options.volume = strokeSpeed[palm]; diff --git a/examples/editVoxels.js b/examples/editVoxels.js index e450f2d1d4..0747b9269f 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -68,9 +68,11 @@ var numColors = 9; var whichColor = 0; // Starting color is 'Copy' mode // Create sounds for for every script actions that require one -var audioOptions = new AudioInjectionOptions(); -audioOptions.volume = 1.0; -audioOptions.position = Vec3.sum(MyAvatar.position, { x: 0, y: 1, z: 0 } ); // start with audio slightly above the avatar +// start with audio slightly above the avatar +var audioOptions = { + position: Vec3.sum(MyAvatar.position, { x: 0, y: 1, z: 0 } ), + volume: 1.0 +}; function SoundArray() { this.audioOptions = audioOptions diff --git a/examples/entityBirds.js b/examples/entityBirds.js index bbc35a5f58..d18513ba49 100644 --- a/examples/entityBirds.js +++ b/examples/entityBirds.js @@ -135,10 +135,10 @@ function updateBirds(deltaTime) { // Tweeting behavior if (birds[i].tweeting == 0) { if (Math.random() < CHANCE_OF_TWEETING) { - var options = new AudioInjectionOptions(); - options.position = properties.position; - options.volume = 0.75; - Audio.playSound(birds[i].tweetSound, options); + Audio.playSound(birds[i].tweetSound, { + position: properties.position, + volume: 0.75 + }); birds[i].tweeting = 10; } } else { diff --git a/examples/entityScripts/playSoundOnClick.js b/examples/entityScripts/playSoundOnClick.js index b261bb269a..fea68db2c3 100644 --- a/examples/entityScripts/playSoundOnClick.js +++ b/examples/entityScripts/playSoundOnClick.js @@ -15,10 +15,9 @@ var bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); this.clickDownOnEntity = function(entityID, mouseEvent) { print("clickDownOnEntity()..."); - var options = new AudioInjectionOptions(); - var position = MyAvatar.position; - options.position = position; - options.volume = 0.5; - Audio.playSound(bird, options); + Audio.playSound(bird, { + position: MyAvatar.position, + volume: 0.5 + }); }; }) diff --git a/examples/entityScripts/playSoundOnEnterOrLeave.js b/examples/entityScripts/playSoundOnEnterOrLeave.js index 228a8a36d0..ab8bcbd2bd 100644 --- a/examples/entityScripts/playSoundOnEnterOrLeave.js +++ b/examples/entityScripts/playSoundOnEnterOrLeave.js @@ -14,12 +14,11 @@ (function(){ var bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); - function playSound(entityID) { - var options = new AudioInjectionOptions(); - var position = MyAvatar.position; - options.position = position; - options.volume = 0.5; - Audio.playSound(bird, options); + function playSound(entityID) { + Audio.playSound(bird, { + position: MyAvatar.position, + volume: 0.5 + }); }; this.enterEntity = function(entityID) { diff --git a/examples/frisbee.js b/examples/frisbee.js index c534a8b3fb..7e266de34b 100644 --- a/examples/frisbee.js +++ b/examples/frisbee.js @@ -177,10 +177,10 @@ function playSound(sound, position) { if (!SOUNDS_ENABLED) { return; } - var options = new AudioInjectionOptions(); - options.position = position; - options.volume = 1.0; - Audio.playSound(sound, options); + + Audio.playSound(sound,{ + position: position + }); } function cleanupFrisbees() { diff --git a/examples/grenadeLauncher.js b/examples/grenadeLauncher.js index bca067326a..e95d8dd79d 100644 --- a/examples/grenadeLauncher.js +++ b/examples/grenadeLauncher.js @@ -44,8 +44,9 @@ var targetLaunchSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/ var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; -var audioOptions = new AudioInjectionOptions(); -audioOptions.volume = 0.9; +var audioOptions { + volume: 0.9 +} var shotsFired = 0; diff --git a/examples/gun.js b/examples/gun.js index 385664226c..76084ce013 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -43,8 +43,9 @@ var targetLaunchSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/ var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; -var audioOptions = new AudioInjectionOptions(); -audioOptions.volume = 0.9; +var audioOptions = { + volume: 0.9 +} var shotsFired = 0; diff --git a/examples/headMove.js b/examples/headMove.js index b1f1c4ab7d..957686bb20 100644 --- a/examples/headMove.js +++ b/examples/headMove.js @@ -72,15 +72,11 @@ var WATCH_AVATAR_DISTANCE = 2.5; var sound = new Sound("http://public.highfidelity.io/sounds/Footsteps/FootstepW2Right-12db.wav"); function playSound() { - var options = new AudioInjectionOptions(); - var position = MyAvatar.position; - options.position = position; - options.volume = 1.0; - Audio.playSound(sound, options); + Audio.playSound(sound, { + position: MyAvatar.position + }); } - - function pullBack() { saveCameraState(); cameraPosition = Vec3.subtract(MyAvatar.position, Vec3.multiplyQbyV(Camera.getOrientation(), { x: 0, y: -hipsToEyes, z: -hipsToEyes * WATCH_AVATAR_DISTANCE })); diff --git a/examples/inWorldTestTone.js b/examples/inWorldTestTone.js index 590bb6c342..b3bf91d14d 100644 --- a/examples/inWorldTestTone.js +++ b/examples/inWorldTestTone.js @@ -19,11 +19,9 @@ var soundPlaying = false; function update(deltaTime) { if (!Audio.isInjectorPlaying(soundPlaying)) { - var options = new AudioInjectionOptions(); - options.position = { x:0, y:0, z:0 }; - options.volume = 1.0; - options.loop = true; - soundPlaying = Audio.playSound(sound, options); + soundPlaying = Audio.playSound(sound, { + loop: true + }); print("Started sound loop"); } } diff --git a/examples/playSound.js b/examples/playSound.js index 4130db5b16..efcda0b42b 100644 --- a/examples/playSound.js +++ b/examples/playSound.js @@ -15,12 +15,11 @@ var bird = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); function maybePlaySound(deltaTime) { if (Math.random() < 0.01) { - // Set the location and other info for the sound to play - var options = new AudioInjectionOptions(); - var position = MyAvatar.position; - options.position = position; - options.volume = 0.5; - Audio.playSound(bird, options); + // Set the location and other info for the sound to play + Audio.playSound(bird, { + position: MyAvatar.position, + volume: 0.5 + }); } } diff --git a/examples/playSoundLoop.js b/examples/playSoundLoop.js index 3122f13f37..b84c475d1a 100644 --- a/examples/playSoundLoop.js +++ b/examples/playSoundLoop.js @@ -20,10 +20,12 @@ var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw" //var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Cocktail+Party+Snippets/Bandcamp.wav"); var soundPlaying = false; -var options = new AudioInjectionOptions(); -options.position = Vec3.sum(Camera.getPosition(), Quat.getFront(MyAvatar.orientation)); -options.volume = 0.5; -options.loop = true; +var options = { + position: Vec3.sum(Camera.getPosition(), Quat.getFront(MyAvatar.orientation)), + volume: 0.5, + loop: true +} + var playing = false; var ball = false; diff --git a/examples/playSoundOrbit.js b/examples/playSoundOrbit.js index 2c44a4535a..d98f7d0768 100644 --- a/examples/playSoundOrbit.js +++ b/examples/playSoundOrbit.js @@ -19,24 +19,23 @@ var distance = 1; var debug = 0; function playSound() { - var options = new AudioInjectionOptions(); - currentTime += deltaTime; + currentTime += deltaTime; var s = distance * Math.sin(currentTime); var c = distance * Math.cos(currentTime); - var soundOffset = { x:s, y:0, z:c }; + var soundOffset = { x:s, y:0, z:c }; - if (debug) { - print("t=" + currentTime + "offset=" + soundOffset.x + "," + soundOffset.y + "," + soundOffset.z); - } + if (debug) { + print("t=" + currentTime + "offset=" + soundOffset.x + "," + soundOffset.y + "," + soundOffset.z); + } - var avatarPosition = MyAvatar.position; - var soundPosition = Vec3.sum(avatarPosition,soundOffset); + var avatarPosition = MyAvatar.position; + var soundPosition = Vec3.sum(avatarPosition,soundOffset); - options.position = soundPosition - options.volume = 1.0; - Audio.playSound(soundClip, options); + Audio.playSound(soundClip, { + position: soundPosition + }); } Script.setInterval(playSound, 250); diff --git a/examples/playSoundWave.js b/examples/playSoundWave.js index f152effb47..c5e69f5cd6 100644 --- a/examples/playSoundWave.js +++ b/examples/playSoundWave.js @@ -14,11 +14,10 @@ Script.include("libraries/globals.js"); var soundClip = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Cocktail%20Party%20Snippets/Walken1.wav"); function playSound() { - var options = new AudioInjectionOptions(); - var position = MyAvatar.position; - options.position = position; - options.volume = 0.5; - Audio.playSound(soundClip, options); + Audio.playSound(soundClip, { + position: MyAvatar.position, + volume: 0.5 + }); } Script.setInterval(playSound, 10000); diff --git a/examples/radio.js b/examples/radio.js index 293867398a..fc09fb184e 100644 --- a/examples/radio.js +++ b/examples/radio.js @@ -15,10 +15,12 @@ var modelURL = HIFI_PUBLIC_BUCKET + "models/entities/radio/Speakers.fbx"; var soundURL = HIFI_PUBLIC_BUCKET + "sounds/FamilyStereo.raw"; var AudioRotationOffset = Quat.fromPitchYawRollDegrees(0, -90, 0); -var audioOptions = new AudioInjectionOptions(); -audioOptions.volume = 0.5; -audioOptions.loop = true; -audioOptions.isStereo = true; +var audioOptions = { + volume: 0.5, + loop: true, + stereo: true +} + var injector = null; var sound = new Sound(soundURL, audioOptions.isStereo); diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index 8d69f066d6..dd5ac9e875 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -217,7 +217,8 @@ function update(deltaTime) { if (invaderStepOfCycle % stepsPerSound == 0) { // play the move sound - var options = new AudioInjectionOptions(); + var options = {}; + if (soundInMyHead) { options.position = { x: MyAvatar.position.x + 0.0, y: MyAvatar.position.y + 0.1, @@ -225,7 +226,7 @@ function update(deltaTime) { } else { options.position = getInvaderPosition(invadersPerRow / 2, numberOfRows / 2); } - options.volume = 1.0; + Audio.playSound(moveSounds[currentMoveSound], options); // get ready for next move sound @@ -330,7 +331,7 @@ function fireMissile() { lifetime: 5 }); - var options = new AudioInjectionOptions(); + var options = {} if (soundInMyHead) { options.position = { x: MyAvatar.position.x + 0.0, y: MyAvatar.position.y + 0.1, @@ -338,7 +339,7 @@ function fireMissile() { } else { options.position = missilePosition; } - options.volume = 1.0; + Audio.playSound(shootSound, options); missileFired = true; @@ -380,7 +381,7 @@ function deleteIfInvader(possibleInvaderEntity) { Entities.deleteEntity(myMissile); // play the hit sound - var options = new AudioInjectionOptions(); + var options = {}; if (soundInMyHead) { options.position = { x: MyAvatar.position.x + 0.0, y: MyAvatar.position.y + 0.1, @@ -388,7 +389,7 @@ function deleteIfInvader(possibleInvaderEntity) { } else { options.position = getInvaderPosition(row, column); } - options.volume = 1.0; + Audio.playSound(hitSound, options); } } diff --git a/examples/toyball.js b/examples/toyball.js index b41dd2bda5..1cd6de16eb 100644 --- a/examples/toyball.js +++ b/examples/toyball.js @@ -113,10 +113,7 @@ function checkControllerSide(whichSide) { inHand: true }; Entities.editEntity(closestEntity, properties); - var options = new AudioInjectionOptions(); - options.position = ballPosition; - options.volume = 1.0; - Audio.playSound(catchSound, options); + Audio.playSound(catchSound, { position: ballPosition }); return; // exit early } @@ -156,10 +153,7 @@ function checkControllerSide(whichSide) { } // Play a new ball sound - var options = new AudioInjectionOptions(); - options.position = ballPosition; - options.volume = 1.0; - Audio.playSound(newSound, options); + Audio.playSound(newSound, { position: ballPosition}); return; // exit early } @@ -207,10 +201,7 @@ function checkControllerSide(whichSide) { rightHandEntity = false; } - var options = new AudioInjectionOptions(); - options.position = ballPosition; - options.volume = 1.0; - Audio.playSound(throwSound, options); + Audio.playSound(throwSound, { position: ballPosition }); } } } diff --git a/examples/walk.js b/examples/walk.js index a9e8f401d6..ac0a2b1d39 100644 --- a/examples/walk.js +++ b/examples/walk.js @@ -285,9 +285,11 @@ function resetJoints() { // play footstep sound function playFootstep(side) { - var options = new AudioInjectionOptions(); - options.position = Camera.getPosition(); - options.volume = 0.5; + var options = { + position: Camera.getPosition(), + volume: 0.5 + } + var walkNumber = 2; // 0 to 2 if(side===DIRECTION_RIGHT && playFootStepSounds) { Audio.playSound(footsteps[walkNumber+1], options);