diff --git a/examples/lobby.js b/examples/lobby.js index 9b4a81c7cd..3e74cb0136 100644 --- a/examples/lobby.js +++ b/examples/lobby.js @@ -46,8 +46,6 @@ var latinSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.st var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.stereo.raw") var currentMusak = null; -var firstMusakPlay = true; - function reticlePosition() { var RETICLE_DISTANCE = 1; return Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), RETICLE_DISTANCE)); @@ -138,15 +136,9 @@ function playRandomMusak() { chosenSound = elevatorSound; } - if (chosenSound) { - if (firstMusakPlay) { - // pick a random number of seconds from 0-10 to offset the muzak - var secondOffset = Math.random() * 10; - firstMusakPlay = false; - } else { - var secondOffset = 0.0; - } - + if (chosenSound) { + // pick a random number of seconds from 0-10 to offset the muzak + var secondOffset = Math.random() * 10; currentMusak = Audio.playSound(chosenSound, { localOnly: true, secondOffset: secondOffset, volume: 0.5 }) } else { currentMusak = null; diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 1775099e8a..d5f82bbdd4 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -78,6 +78,19 @@ float AudioInjector::getLoudness() { } void AudioInjector::injectAudio() { + + // check if we need to offset the sound by some number of seconds + if (_options.secondOffset > 0.0f) { + + // convert the offset into a number of bytes + int byteOffset = (int) floorf(SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f)); + byteOffset *= sizeof(int16_t); + + qDebug() << "Changing current send position to" << byteOffset; + + _currentSendPosition = byteOffset; + } + if (_options.localOnly) { injectLocally(); } else { @@ -94,19 +107,8 @@ void AudioInjector::injectLocally() { _localBuffer->open(QIODevice::ReadOnly); _localBuffer->setShouldLoop(_options.loop); - // check if we need to offset the sound by some number of seconds - if (_options.secondOffset > 0.0f) { - - qDebug() << "injector wants a sound offset of" << _options.secondOffset; - // convert the offset into a number of bytes - int byteOffset = (int) floorf(SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f)); - byteOffset *= sizeof(int16_t); - - qDebug() << "that gives us" << byteOffset << "bytes"; - - // give that byte offset to our local buffer - _localBuffer->setCurrentOffset(byteOffset); - } + // give our current send position to the local buffer + _localBuffer->setCurrentOffset(_currentSendPosition); QMetaObject::invokeMethod(_localAudioInterface, "outputLocalInjector", Qt::BlockingQueuedConnection,