switch to next musak when finished

This commit is contained in:
Stephen Birarda 2014-11-19 14:52:57 -08:00
parent 45450c4fe3
commit 987b75d8f7
4 changed files with 49 additions and 18 deletions

View file

@ -44,7 +44,8 @@ var currentDrone = null;
var latinSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.stereo.raw")
var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.stereo.raw")
var currentMusak = null;
var currentMusakInjector = null;
var currentSound = null;
function reticlePosition() {
var RETICLE_DISTANCE = 1;
@ -125,23 +126,42 @@ function changeLobbyTextures() {
Overlays.editOverlay(panelWall, textureProp);
}
var MUSAK_VOLUME = 0.5;
function playNextMusak() {
if (panelWall) {
print("PLAYING THE NEXT MUSAK!");
if (currentSound == latinSound) {
if (elevatorSound.downloaded) {
currentSound = elevatorSound;
}
} else if (currentSound == elevatorSound) {
if (latinSound.downloaded) {
currentSound = latinSound;
}
}
currentMusakInjector = Audio.playSound(currentSound, { localOnly: true, volume: MUSAK_VOLUME });
}
}
function playRandomMusak() {
chosenSound = null;
currentSound = null;
if (latinSound.downloaded && elevatorSound.downloaded) {
chosenSound = Math.random < 0.5 ? latinSound : elevatorSound;
currentSound = Math.random() < 0.5 ? latinSound : elevatorSound;
} else if (latinSound.downloaded) {
chosenSound = latinSound;
currentSound = latinSound;
} else if (elevatorSound.downloaded) {
chosenSound = elevatorSound;
currentSound = elevatorSound;
}
if (chosenSound) {
// pick a random number of seconds from 0-10 to offset the muzak
if (currentSound) {
// pick a random number of seconds from 0-10 to offset the musak
var secondOffset = Math.random() * 10;
currentMusak = Audio.playSound(chosenSound, { localOnly: true, secondOffset: secondOffset, volume: 0.5 })
currentMusakInjector = Audio.playSound(currentSound, { localOnly: true, secondOffset: secondOffset, volume: MUSAK_VOLUME });
} else {
currentMusak = null;
currentMusakInjector = null;
}
}
@ -150,16 +170,16 @@ function cleanupLobby() {
Overlays.deleteOverlay(orbShell);
Overlays.deleteOverlay(reticle);
Audio.stopInjector(currentDrone);
currentDrone = null;
Audio.stopInjector(currentMusak);
currentMusak = null;
panelWall = false;
orbShell = false;
reticle = false;
Audio.stopInjector(currentDrone);
currentDrone = null;
Audio.stopInjector(currentMusakInjector);
currentMusakInjector = null;
locations = {};
toggleEnvironmentRendering(true);
@ -224,6 +244,11 @@ function update(deltaTime) {
Overlays.editOverlay(reticle, {
position: reticlePosition()
});
// if the reticle is up then we may need to play the next musak
if (!Audio.isInjectorPlaying(currentMusakInjector)) {
playNextMusak();
}
}
}

View file

@ -86,8 +86,6 @@ void AudioInjector::injectAudio() {
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;
}
@ -117,7 +115,8 @@ void AudioInjector::injectLocally() {
Q_ARG(qreal, _options.volume),
Q_ARG(AudioInjector*, this));
// if we're not looping and the buffer tells us it is empty then emit finished
connect(_localBuffer, &AudioInjectorLocalBuffer::bufferEmpty, this, &AudioInjector::stop);
if (!success) {
qDebug() << "AudioInjector::injectLocally could not output locally via _localAudioInterface";

View file

@ -47,6 +47,11 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
_currentOffset += bytesRead;
}
if (!_shouldLoop && bytesRead == bytesToEnd) {
// we hit the end of the buffer, emit a signal
emit bufferEmpty();
}
return bytesRead;
} else {
return 0;

View file

@ -27,6 +27,8 @@ public:
void setShouldLoop(bool shouldLoop) { _shouldLoop = shouldLoop; }
void setCurrentOffset(int currentOffset) { _currentOffset = currentOffset; }
signals:
void bufferEmpty();
private:
qint64 recursiveReadFromFront(char* data, qint64 maxSize);