diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index e86ecda36e..f5bed48a86 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -370,50 +370,6 @@ void AudioMixer::run() { _maxSourceLoudnessInFrame); } } - - const float STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.10; - const float BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.30; - const float CUTOFF_EPSILON = 0.0001; - - const int TRAILING_AVERAGE_FRAMES = 100; - const float CURRENT_FRAME_RATIO = 1.0f / TRAILING_AVERAGE_FRAMES; - const float PREVIOUS_FRAMES_RATIO = 1 - CURRENT_FRAME_RATIO; - - if (usecToSleep < 0) { - usecToSleep = 0; - } - - _trailingSleepRatio = (PREVIOUS_FRAMES_RATIO * _trailingSleepRatio) - + (usecToSleep * CURRENT_FRAME_RATIO / (float) BUFFER_SEND_INTERVAL_USECS); - - float lastCutoffRatio = _loudnessCutoffRatio; - bool hasRatioChanged = false; - - if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) { - // we're struggling - change our min required loudness to reduce some load - _loudnessCutoffRatio += (1 - _loudnessCutoffRatio) / 2; - - qDebug() << "Mixer is struggling, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was" - << lastCutoffRatio << "and is now" << _loudnessCutoffRatio; - hasRatioChanged = true; - } else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && _loudnessCutoffRatio != 0) { - // we've recovered and can back off the required loudness - _loudnessCutoffRatio -= _loudnessCutoffRatio / 2; - - if (_loudnessCutoffRatio < CUTOFF_EPSILON) { - _loudnessCutoffRatio = 0; - } - - qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was" - << lastCutoffRatio << "and is now" << _loudnessCutoffRatio; - hasRatioChanged = true; - } - - if (hasRatioChanged) { - // set out min required loudness from the new ratio - _minRequiredLoudness = _loudnessCutoffRatio * (_maxSourceLoudnessInFrame - _minSourceLoudnessInFrame); - qDebug() << "Minimum loudness required to be mixed is now" << _minRequiredLoudness; - } foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { if (node->getType() == NodeType::Agent && node->getActiveSocket() && node->getLinkedData() diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 41fd72e54e..f370a1509f 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -96,16 +96,7 @@ void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSam // calculate the average loudness for the next NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL // that would be mixed in _ringBuffers[i]->updateAverageLoudnessForBoundarySamples(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL); - - float ringBufferLoudness = _ringBuffers[i]->getAverageLoudness(); - - if (ringBufferLoudness != 0 && ringBufferLoudness < currentMinLoudness) { - currentMinLoudness = ringBufferLoudness; - } - - if (ringBufferLoudness > currentMaxLoudness) { - currentMaxLoudness = ringBufferLoudness; - } + } } } diff --git a/examples/bot.js b/examples/bot.js index ebc8c4d5aa..ea78f40de9 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -26,15 +26,25 @@ var CHANCE_OF_MOVING = 0.005; var CHANCE_OF_SOUND = 0.005; var CHANCE_OF_HEAD_TURNING = 0.05; var CHANCE_OF_BIG_MOVE = 0.1; +var CHANCE_OF_WAVING = 0.005; // Currently this isn't working + +var shouldReceiveVoxels = true; +var VOXEL_FPS = 60.0; +var lastVoxelQueryTime = 0.0; var isMoving = false; var isTurningHead = false; +var isPlayingAudio = false; +var isWaving = false; +var waveFrequency = 0.0; +var waveAmplitude = 0.0; var X_MIN = 0.0; var X_MAX = 5.0; var Z_MIN = 0.0; var Z_MAX = 5.0; var Y_PELVIS = 2.5; +var SHOULDER_JOINT_NUMBER = 15; var MOVE_RANGE_SMALL = 0.5; var MOVE_RANGE_BIG = Math.max(X_MAX - X_MIN, Z_MAX - Z_MIN) / 2.0; @@ -51,6 +61,8 @@ var targetDirection = { x: 0, y: 0, z: 0, w: 0 }; var currentDirection = { x: 0, y: 0, z: 0, w: 0 }; var targetHeadPitch = 0.0; +var cumulativeTime = 0.0; + var sounds = []; loadSounds(); @@ -100,13 +112,37 @@ Agent.isListeningToAudioStream = true; Avatar.position = firstPosition; printVector("New bot, position = ", Avatar.position); +function stopWaving() { + isWaving = false; + Avatar.clearJointData(SHOULDER_JOINT_NUMBER); +} + function updateBehavior(deltaTime) { - if (Math.random() < CHANCE_OF_SOUND) { - playRandomSound(); + + cumulativeTime += deltaTime; + + if (shouldReceiveVoxels && ((cumulativeTime - lastVoxelQueryTime) > (1.0 / VOXEL_FPS))) { + VoxelViewer.setPosition(Avatar.position); + VoxelViewer.setOrientation(Avatar.orientation); + VoxelViewer.queryOctree(); + lastVoxelQueryTime = cumulativeTime; + /* + if (Math.random() < (1.0 / VOXEL_FPS)) { + print("Voxels in view = " + VoxelViewer.getOctreeElementsCount()); + }*/ } - if (Agent.isPlayingAvatarSound) { - Avatar.handPosition = Vec3.sum(Avatar.position, Quat.getFront(Avatar.orientation)); + if (!isWaving && (Math.random() < CHANCE_OF_WAVING)) { + isWaving = true; + waveFrequency = 1.0 + Math.random() * 5.0; + waveAmplitude = 5.0 + Math.random() * 60.0; + Script.setTimeout(stopWaving, 1000 + Math.random() * 2000); + } else if (isWaving) { + Avatar.setJointData(SHOULDER_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, waveAmplitude * Math.sin(cumulativeTime * waveFrequency))); + } + + if (Math.random() < CHANCE_OF_SOUND) { + playRandomSound(); } if (!isTurningHead && (Math.random() < CHANCE_OF_HEAD_TURNING)) { diff --git a/examples/crazylegs.js b/examples/crazylegs.js index c098758a38..099387e000 100644 --- a/examples/crazylegs.js +++ b/examples/crazylegs.js @@ -12,6 +12,10 @@ var AMPLITUDE = 45.0; var cumulativeTime = 0.0; +print("Joint List:"); +var jointList = MyAvatar.getJointNames(); +print(jointList); + Script.update.connect(function(deltaTime) { cumulativeTime += deltaTime; MyAvatar.setJointData("joint_R_hip", Quat.fromPitchYawRollDegrees(0.0, 0.0, AMPLITUDE * Math.sin(cumulativeTime * FREQUENCY))); diff --git a/examples/editVoxels.js b/examples/editVoxels.js index 43bc485274..c46df7c3dc 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -33,7 +33,7 @@ var zFightingSizeAdjust = 0.002; // used to adjust preview voxels to prevent z f var previewLineWidth = 1.5; var oldMode = Camera.getMode(); - +var trackAsOrbitOrPan = false; var isAdding = false; var isExtruding = false; var extrudeDirection = { x: 0, y: 0, z: 0 }; @@ -792,7 +792,6 @@ function mousePressEvent(event) { if (!trackAsOrbitOrPan) { var clickedOnSomething = false; var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - // If the user clicked on the thumb, handle the slider logic if (clickedOverlay == thumb) { @@ -1113,7 +1112,6 @@ function mouseMoveEvent(event) { var dy = event.y - mouseY; if (Math.sqrt(dx*dx + dy*dy) > PIXELS_PER_EXTRUDE_VOXEL) { lastVoxelPosition = Vec3.sum(lastVoxelPosition, extrudeDirection); - Voxels.eraseVoxel(voxelDetails.x, voxelDetails.y, voxelDetails.z, voxelDetails.s); Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z, extrudeScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue); mouseX = event.x; diff --git a/examples/gun.js b/examples/gun.js index 29b60a94ad..94f3fd4ee3 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -12,6 +12,11 @@ // // + +function getRandomFloat(min, max) { + return Math.random() * (max - min) + min; +} + var lastX = 0; var lastY = 0; var yawFromMouse = 0; @@ -19,17 +24,22 @@ var pitchFromMouse = 0; var isMouseDown = false; var BULLET_VELOCITY = 5.0; +var MIN_THROWER_DELAY = 1000; +var MAX_THROWER_DELAY = 1000; var LEFT_BUTTON_3 = 3; // Load some sound to use for loading and firing var fireSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw"); var loadSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/Gun_Reload_Weapon22.raw"); var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/BulletImpact2.raw"); -var targetLaunchSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw"); +var targetHitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw"); +var targetLaunchSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw"); var audioOptions = new AudioInjectionOptions(); audioOptions.volume = 0.9; +var shotTime = new Date(); + // initialize our triggers var triggerPulled = new Array(); var numberOfTriggers = Controller.getNumberOfTriggers(); @@ -94,7 +104,9 @@ function shootTarget() { var DISTANCE_TO_LAUNCH_FROM = 3.0; var camera = Camera.getPosition(); //printVector("camera", camera); - var forwardVector = Quat.getFront(Camera.getOrientation()); + var targetDirection = Quat.angleAxis(getRandomFloat(-20.0, 20.0), { x:0, y:1, z:0 }); + targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection); + var forwardVector = Quat.getFront(targetDirection); //printVector("forwardVector", forwardVector); var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_TO_LAUNCH_FROM)); //printVector("newPosition", newPosition); @@ -111,6 +123,9 @@ function shootTarget() { lifetime: 1000.0, damping: 0.99 }); + // Record start time + shotTime = new Date(); + // Play target shoot sound audioOptions.position = newPosition; Audio.playSound(targetLaunchSound, audioOptions); @@ -119,31 +134,43 @@ function shootTarget() { function particleCollisionWithVoxel(particle, voxel, penetration) { - Vec3.print('particleCollisionWithVoxel() ... penetration=', penetration); - var HOLE_SIZE = 0.125; var particleProperties = Particles.getParticleProperties(particle); var position = particleProperties.position; Particles.deleteParticle(particle); // Make a hole in this voxel + Vec3.print("penetration", penetration); + Vec3.print("position", position); + var pointOfEntry = Vec3.subtract(position, penetration); + Vec3.print("pointOfEntry", pointOfEntry); + Voxels.eraseVoxel(pointOfEntry.x, pointOfEntry.y, pointOfEntry.z, HOLE_SIZE); Voxels.eraseVoxel(position.x, position.y, position.z, HOLE_SIZE); //audioOptions.position = position; audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); - Audio.playSound(impactSound, audioOptions); + Audio.playSound(targetHitSound, audioOptions); } function particleCollisionWithParticle(particle1, particle2) { - print("Particle/Particle!"); score++; Overlays.editOverlay(text, { text: "Score: " + score } ); + // Sort out which particle is which + + // Record shot time + var endTime = new Date(); + var msecs = endTime.valueOf() - shotTime.valueOf(); + print("hit, msecs = " + msecs); Particles.deleteParticle(particle1); Particles.deleteParticle(particle2); + audioOptions.position = newPosition; + audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); + Audio.playSound(targetHitSound, audioOptions); } function keyPressEvent(event) { // if our tools are off, then don't do anything if (event.text == "t") { - shootTarget(); + var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY; + Script.setTimeout(shootTarget, time); } } @@ -164,7 +191,8 @@ function update(deltaTime) { // Check hydra controller for launch button press if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) { isLaunchButtonPressed = true; - shootTarget(); + var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY; + Script.setTimeout(shootTarget, time); } else if (isLaunchButtonPressed && !Controller.isButtonPressed(LEFT_BUTTON_3)) { isLaunchButtonPressed = false; diff --git a/examples/voxelBird.js b/examples/voxelBird.js deleted file mode 100644 index 1e33851ff6..0000000000 --- a/examples/voxelBird.js +++ /dev/null @@ -1,133 +0,0 @@ -// -// This sample script moves a voxel around like a bird and sometimes makes tweeting noises -// - -function vLength(v) { - return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); -} - -function printVector(v) { - print(v.x + ", " + v.y + ", " + v.z + "\n"); -} - -// Create a random vector with individual lengths between a,b -function randVector(a, b) { - var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) }; - return rval; -} - -function vMinus(a, b) { - var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z }; - return rval; -} - -function vPlus(a, b) { - var rval = { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z }; - return rval; -} - -function vCopy(a, b) { - a.x = b.x; - a.y = b.y; - a.z = b.z; - return; -} - -// Returns a vector which is fraction of the way between a and b -function vInterpolate(a, b, fraction) { - var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction }; - return rval; -} - -// Decide what kind of bird we are -var tweet; - -var which = Math.random(); -if (which < 0.2) { - tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/bushtit_1.raw"); -} else if (which < 0.4) { - tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/rosyfacedlovebird.raw"); -} else if (which < 0.6) { - tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/saysphoebe.raw"); -} else if (which < 0.8) { - tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/mexicanWhipoorwill.raw"); -} else { - tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/westernscreechowl.raw"); -} - -var position = { x: 0, y: 0, z: 0 }; -var lastPosition = { x: 0, y: 0, z: 0 }; -var oldPosition = { x: 0, y: 0, z:0 }; -var targetPosition = { x: 0, y: 0, z: 0 }; - -var size = 0.125; -var range = 50.0; // Over what distance in meters do you want your bird to fly around -var color = { r: 100, g: 50, b: 150 }; -var colorEdge = { r:255, g:250, b:175 }; -var frame = 0; -var thisColor = color; -var moving = false; -var tweeting = 0; -var moved = true; - -var CHANCE_OF_MOVING = 0.05; -var CHANCE_OF_TWEETING = 0.05; - -function moveBird(deltaTime) { - frame++; - if (frame % 3 == 0) { - // Tweeting behavior - if (tweeting == 0) { - if (Math.random() < CHANCE_OF_TWEETING) { - //print("tweet!" + "\n"); - var options = new AudioInjectionOptions();
 - options.position = position; - options.volume = 0.75; - Audio.playSound(tweet, options); - tweeting = 10; - } - } else { - tweeting -= 1; - } - // Moving behavior - if (moving == false) { - if (Math.random() < CHANCE_OF_MOVING) { - targetPosition = randVector(0, range); - //printVector(position); - moving = true; - } - } - if (moving) { - position = vInterpolate(position, targetPosition, 0.5); - if (vLength(vMinus(position, targetPosition)) < (size / 2.0)) { - moved = false; - moving = false; - } else { - moved = true; - } - } - - if (tweeting > 0) { - // Change color of voxel to blinky red a bit while playing the sound - var blinkColor = { r: Math.random() * 255, g: 0, b: 0 }; - Voxels.setVoxel(position.x, - position.y, - position.z, - size, - blinkColor.r, blinkColor.g, blinkColor.b); - } - if (moved) { - Voxels.setVoxel(position.x, position.y, position.z, size, thisColor.r, thisColor.g, thisColor.b); - // delete old voxel - - Voxels.eraseVoxel(oldPosition.x, oldPosition.y, oldPosition.z, size); - // Copy old location to new - vCopy(oldPosition, position); - moved = false; - } - } -} - -Voxels.setPacketsPerSecond(10000); -// Connect a call back that happens every frame -Script.update.connect(moveBird); \ No newline at end of file diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 05998e6436..34e3614716 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -113,139 +113,22 @@ Menu - + Open .ini config file - - + + Text files (*.ini) - + Save .ini config file - - PreferencesDialog - - - - Avatar - - - - - - <html><head/><body><p>Avatar display name <span style=" color:#909090;">(optional)</span></p></body></html> - - - - - - Not showing a name - - - - - - Head - - - - - - Body - - - - - - Advanced Tuning - - - - - - It's not recomended that you play with these settings unless you've looked into exactly what they do. - - - - - - <p>Avatar</p> - - - - - - Lean scale (applies to Faceshift users) - - - - - - Vertical field of view - - - - - - Avatar scale (default is 1.0) - - - - - - Pupil dillation - - - - - - Audio Jitter Buffer Samples (0 for automatic) - - - - - - Faceshift eye detection - - - - - - <html><head/><body><p>Voxels</p></body></html> - - - - - - Maximum voxels - - - - - - Max voxels sent each second - - - - - - Cancel - - - - - - Save all changes - - - QObject diff --git a/interface/resources/visage/tracker.cfg b/interface/resources/visage/tracker.cfg index 10744da6e5..2efb7f3463 100644 --- a/interface/resources/visage/tracker.cfg +++ b/interface/resources/visage/tracker.cfg @@ -40,7 +40,7 @@ detect_strip_roi_width 2 detect_strip_roi_height 4 smoothing_factors - 150 5 -2 100 -1 50 50 0 + 5 25 -2 100 -1 50 25 0 #translation rotation action_units eyebrows mouth gaze eye_closure other process_eyes 1 diff --git a/libraries/audio/src/AudioRingBuffer.cpp b/libraries/audio/src/AudioRingBuffer.cpp index cf35b6a20f..800f4f64ee 100644 --- a/libraries/audio/src/AudioRingBuffer.cpp +++ b/libraries/audio/src/AudioRingBuffer.cpp @@ -66,12 +66,8 @@ void AudioRingBuffer::updateAverageLoudnessForBoundarySamples(int numSamples) { nextLoudness /= numSamples; nextLoudness /= MAX_SAMPLE_VALUE; - - const int TRAILING_AVERAGE_FRAMES = 100; - const float CURRENT_FRAME_RATIO = 1.0f / TRAILING_AVERAGE_FRAMES; - const float PREVIOUS_FRAMES_RATIO = 1 - CURRENT_FRAME_RATIO; - _averageLoudness = (_averageLoudness * PREVIOUS_FRAMES_RATIO) + (CURRENT_FRAME_RATIO * nextLoudness); + _averageLoudness = nextLoudness; } qint64 AudioRingBuffer::readSamples(int16_t* destination, qint64 maxSamples) { diff --git a/libraries/audio/src/PositionalAudioRingBuffer.cpp b/libraries/audio/src/PositionalAudioRingBuffer.cpp index ccbe5d3f23..8fb3d64e7d 100644 --- a/libraries/audio/src/PositionalAudioRingBuffer.cpp +++ b/libraries/audio/src/PositionalAudioRingBuffer.cpp @@ -80,13 +80,11 @@ int PositionalAudioRingBuffer::parsePositionalData(const QByteArray& positionalB bool PositionalAudioRingBuffer::shouldBeAddedToMix(int numJitterBufferSamples) { if (!isNotStarvedOrHasMinimumSamples(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL + numJitterBufferSamples)) { if (_shouldOutputStarveDebug) { - qDebug() << "Starved and do not have minimum samples to start. Buffer held back."; _shouldOutputStarveDebug = false; } return false; } else if (samplesAvailable() < NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { - qDebug() << "Do not have number of samples needed for interval. Buffer starved."; _isStarved = true; // reset our _shouldOutputStarveDebug to true so the next is printed diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index 0f938b80b0..78ebf4b921 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -11,9 +11,10 @@ #include #include -#include "AvatarData.h" +#include "AvatarData.h" #include "HandData.h" + HandData::HandData(AvatarData* owningAvatar) : _owningAvatarData(owningAvatar) { diff --git a/libraries/shared/src/ThreadedAssignment.cpp b/libraries/shared/src/ThreadedAssignment.cpp index c4282028ae..b3a54b1488 100644 --- a/libraries/shared/src/ThreadedAssignment.cpp +++ b/libraries/shared/src/ThreadedAssignment.cpp @@ -56,6 +56,7 @@ void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeTy void ThreadedAssignment::checkInWithDomainServerOrExit() { if (NodeList::getInstance()->getNumNoReplyDomainCheckIns() == MAX_SILENT_DOMAIN_SERVER_CHECK_INS) { + qDebug() << "NRDC:" << NodeList::getInstance()->getNumNoReplyDomainCheckIns(); setFinished(true); } else { NodeList::getInstance()->sendDomainServerCheckIn();