overte/examples/audioExamples/injectorLoadTest.js

90 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-02-18 11:50:26 -08:00
//
// injectorLoadTest.js
// audio
//
// Created by Eric Levin 2/1/2016
// Copyright 2016 High Fidelity, Inc.
// This script tests what happens when many audio injectors are created and played
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
Script.include("../libraries/utils.js");
2016-02-18 12:14:30 -08:00
2016-02-18 16:17:22 -08:00
var numSoundsToPlayPerBatch = 50
2016-02-18 15:39:38 -08:00
var numSoundsPlaying = 0;
2016-02-18 16:17:22 -08:00
var timeBetweenBatch = 30000;
2016-02-18 11:50:26 -08:00
// A green box represents an injector that is playing
var basePosition = {
x: 0,
y: 0,
z: 0
};
var soundBoxes = [];
var testSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove.wav");
2016-02-18 12:14:30 -08:00
var totalInjectors = 0;
2016-02-18 11:50:26 -08:00
2016-02-18 12:00:24 -08:00
if(!testSound.downloaded) {
2016-02-18 12:02:22 -08:00
print("SOUND IS NOT READY YET")
2016-02-18 12:00:24 -08:00
testSound.ready.connect(function() {
playSounds();
});
} else {
// otherwise play sounds right away
playSounds();
2016-02-18 11:50:26 -08:00
}
2016-02-18 12:00:24 -08:00
function playSounds() {
2016-02-18 12:02:22 -08:00
print("PLAY SOUNDS!")
2016-02-18 12:14:30 -08:00
for (var i = 0; i < numSoundsToPlayPerBatch; i++) {
2016-02-18 12:00:24 -08:00
playSound();
2016-02-18 12:14:30 -08:00
}
2016-02-18 16:06:53 -08:00
Script.setTimeout(function() {
numSoundsPlaying = 0;
}, 1500);
2016-02-18 12:14:30 -08:00
print("EBL Total Number of Injectors: " + totalInjectors);
Script.setTimeout(function() {
playSounds();
}, timeBetweenBatch);
2016-02-18 12:00:24 -08:00
}
2016-02-18 11:50:26 -08:00
function playSound() {
var position = Vec3.sum(basePosition, {x: randFloat(-.1, .1), y: randFloat(-1, 1), z: randFloat(-3, -.1)});
var injector = Audio.playSound(testSound, {
position: position,
2016-02-18 16:06:53 -08:00
volume: 0.2
2016-02-18 11:50:26 -08:00
});
2016-02-18 15:39:38 -08:00
2016-02-18 16:06:53 -08:00
numSoundsPlaying++;
print("NUM SOUNDS PLAYING: " + numSoundsPlaying);
print("*******************************************");
2016-02-18 16:17:22 -08:00
print("INJECTOR VALUE: ")
print(JSON.stringify(injector));
2016-02-18 12:14:30 -08:00
totalInjectors++;
2016-02-18 11:50:26 -08:00
var soundBox = Entities.addEntity({
type: "Box",
color: {red: 200, green: 10, blue: 200},
dimensions: {x: 0.1, y: 0.1, z: 0.1},
position: position
});
soundBoxes.push(soundBox);
}
function cleanup() {
soundBoxes.forEach( function(soundBox) {
Entities.deleteEntity(soundBox);
});
}
Script.scriptEnding.connect(cleanup);