mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 16:13:28 +02:00
Merge pull request #2954 from ctrlaltdavid/19715
Code Review for Job #19715
This commit is contained in:
commit
169e7d61fd
4 changed files with 55 additions and 0 deletions
43
examples/playSoundLoop.js
Normal file
43
examples/playSoundLoop.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// playSoundLoop.js
|
||||
// examples
|
||||
//
|
||||
// Created by David Rowe on 5/29/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This example script plays a sound in a continuous loop.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var sound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+A.raw");
|
||||
|
||||
var soundPlaying = false;
|
||||
|
||||
function keyPressEvent(event) {
|
||||
if (event.text === "1") {
|
||||
if (!Audio.isInjectorPlaying(soundPlaying)) {
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = MyAvatar.position;
|
||||
options.volume = 0.5;
|
||||
options.loop = true;
|
||||
soundPlaying = Audio.playSound(sound, options);
|
||||
print("Started sound loop");
|
||||
} else {
|
||||
Audio.stopInjector(soundPlaying);
|
||||
print("Stopped sound loop");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
if (Audio.isInjectorPlaying(soundPlaying)) {
|
||||
Audio.stopInjector(soundPlaying);
|
||||
print("Stopped sound loop");
|
||||
}
|
||||
}
|
||||
|
||||
// Connect a call back that happens every frame
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
|
@ -88,6 +88,7 @@ void AudioInjector::injectAudio() {
|
|||
int currentSendPosition = 0;
|
||||
|
||||
int numPreAudioDataBytes = injectAudioPacket.size();
|
||||
bool shouldLoop = _options.getLoop();
|
||||
|
||||
// loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks
|
||||
while (currentSendPosition < soundByteArray.size() && !_shouldStop) {
|
||||
|
@ -120,6 +121,10 @@ void AudioInjector::injectAudio() {
|
|||
usleep(usecToSleep);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldLoop && currentSendPosition == soundByteArray.size()) {
|
||||
currentSendPosition = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
|||
QObject(parent),
|
||||
_position(0.0f, 0.0f, 0.0f),
|
||||
_volume(1.0f),
|
||||
_loop(false),
|
||||
_orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
_loopbackAudioInterface(NULL)
|
||||
{
|
||||
|
@ -24,6 +25,7 @@ AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
|||
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
|
||||
_position = other._position;
|
||||
_volume = other._volume;
|
||||
_loop = other._loop;
|
||||
_orientation = other._orientation;
|
||||
_loopbackAudioInterface = other._loopbackAudioInterface;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class AudioInjectorOptions : public QObject {
|
|||
|
||||
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||
Q_PROPERTY(float volume READ getVolume WRITE setVolume)
|
||||
Q_PROPERTY(bool loop READ getLoop WRITE setLoop)
|
||||
public:
|
||||
AudioInjectorOptions(QObject* parent = 0);
|
||||
AudioInjectorOptions(const AudioInjectorOptions& other);
|
||||
|
@ -36,6 +37,9 @@ public:
|
|||
float getVolume() const { return _volume; }
|
||||
void setVolume(float volume) { _volume = volume; }
|
||||
|
||||
float getLoop() const { return _loop; }
|
||||
void setLoop(float loop) { _loop = loop; }
|
||||
|
||||
const glm::quat& getOrientation() const { return _orientation; }
|
||||
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
|
||||
|
||||
|
@ -45,6 +49,7 @@ public:
|
|||
private:
|
||||
glm::vec3 _position;
|
||||
float _volume;
|
||||
bool _loop;
|
||||
glm::quat _orientation;
|
||||
AbstractAudioInterface* _loopbackAudioInterface;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue