From 771e5a4f9de7ab08bb5308b7b43d9528d5e00b58 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 20 Oct 2015 11:21:09 -0700 Subject: [PATCH] add toybox ac scripts, write headers for them, organize --- examples/toys/AC_scripts/arcade_game_sound.js | 52 +++++++++++++++++++ examples/toys/AC_scripts/cat_purr_sound.js | 41 +++++++++++++++ .../toys/AC_scripts/dogs_barking_sound.js | 52 +++++++++++++++++++ examples/toys/AC_scripts/fireplace_sound.js | 38 ++++++++++++++ .../AC_scripts}/flickeringLight.js | 0 examples/toys/AC_scripts/insects_sound.js | 39 ++++++++++++++ examples/toys/AC_scripts/river_water_sound.js | 37 +++++++++++++ examples/toys/AC_scripts/windmill_sound.js | 38 ++++++++++++++ 8 files changed, 297 insertions(+) create mode 100644 examples/toys/AC_scripts/arcade_game_sound.js create mode 100644 examples/toys/AC_scripts/cat_purr_sound.js create mode 100644 examples/toys/AC_scripts/dogs_barking_sound.js create mode 100644 examples/toys/AC_scripts/fireplace_sound.js rename examples/{acScripts => toys/AC_scripts}/flickeringLight.js (100%) create mode 100644 examples/toys/AC_scripts/insects_sound.js create mode 100644 examples/toys/AC_scripts/river_water_sound.js create mode 100644 examples/toys/AC_scripts/windmill_sound.js diff --git a/examples/toys/AC_scripts/arcade_game_sound.js b/examples/toys/AC_scripts/arcade_game_sound.js new file mode 100644 index 0000000000..0f158aa574 --- /dev/null +++ b/examples/toys/AC_scripts/arcade_game_sound.js @@ -0,0 +1,52 @@ +// Adds arcade game noises to Toybox. +// By Ryan Karpf 10/20/2015 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var SOUND_URL = "http://hifi-public.s3.amazonaws.com/ryan/ARCADE_GAMES_VID.L.L.wav"; +var SOUND_POSITION = { x: 543.77, y: 495.07, z: 502.25 }; + +var MINUTE = 60 * 1000; +var PLAY_SOUND_INTERVAL = 1.5 * MINUTE; + +var audioOptions = { + position: SOUND_POSITION, + volume: .01, + loop: false, +}; + +var sound = SoundCache.getSound(SOUND_URL); +var injector = null; + +function playSound() { + print("Playing sound"); + if (injector) { + // try/catch in case the injector QObject has been deleted already + try { + injector.stop(); + } catch (e) { + } + } + injector = Audio.playSound(sound, audioOptions); +} + +function checkDownloaded() { + if (sound.downloaded) { + print("Sound downloaded."); + Script.clearInterval(checkDownloadedTimer); + Script.setInterval(playSound, PLAY_SOUND_INTERVAL); + playSound(); + } +} + +// Check once a second to see if the audio file has been downloaded +var checkDownloadedTimer = Script.setInterval(checkDownloaded, 1000); + +Script.scriptEnding.connect(function() { + if (injector) { + injector.stop(); + } +}); \ No newline at end of file diff --git a/examples/toys/AC_scripts/cat_purr_sound.js b/examples/toys/AC_scripts/cat_purr_sound.js new file mode 100644 index 0000000000..c02b14ebf8 --- /dev/null +++ b/examples/toys/AC_scripts/cat_purr_sound.js @@ -0,0 +1,41 @@ +// +// ambiance.js +// examples +// +// Created by Clément Brisset on 11/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var soundURL = "http://hifi-public.s3.amazonaws.com/ryan/Cat_Purring_Deep_Low_Snor.wav"; +var position = { x: 551.48, y: 495.60, z: 502.08}; +var audioOptions = { + position: position, + volume: .03, + loop: true +}; + +var sound = SoundCache.getSound(soundURL); +var injector = null; +var count = 300; + +Script.update.connect(function() { + if (count > 0) { + count--; + return; + } + + if (sound.downloaded && injector === null) { + print("Sound downloaded."); + injector = Audio.playSound(sound, audioOptions); + print("Playing: " + injector); + } +}); + +Script.scriptEnding.connect(function() { + if (injector !== null) { + injector.stop(); + } +}); \ No newline at end of file diff --git a/examples/toys/AC_scripts/dogs_barking_sound.js b/examples/toys/AC_scripts/dogs_barking_sound.js new file mode 100644 index 0000000000..c362e1ac76 --- /dev/null +++ b/examples/toys/AC_scripts/dogs_barking_sound.js @@ -0,0 +1,52 @@ +// Adds a dogs barking noise to Toybox. +// By Ryan Karpf 10/20/2015 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var SOUND_URL = "http://hifi-public.s3.amazonaws.com/ryan/dogs_barking_1.L.wav"; +var SOUND_POSITION = { x: 523, y: 495, z: 469 }; + +var MINUTE = 60 * 1000; +var PLAY_SOUND_INTERVAL = 1 * MINUTE; + +var audioOptions = { + position: SOUND_POSITION, + volume: .05, + loop: false, +}; + +var sound = SoundCache.getSound(SOUND_URL); +var injector = null; + +function playSound() { + print("Playing sound"); + if (injector) { + // try/catch in case the injector QObject has been deleted already + try { + injector.stop(); + } catch (e) { + } + } + injector = Audio.playSound(sound, audioOptions); +} + +function checkDownloaded() { + if (sound.downloaded) { + print("Sound downloaded."); + Script.clearInterval(checkDownloadedTimer); + Script.setInterval(playSound, PLAY_SOUND_INTERVAL); + playSound(); + } +} + +// Check once a second to see if the audio file has been downloaded +var checkDownloadedTimer = Script.setInterval(checkDownloaded, 1000); + +Script.scriptEnding.connect(function() { + if (injector) { + injector.stop(); + } +}); \ No newline at end of file diff --git a/examples/toys/AC_scripts/fireplace_sound.js b/examples/toys/AC_scripts/fireplace_sound.js new file mode 100644 index 0000000000..76a7153c4b --- /dev/null +++ b/examples/toys/AC_scripts/fireplace_sound.js @@ -0,0 +1,38 @@ +// Adds a fireplace noise to Toybox. +// By Ryan Karpf 10/20/2015 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var soundURL = "http://hifi-public.s3.amazonaws.com/ryan/demo/0619_Fireplace__Tree_B.L.wav"; +var position = { x: 551.61, y: 494.88, z: 502.00}; +var audioOptions = { + position: position, + volume: .08, + loop: true +}; + +var sound = SoundCache.getSound(soundURL); +var injector = null; +var count = 300; + +Script.update.connect(function() { + if (count > 0) { + count--; + return; + } + + if (sound.downloaded && injector === null) { + print("Sound downloaded."); + injector = Audio.playSound(sound, audioOptions); + print("Playing: " + injector); + } +}); + +Script.scriptEnding.connect(function() { + if (injector !== null) { + injector.stop(); + } +}); \ No newline at end of file diff --git a/examples/acScripts/flickeringLight.js b/examples/toys/AC_scripts/flickeringLight.js similarity index 100% rename from examples/acScripts/flickeringLight.js rename to examples/toys/AC_scripts/flickeringLight.js diff --git a/examples/toys/AC_scripts/insects_sound.js b/examples/toys/AC_scripts/insects_sound.js new file mode 100644 index 0000000000..1783413901 --- /dev/null +++ b/examples/toys/AC_scripts/insects_sound.js @@ -0,0 +1,39 @@ +// Adds an insect noise to Toybox. +// By Ryan Karpf 10/20/2015 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + + +var soundURL = "http://hifi-public.s3.amazonaws.com/ryan/insects3.wav"; +var position = { x: 560, y: 495, z: 474}; +var audioOptions = { + position: position, + volume: .25, + loop: true +}; + +var sound = SoundCache.getSound(soundURL); +var injector = null; +var count = 300; + +Script.update.connect(function() { + if (count > 0) { + count--; + return; + } + + if (sound.downloaded && injector === null) { + print("Sound downloaded."); + injector = Audio.playSound(sound, audioOptions); + print("Playing: " + injector); + } +}); + +Script.scriptEnding.connect(function() { + if (injector !== null) { + injector.stop(); + } +}); \ No newline at end of file diff --git a/examples/toys/AC_scripts/river_water_sound.js b/examples/toys/AC_scripts/river_water_sound.js new file mode 100644 index 0000000000..30df67b515 --- /dev/null +++ b/examples/toys/AC_scripts/river_water_sound.js @@ -0,0 +1,37 @@ +// Adds a river water sound to Toybox. +// By Ryan Karpf 10/20/2015 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var soundURL = "http://hifi-public.s3.amazonaws.com/ryan/Water_Lap_River_Edge_Gentle.L.wav"; +var position = { x: 580, y: 493, z: 528}; +var audioOptions = { + position: position, + volume: .4, + loop: true +}; + +var sound = SoundCache.getSound(soundURL); +var injector = null; +var count = 300; + +Script.update.connect(function() { + if (count > 0) { + count--; + return; + } + + if (sound.downloaded && injector === null) { + print("Sound downloaded."); + injector = Audio.playSound(sound, audioOptions); + print("Playing: " + injector); + } +}); + +Script.scriptEnding.connect(function() { + if (injector !== null) { + injector.stop(); + } +}); \ No newline at end of file diff --git a/examples/toys/AC_scripts/windmill_sound.js b/examples/toys/AC_scripts/windmill_sound.js new file mode 100644 index 0000000000..2072dbb9dd --- /dev/null +++ b/examples/toys/AC_scripts/windmill_sound.js @@ -0,0 +1,38 @@ +// Adds a windmill noise to toybox. +// By Ryan Karpf 10/20/2015 +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var soundURL = "http://hifi-public.s3.amazonaws.com/ryan/WINDMILL_Mono.wav"; +var position = { x: 530, y: 516, z: 518}; +var audioOptions = { + position: position, + volume: .08, + loop: true +}; + +var sound = SoundCache.getSound(soundURL); +var injector = null; +var count = 300; + +Script.update.connect(function() { + if (count > 0) { + count--; + return; + } + + if (sound.downloaded && injector === null) { + print("Sound downloaded."); + injector = Audio.playSound(sound, audioOptions); + print("Playing: " + injector); + } +}); + +Script.scriptEnding.connect(function() { + if (injector !== null) { + injector.stop(); + } +}); \ No newline at end of file