mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 20:54:25 +02:00
handle offset passed in AudioInjectorOptions for mixer injections
This commit is contained in:
parent
81c5f9ba5a
commit
45450c4fe3
2 changed files with 18 additions and 24 deletions
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue