From fd6b9c3550676af1a00dfdccf68ce1ab02961842 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 10:16:42 -0800 Subject: [PATCH 1/7] changes to sound class to allow caching of sounds --- libraries/audio/src/AudioInjector.cpp | 41 +++++++------ libraries/audio/src/AudioInjector.h | 3 +- libraries/audio/src/Sound.cpp | 85 ++------------------------- libraries/audio/src/Sound.h | 24 +++----- libraries/audio/src/SoundCache.cpp | 33 +++++++++++ libraries/audio/src/SoundCache.h | 37 ++++++++++++ libraries/avatars/src/Recording.cpp | 24 ++------ libraries/avatars/src/Recording.h | 9 +-- 8 files changed, 114 insertions(+), 142 deletions(-) create mode 100644 libraries/audio/src/SoundCache.cpp create mode 100644 libraries/audio/src/SoundCache.h diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 1743504883..1c9c93c00e 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -31,7 +31,6 @@ void injectorFromScriptValue(const QScriptValue& object, AudioInjector*& out) { AudioInjector::AudioInjector(QObject* parent) : QObject(parent), - _sound(NULL), _options(), _shouldStop(false), _loudness(0.0f), @@ -42,7 +41,7 @@ AudioInjector::AudioInjector(QObject* parent) : } AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) : - _sound(sound), + _audioData(sound->getByteArray()), _options(injectorOptions), _shouldStop(false), _loudness(0.0f), @@ -52,6 +51,18 @@ AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorO { } +AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions) : + _audioData(audioData), + _options(injectorOptions), + _shouldStop(false), + _loudness(0.0f), + _isFinished(false), + _currentSendPosition(0), + _localBuffer(NULL) +{ + +} + AudioInjector::~AudioInjector() { if (_localBuffer) { _localBuffer->stop(); @@ -76,11 +87,9 @@ void AudioInjector::injectAudio() { void AudioInjector::injectLocally() { bool success = false; - if (_localAudioInterface) { - const QByteArray& soundByteArray = _sound->getByteArray(); - - if (soundByteArray.size() > 0) { - _localBuffer = new AudioInjectorLocalBuffer(_sound->getByteArray(), this); + if (_localAudioInterface) { + if (_audioData.size() > 0) { + _localBuffer = new AudioInjectorLocalBuffer(_audioData, this); _localBuffer->open(QIODevice::ReadOnly); _localBuffer->setShouldLoop(_options.loop); @@ -114,15 +123,13 @@ void AudioInjector::injectLocally() { const uchar MAX_INJECTOR_VOLUME = 0xFF; void AudioInjector::injectToMixer() { - QByteArray soundByteArray = _sound->getByteArray(); - if (_currentSendPosition < 0 || - _currentSendPosition >= soundByteArray.size()) { + _currentSendPosition >= _audioData.size()) { _currentSendPosition = 0; } // make sure we actually have samples downloaded to inject - if (soundByteArray.size()) { + if (_audioData.size()) { // setup the packet for injected audio QByteArray injectAudioPacket = byteArrayWithPopulatedHeader(PacketTypeInjectAudio); @@ -172,15 +179,15 @@ void AudioInjector::injectToMixer() { // loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks quint16 outgoingInjectedAudioSequenceNumber = 0; - while (_currentSendPosition < soundByteArray.size() && !_shouldStop) { + while (_currentSendPosition < _audioData.size() && !_shouldStop) { int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL, - soundByteArray.size() - _currentSendPosition); + _audioData.size() - _currentSendPosition); // Measure the loudness of this frame _loudness = 0.0f; for (int i = 0; i < bytesToCopy; i += sizeof(int16_t)) { - _loudness += abs(*reinterpret_cast(soundByteArray.data() + _currentSendPosition + i)) / + _loudness += abs(*reinterpret_cast(_audioData.data() + _currentSendPosition + i)) / (MAX_SAMPLE_VALUE / 2.0f); } _loudness /= (float)(bytesToCopy / sizeof(int16_t)); @@ -203,7 +210,7 @@ void AudioInjector::injectToMixer() { // copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet memcpy(injectAudioPacket.data() + numPreAudioDataBytes, - soundByteArray.data() + _currentSendPosition, bytesToCopy); + _audioData.data() + _currentSendPosition, bytesToCopy); // grab our audio mixer from the NodeList, if it exists NodeList* nodeList = NodeList::getInstance(); @@ -217,7 +224,7 @@ void AudioInjector::injectToMixer() { // send two packets before the first sleep so the mixer can start playback right away - if (_currentSendPosition != bytesToCopy && _currentSendPosition < soundByteArray.size()) { + if (_currentSendPosition != bytesToCopy && _currentSendPosition < _audioData.size()) { // not the first packet and not done // sleep for the appropriate time int usecToSleep = (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - timer.nsecsElapsed() / 1000; @@ -227,7 +234,7 @@ void AudioInjector::injectToMixer() { } } - if (shouldLoop && _currentSendPosition >= soundByteArray.size()) { + if (shouldLoop && _currentSendPosition >= _audioData.size()) { _currentSendPosition = 0; } } diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index 13188c5977..257b538c11 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -29,6 +29,7 @@ class AudioInjector : public QObject { public: AudioInjector(QObject* parent); AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions); + AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions); ~AudioInjector(); bool isFinished() const { return _isFinished; } @@ -51,7 +52,7 @@ private: void injectToMixer(); void injectLocally(); - Sound* _sound; + QByteArray _audioData; AudioInjectorOptions _options; bool _shouldStop; float _loudness; diff --git a/libraries/audio/src/Sound.cpp b/libraries/audio/src/Sound.cpp index 4c520f27ce..8f858e6d3c 100644 --- a/libraries/audio/src/Sound.cpp +++ b/libraries/audio/src/Sound.cpp @@ -38,87 +38,17 @@ void soundFromScriptValue(const QScriptValue& object, Sound*& out) { out = qobject_cast(object.toQObject()); } -// procedural audio version of Sound -Sound::Sound(float volume, float frequency, float duration, float decay, QObject* parent) : - QObject(parent), - _isStereo(false) +Sound::Sound(const QUrl& url, bool isStereo) : + Resource(url), + _isStereo(isStereo) { - static char monoAudioData[MAX_PACKET_SIZE]; - static int16_t* monoAudioSamples = (int16_t*)(monoAudioData); - - float t; - const float AUDIO_CALLBACK_MSECS = (float) NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL / (float)SAMPLE_RATE * 1000.0; - const float MAX_VOLUME = 32000.f; - const float MAX_DURATION = 2.f; - const float MIN_AUDIBLE_VOLUME = 0.001f; - const float NOISE_MAGNITUDE = 0.02f; - const int MAX_SAMPLE_VALUE = std::numeric_limits::max(); - const int MIN_SAMPLE_VALUE = std::numeric_limits::min(); - int numSamples = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; // we add sounds in chunks of this many samples - int chunkStartingSample = 0; - float waveFrequency = (frequency / SAMPLE_RATE) * TWO_PI; - while (volume > 0.f) { - for (int i = 0; i < numSamples; i++) { - t = (float)chunkStartingSample + (float)i; - float sample = sinf(t * waveFrequency); - sample += ((randFloat() - 0.5f) * NOISE_MAGNITUDE); - sample *= volume * MAX_VOLUME; - - monoAudioSamples[i] = glm::clamp((int)sample, MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE); - volume *= (1.f - decay); - } - // add the monoAudioSamples to our actual output Byte Array - _byteArray.append(monoAudioData, numSamples * sizeof(int16_t)); - chunkStartingSample += numSamples; - duration = glm::clamp(duration - (AUDIO_CALLBACK_MSECS / 1000.f), 0.f, MAX_DURATION); - //qDebug() << "decaying... _duration=" << _duration; - if (duration == 0.f || (volume < MIN_AUDIBLE_VOLUME)) { - volume = 0.f; - } - } } -Sound::Sound(const QUrl& sampleURL, bool isStereo, QObject* parent) : - QObject(parent), - _isStereo(isStereo), - _hasDownloaded(false) -{ - // assume we have a QApplication or QCoreApplication instance and use the - // QNetworkAccess manager to grab the raw audio file at the given URL - - QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); - - qDebug() << "Requesting audio file" << sampleURL.toDisplayString(); - - QNetworkReply* soundDownload = networkAccessManager.get(QNetworkRequest(sampleURL)); - connect(soundDownload, &QNetworkReply::finished, this, &Sound::replyFinished); - connect(soundDownload, SIGNAL(error(QNetworkReply::NetworkError)), - this, SLOT(replyError(QNetworkReply::NetworkError))); -} - -Sound::Sound(const QByteArray byteArray, QObject* parent) : - QObject(parent), - _byteArray(byteArray), - _isStereo(false), - _hasDownloaded(true) -{ -} - -void Sound::append(const QByteArray byteArray) { - _byteArray.append(byteArray); -} - -void Sound::replyFinished() { - - QNetworkReply* reply = reinterpret_cast(sender()); - +void Sound::downloadFinished(QNetworkReply* reply) { // replace our byte array with the downloaded data QByteArray rawAudioByteArray = reply->readAll(); - // foreach(QByteArray b, reply->rawHeaderList()) - // qDebug() << b.constData() << ": " << reply->rawHeader(b).constData(); - if (reply->hasRawHeader("Content-Type")) { QByteArray headerContentType = reply->rawHeader("Content-Type"); @@ -140,13 +70,6 @@ void Sound::replyFinished() { } else { qDebug() << "Network reply without 'Content-Type'."; } - - _hasDownloaded = true; -} - -void Sound::replyError(QNetworkReply::NetworkError code) { - QNetworkReply* reply = reinterpret_cast(sender()); - qDebug() << "Error downloading sound file at" << reply->url().toString() << "-" << reply->errorString(); } void Sound::downSample(const QByteArray& rawAudioByteArray) { diff --git a/libraries/audio/src/Sound.h b/libraries/audio/src/Sound.h index f7b51891f0..2880781ac6 100644 --- a/libraries/audio/src/Sound.h +++ b/libraries/audio/src/Sound.h @@ -16,38 +16,28 @@ #include #include -class Sound : public QObject { +#include + +class Sound : public Resource { Q_OBJECT - Q_PROPERTY(bool downloaded READ hasDownloaded) + Q_PROPERTY(bool downloaded READ isLoaded) public: - Sound(const QUrl& sampleURL, bool isStereo = false, QObject* parent = NULL); - Sound(float volume, float frequency, float duration, float decay, QObject* parent = NULL); - Sound(const QByteArray byteArray, QObject* parent = NULL); - void append(const QByteArray byteArray); + Sound(const QUrl& url, bool isStereo = false); bool isStereo() const { return _isStereo; } - bool hasDownloaded() const { return _hasDownloaded; } const QByteArray& getByteArray() { return _byteArray; } private: QByteArray _byteArray; bool _isStereo; - bool _hasDownloaded; void trimFrames(); void downSample(const QByteArray& rawAudioByteArray); void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray); - -private slots: - void replyFinished(); - void replyError(QNetworkReply::NetworkError code); + + virtual void downloadFinished(QNetworkReply* reply); }; -Q_DECLARE_METATYPE(Sound*) - -QScriptValue soundToScriptValue(QScriptEngine* engine, Sound* const& in); -void soundFromScriptValue(const QScriptValue& object, Sound*& out); - #endif // hifi_Sound_h diff --git a/libraries/audio/src/SoundCache.cpp b/libraries/audio/src/SoundCache.cpp new file mode 100644 index 0000000000..09b9cfe330 --- /dev/null +++ b/libraries/audio/src/SoundCache.cpp @@ -0,0 +1,33 @@ +// +// SoundCache.cpp +// libraries/audio/src +// +// Created by Stephen Birarda on 2014-11-13. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "SoundCache.h" + +SoundCache::SoundCache(QObject* parent) : + ResourceCache(parent) { +} + +SharedSoundPointer SoundCache::getSound(const QUrl& url) { + if (QThread::currentThread() != thread()) { + SharedSoundPointer result; + QMetaObject::invokeMethod(this, "getSound", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(SharedSoundPointer, result), Q_ARG(const QUrl&, url)); + return result; + } + return getResource(url).staticCast(); +} + +QSharedPointer SoundCache::createResource(const QUrl& url, const QSharedPointer& fallback, + bool delayLoad, const void* extra) { + return QSharedPointer(new Sound(url), &Resource::allReferencesCleared); +} \ No newline at end of file diff --git a/libraries/audio/src/SoundCache.h b/libraries/audio/src/SoundCache.h new file mode 100644 index 0000000000..4146171794 --- /dev/null +++ b/libraries/audio/src/SoundCache.h @@ -0,0 +1,37 @@ +// +// SoundCache.h +// libraries/audio/src +// +// Created by Stephen Birarda on 2014-11-13. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_SoundCache_h +#define hifi_SoundCache_h + +#include + +#include "Sound.h" + +typedef QSharedPointer SharedSoundPointer; + +/// Scriptable interface for FBX animation loading. +class SoundCache : public ResourceCache { + Q_OBJECT +public: + SoundCache(QObject* parent = NULL); + + Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); + +protected: + + virtual QSharedPointer createResource(const QUrl& url, + const QSharedPointer& fallback, bool delayLoad, const void* extra); +}; + +Q_DECLARE_METATYPE(SharedSoundPointer) + +#endif // hifi_SoundCache_h \ No newline at end of file diff --git a/libraries/avatars/src/Recording.cpp b/libraries/avatars/src/Recording.cpp index 0d089a2bd2..b39421d03a 100644 --- a/libraries/avatars/src/Recording.cpp +++ b/libraries/avatars/src/Recording.cpp @@ -43,13 +43,6 @@ void RecordingFrame::setBlendshapeCoefficients(QVector blendshapeCoeffici _blendshapeCoefficients = blendshapeCoefficients; } -Recording::Recording() : _audio(NULL) { -} - -Recording::~Recording() { - delete _audio; -} - int Recording::getLength() const { if (_timestamps.isEmpty()) { return 0; @@ -77,19 +70,10 @@ void Recording::addFrame(int timestamp, RecordingFrame &frame) { _frames << frame; } -void Recording::addAudioPacket(const QByteArray& byteArray) { - if (!_audio) { - _audio = new Sound(byteArray); - return; - } - _audio->append(byteArray); -} - void Recording::clear() { _timestamps.clear(); _frames.clear(); - delete _audio; - _audio = NULL; + _audioData.clear(); } void writeVec3(QDataStream& stream, const glm::vec3& value) { @@ -324,7 +308,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) { fileStream << buffer; } - fileStream << recording->_audio->getByteArray(); + fileStream << recording->getAudioData(); qint64 writingTime = timer.restart(); // Write data length and CRC-16 @@ -367,7 +351,7 @@ void writeRecordingToFile(RecordingPointer recording, const QString& filename) { qDebug() << "Recording:"; qDebug() << "Total frames:" << recording->getFrameNumber(); - qDebug() << "Audio array:" << recording->getAudio()->getByteArray().size(); + qDebug() << "Audio array:" << recording->getAudioData().size(); } qint64 checksumTime = timer.elapsed(); @@ -642,7 +626,7 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString qDebug() << "Recording:"; qDebug() << "Total frames:" << recording->getFrameNumber(); - qDebug() << "Audio array:" << recording->getAudio()->getByteArray().size(); + qDebug() << "Audio array:" << recording->getAudioData().size(); } diff --git a/libraries/avatars/src/Recording.h b/libraries/avatars/src/Recording.h index aa14dc5d76..d1da77560c 100644 --- a/libraries/avatars/src/Recording.h +++ b/libraries/avatars/src/Recording.h @@ -48,9 +48,6 @@ public: /// Stores a recording class Recording { public: - Recording(); - ~Recording(); - bool isEmpty() const { return _timestamps.isEmpty(); } int getLength() const; // in ms @@ -58,11 +55,11 @@ public: int getFrameNumber() const { return _frames.size(); } qint32 getFrameTimestamp(int i) const; const RecordingFrame& getFrame(int i) const; - Sound* getAudio() const { return _audio; } + const QByteArray& getAudioData() const { return _audioData; } protected: void addFrame(int timestamp, RecordingFrame& frame); - void addAudioPacket(const QByteArray& byteArray); + void addAudioPacket(const QByteArray& byteArray) { _audioData.append(byteArray); } void clear(); private: @@ -70,7 +67,7 @@ private: QVector _timestamps; QVector _frames; - Sound* _audio; + QByteArray _audioData; friend class Recorder; friend class Player; From e10d132f754ced8e0b75f66e523151f3550486cb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 14:47:28 -0800 Subject: [PATCH 2/7] avoid Qt QTimer thread bug by putting SoundCache on same thread --- examples/birdSongs.js | 9 ++-- interface/src/Application.cpp | 2 + .../audio/src/AudioScriptingInterface.cpp | 48 ++++++++++--------- libraries/audio/src/Sound.cpp | 15 +++--- libraries/audio/src/Sound.h | 13 ++++- libraries/audio/src/SoundCache.cpp | 14 +++++- libraries/audio/src/SoundCache.h | 11 ++--- libraries/avatars/src/Player.cpp | 2 +- libraries/networking/src/ResourceCache.cpp | 6 ++- libraries/script-engine/src/ScriptEngine.cpp | 13 ----- libraries/shared/src/LogHandler.cpp | 2 - 11 files changed, 74 insertions(+), 61 deletions(-) diff --git a/examples/birdSongs.js b/examples/birdSongs.js index 680cb025ad..267fa20b49 100644 --- a/examples/birdSongs.js +++ b/examples/birdSongs.js @@ -67,7 +67,7 @@ function maybePlaySound(deltaTime) { lifetime: 10 }); } - + playing.push({ audioId: Audio.playSound(birds[whichBird].sound, options), entityId: entityId, lightId: lightId, color: birds[whichBird].color }); } if (playing.length != numPlaying) { @@ -159,8 +159,9 @@ function loadBirds() { var SOUND_BASE_URL = "http://public.highfidelity.io/sounds/Animals/"; for (var i = 0; i < sound_filenames.length; i++) { - birds.push({ sound: new Sound(SOUND_BASE_URL + sound_filenames[i]), - color: colors[i] - } ); + birds.push({ + sound: SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i]), + color: colors[i] + }); } } \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f11ac14d40..6188811442 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -65,6 +65,7 @@ #include #include #include +#include #include #include @@ -3916,6 +3917,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AnimationCache", &_animationCache); + scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance()); scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector); scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels); diff --git a/libraries/audio/src/AudioScriptingInterface.cpp b/libraries/audio/src/AudioScriptingInterface.cpp index cb010ef11d..35a11f4dd4 100644 --- a/libraries/audio/src/AudioScriptingInterface.cpp +++ b/libraries/audio/src/AudioScriptingInterface.cpp @@ -43,28 +43,32 @@ void AudioScriptingInterface::stopAllInjectors() { } AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) { - - AudioInjector* injector = new AudioInjector(sound, injectorOptions); - injector->setLocalAudioInterface(_localAudioInterface); - - QThread* injectorThread = new QThread(); - - injector->moveToThread(injectorThread); - - // start injecting when the injector thread starts - connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio); - - // connect the right slots and signals so that the AudioInjector is killed once the injection is complete - connect(injector, &AudioInjector::finished, injector, &AudioInjector::deleteLater); - connect(injector, &AudioInjector::finished, injectorThread, &QThread::quit); - connect(injector, &AudioInjector::finished, this, &AudioScriptingInterface::injectorStopped); - connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater); - - injectorThread->start(); - - _activeInjectors.append(QPointer(injector)); - - return injector; + if (sound) { + AudioInjector* injector = new AudioInjector(sound, injectorOptions); + injector->setLocalAudioInterface(_localAudioInterface); + + QThread* injectorThread = new QThread(); + + injector->moveToThread(injectorThread); + + // start injecting when the injector thread starts + connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio); + + // connect the right slots and signals so that the AudioInjector is killed once the injection is complete + connect(injector, &AudioInjector::finished, injector, &AudioInjector::deleteLater); + connect(injector, &AudioInjector::finished, injectorThread, &QThread::quit); + connect(injector, &AudioInjector::finished, this, &AudioScriptingInterface::injectorStopped); + connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater); + + injectorThread->start(); + + _activeInjectors.append(QPointer(injector)); + + return injector; + } else { + qDebug() << "AudioScriptingInterface::playSound called with null Sound object."; + return NULL; + } } void AudioScriptingInterface::stopInjector(AudioInjector* injector) { diff --git a/libraries/audio/src/Sound.cpp b/libraries/audio/src/Sound.cpp index 8f858e6d3c..ff54e262f8 100644 --- a/libraries/audio/src/Sound.cpp +++ b/libraries/audio/src/Sound.cpp @@ -29,18 +29,19 @@ #include "AudioEditBuffer.h" #include "Sound.h" - -QScriptValue soundToScriptValue(QScriptEngine* engine, Sound* const& in) { - return engine->newQObject(in); +QScriptValue soundToScriptValue(QScriptEngine* engine, SharedSoundPointer const& in) { + return engine->newQObject(in.data()); } -void soundFromScriptValue(const QScriptValue& object, Sound*& out) { - out = qobject_cast(object.toQObject()); +void soundFromScriptValue(const QScriptValue &object, SharedSoundPointer &out) { + out = SharedSoundPointer(qobject_cast(object.toQObject())); + qDebug() << "Sound from script value" << out.data(); } Sound::Sound(const QUrl& url, bool isStereo) : Resource(url), - _isStereo(isStereo) + _isStereo(isStereo), + _isReady(false) { } @@ -70,6 +71,8 @@ void Sound::downloadFinished(QNetworkReply* reply) { } else { qDebug() << "Network reply without 'Content-Type'."; } + + _isReady = true; } void Sound::downSample(const QByteArray& rawAudioByteArray) { diff --git a/libraries/audio/src/Sound.h b/libraries/audio/src/Sound.h index 2880781ac6..c78bf72ff7 100644 --- a/libraries/audio/src/Sound.h +++ b/libraries/audio/src/Sound.h @@ -21,17 +21,19 @@ class Sound : public Resource { Q_OBJECT - Q_PROPERTY(bool downloaded READ isLoaded) + Q_PROPERTY(bool downloaded READ isReady) public: Sound(const QUrl& url, bool isStereo = false); bool isStereo() const { return _isStereo; } - + bool isReady() const { return _isReady; } + const QByteArray& getByteArray() { return _byteArray; } private: QByteArray _byteArray; bool _isStereo; + bool _isReady; void trimFrames(); void downSample(const QByteArray& rawAudioByteArray); @@ -40,4 +42,11 @@ private: virtual void downloadFinished(QNetworkReply* reply); }; +typedef QSharedPointer SharedSoundPointer; + +Q_DECLARE_METATYPE(SharedSoundPointer) + +QScriptValue soundToScriptValue(QScriptEngine* engine, SharedSoundPointer const& in); +void soundFromScriptValue(const QScriptValue& object, SharedSoundPointer& out); + #endif // hifi_Sound_h diff --git a/libraries/audio/src/SoundCache.cpp b/libraries/audio/src/SoundCache.cpp index 09b9cfe330..68a35e3c48 100644 --- a/libraries/audio/src/SoundCache.cpp +++ b/libraries/audio/src/SoundCache.cpp @@ -13,8 +13,17 @@ #include "SoundCache.h" +static int soundPointerMetaTypeId = qRegisterMetaType(); + +SoundCache& SoundCache::getInstance() { + static SoundCache staticInstance; + return staticInstance; +} + SoundCache::SoundCache(QObject* parent) : - ResourceCache(parent) { + ResourceCache(parent) +{ + } SharedSoundPointer SoundCache::getSound(const QUrl& url) { @@ -24,10 +33,11 @@ SharedSoundPointer SoundCache::getSound(const QUrl& url) { Q_RETURN_ARG(SharedSoundPointer, result), Q_ARG(const QUrl&, url)); return result; } + qDebug() << "Requesting sound at" << url.toString() << "from SoundCache"; return getResource(url).staticCast(); } QSharedPointer SoundCache::createResource(const QUrl& url, const QSharedPointer& fallback, - bool delayLoad, const void* extra) { + bool delayLoad, const void* extra) { return QSharedPointer(new Sound(url), &Resource::allReferencesCleared); } \ No newline at end of file diff --git a/libraries/audio/src/SoundCache.h b/libraries/audio/src/SoundCache.h index 4146171794..f9fbf51c10 100644 --- a/libraries/audio/src/SoundCache.h +++ b/libraries/audio/src/SoundCache.h @@ -16,22 +16,19 @@ #include "Sound.h" -typedef QSharedPointer SharedSoundPointer; - -/// Scriptable interface for FBX animation loading. +/// Scriptable interface for sound loading. class SoundCache : public ResourceCache { Q_OBJECT public: - SoundCache(QObject* parent = NULL); + static SoundCache& getInstance(); Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); protected: - virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra); +private: + SoundCache(QObject* parent = NULL); }; -Q_DECLARE_METATYPE(SharedSoundPointer) - #endif // hifi_SoundCache_h \ No newline at end of file diff --git a/libraries/avatars/src/Player.cpp b/libraries/avatars/src/Player.cpp index 63384371bd..9f01e98730 100644 --- a/libraries/avatars/src/Player.cpp +++ b/libraries/avatars/src/Player.cpp @@ -168,7 +168,7 @@ void Player::setupAudioThread() { _audioThread = new QThread(); _options.position = _avatar->getPosition(); _options.orientation = _avatar->getOrientation(); - _injector.reset(new AudioInjector(_recording->getAudio(), _options), &QObject::deleteLater); + _injector.reset(new AudioInjector(_recording->getAudioData(), _options), &QObject::deleteLater); _injector->moveToThread(_audioThread); _audioThread->start(); QMetaObject::invokeMethod(_injector.data(), "injectAudio", Qt::QueuedConnection); diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index bd0f1cae01..097ede23d0 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -22,7 +22,9 @@ ResourceCache::ResourceCache(QObject* parent) : QObject(parent), - _lastLRUKey(0) { + _lastLRUKey(0) +{ + } ResourceCache::~ResourceCache() { @@ -291,7 +293,7 @@ void Resource::makeRequest() { connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64))); connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError())); connect(_reply, SIGNAL(finished()), SLOT(handleReplyFinished())); - + _replyTimer = new QTimer(this); connect(_replyTimer, SIGNAL(timeout()), SLOT(handleReplyTimeout())); _replyTimer->setSingleShot(true); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 2691b10273..e6002d7c10 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -47,14 +46,6 @@ VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; EntityScriptingInterface ScriptEngine::_entityScriptingInterface; -static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* engine) { - QUrl soundURL = QUrl(context->argument(0).toString()); - bool isStereo = context->argument(1).toBool(); - QScriptValue soundScriptValue = engine->newQObject(new Sound(soundURL, isStereo), QScriptEngine::ScriptOwnership); - - return soundScriptValue; -} - static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ qDebug() << "script:print()<<" << context->argument(0).toString(); QString message = context->argument(0).toString() @@ -263,10 +254,6 @@ void ScriptEngine::init() { QScriptValue printConstructorValue = newFunction(debugPrint); globalObject().setProperty("print", printConstructorValue); - QScriptValue soundConstructorValue = newFunction(soundConstructor); - QScriptValue soundMetaObject = newQMetaObject(&Sound::staticMetaObject, soundConstructorValue); - globalObject().setProperty("Sound", soundMetaObject); - QScriptValue localVoxelsValue = scriptValueFromQMetaObject(); globalObject().setProperty("LocalVoxels", localVoxelsValue); diff --git a/libraries/shared/src/LogHandler.cpp b/libraries/shared/src/LogHandler.cpp index a13f3a9dad..dfac02b912 100644 --- a/libraries/shared/src/LogHandler.cpp +++ b/libraries/shared/src/LogHandler.cpp @@ -119,8 +119,6 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont char dateString[100]; strftime(dateString, sizeof(dateString), DATE_STRING_FORMAT, localTime); - prefixString.append(QString(" [%1]").arg(dateString)); - if (_shouldOutputPID) { prefixString.append(QString(" [%1").arg(getpid())); From 8a03738c837a0e3ecca0b236dbec92503681d6b3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 14:48:18 -0800 Subject: [PATCH 3/7] give a Sound cache to the assignment-client --- assignment-client/src/Agent.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 60129aa444..f3efccf31a 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -217,6 +218,8 @@ void Agent::run() { _scriptEngine.registerGlobalObject("Agent", this); _scriptEngine.init(); // must be done before we set up the viewers + + _scriptEngine.registerGlobalObject("SoundCache", &SoundCache::getInstance()); _scriptEngine.registerGlobalObject("VoxelViewer", &_voxelViewer); // connect the VoxelViewer and the VoxelScriptingInterface to each other From de5881818b06f042de2607d3b5e377dc80518a16 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 14:54:48 -0800 Subject: [PATCH 4/7] update playSound to new sound interface --- examples/playSound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/playSound.js b/examples/playSound.js index efcda0b42b..bc21204665 100644 --- a/examples/playSound.js +++ b/examples/playSound.js @@ -11,7 +11,7 @@ Script.include("libraries/globals.js"); // First, load a sample sound from a URL -var bird = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); +var bird = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); function maybePlaySound(deltaTime) { if (Math.random() < 0.01) { From f27367a0c12cda95e88b52daca63f2ab0866dd08 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 15:00:40 -0800 Subject: [PATCH 5/7] fix audio-mixer muting for injectors --- assignment-client/src/audio/AudioMixer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 4173cacfc7..6c8a4fd1c2 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -774,7 +774,8 @@ void AudioMixer::run() { nodeData->checkBuffersBeforeFrameSend(); // if the stream should be muted, send mute packet - if (shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) { + if (nodeData->getAvatarAudioStream() + && shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) { static const int TIME_BETWEEN_MUTES = 5; // in secs if (usecTimestampNow() - nodeData->getAvatarAudioStream()->getLastMuted() > TIME_BETWEEN_MUTES * USECS_PER_SECOND) { From cfa2912877f15dfd238e1f987ff077850cb70abf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 15:01:45 -0800 Subject: [PATCH 6/7] use new SoundCache across scripts --- examples/airGuitar.js | 24 +++++----- examples/audioBall.js | 2 +- examples/avatarCollision.js | 44 +++++++++---------- examples/bot.js | 2 +- examples/botProceduralWayPoints.js | 4 +- examples/bot_procedural.js | 4 +- examples/clap.js | 20 ++++----- examples/drumStick.js | 4 +- examples/editVoxels.js | 2 +- examples/entityBirds.js | 10 ++--- examples/entityScripts/playSoundOnClick.js | 2 +- .../entityScripts/playSoundOnEnterOrLeave.js | 2 +- examples/frisbee.js | 6 +-- examples/grenadeLauncher.js | 10 ++--- examples/gun.js | 10 ++--- examples/headMove.js | 2 +- examples/inWorldTestTone.js | 2 +- examples/libraries/walkApi.js | 12 ++--- examples/lobby.js | 6 +-- examples/playSoundLoop.js | 6 +-- examples/playSoundOrbit.js | 2 +- examples/playSoundWave.js | 2 +- examples/radio.js | 2 +- examples/spaceInvadersExample.js | 12 ++--- examples/toyball.js | 6 +-- 25 files changed, 99 insertions(+), 99 deletions(-) diff --git a/examples/airGuitar.js b/examples/airGuitar.js index 2c3d0409fa..5a62ee3e7b 100644 --- a/examples/airGuitar.js +++ b/examples/airGuitar.js @@ -34,22 +34,22 @@ var guitarModel = HIFI_PUBLIC_BUCKET + "models/attachments/guitar.fst"; var chords = new Array(); // Nylon string guitar -chords[1] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); -chords[2] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+B.raw"); -chords[3] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+E.raw"); -chords[4] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+G.raw"); +chords[1] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); +chords[2] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+B.raw"); +chords[3] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+E.raw"); +chords[4] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+G.raw"); // Electric guitar -chords[5] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+A+short.raw"); -chords[6] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+B+short.raw"); -chords[7] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+E+short.raw"); -chords[8] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+G+short.raw"); +chords[5] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+A+short.raw"); +chords[6] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+B+short.raw"); +chords[7] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+E+short.raw"); +chords[8] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+G+short.raw"); // Steel Guitar -chords[9] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+A.raw"); -chords[10] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+B.raw"); -chords[11] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+E.raw"); -chords[12] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+G.raw"); +chords[9] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+A.raw"); +chords[10] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+B.raw"); +chords[11] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+E.raw"); +chords[12] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+G.raw"); var NUM_CHORDS = 4; var NUM_GUITARS = 3; diff --git a/examples/audioBall.js b/examples/audioBall.js index ca666285a9..e0c0ce7976 100644 --- a/examples/audioBall.js +++ b/examples/audioBall.js @@ -15,7 +15,7 @@ Script.include("libraries/globals.js"); -var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); +var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); var CHANCE_OF_PLAYING_SOUND = 0.01; var FACTOR = 0.05; diff --git a/examples/avatarCollision.js b/examples/avatarCollision.js index 4bd0adf69a..ce13daa50d 100644 --- a/examples/avatarCollision.js +++ b/examples/avatarCollision.js @@ -24,28 +24,28 @@ var audioOptions = { } var hitSounds = new Array(); -hitSounds[0] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit1.raw"); -hitSounds[1] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit2.raw"); -hitSounds[2] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit3.raw"); -hitSounds[3] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit4.raw"); -hitSounds[4] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit5.raw"); -hitSounds[5] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit6.raw"); -hitSounds[6] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit7.raw"); -hitSounds[7] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit8.raw"); -hitSounds[8] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit9.raw"); -hitSounds[9] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit10.raw"); -hitSounds[10] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit11.raw"); -hitSounds[11] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit12.raw"); -hitSounds[12] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit13.raw"); -hitSounds[13] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit14.raw"); -hitSounds[14] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit15.raw"); -hitSounds[15] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit16.raw"); -hitSounds[16] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit17.raw"); -hitSounds[17] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit18.raw"); -hitSounds[18] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit19.raw"); -hitSounds[19] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit20.raw"); -hitSounds[20] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit21.raw"); -hitSounds[21] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit22.raw"); +hitSounds[0] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit1.raw"); +hitSounds[1] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit2.raw"); +hitSounds[2] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit3.raw"); +hitSounds[3] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit4.raw"); +hitSounds[4] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit5.raw"); +hitSounds[5] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit6.raw"); +hitSounds[6] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit7.raw"); +hitSounds[7] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit8.raw"); +hitSounds[8] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit9.raw"); +hitSounds[9] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit10.raw"); +hitSounds[10] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit11.raw"); +hitSounds[11] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit12.raw"); +hitSounds[12] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit13.raw"); +hitSounds[13] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit14.raw"); +hitSounds[14] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit15.raw"); +hitSounds[15] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit16.raw"); +hitSounds[16] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit17.raw"); +hitSounds[17] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit18.raw"); +hitSounds[18] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit19.raw"); +hitSounds[19] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit20.raw"); +hitSounds[20] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit21.raw"); +hitSounds[21] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit22.raw"); function playHitSound(mySessionID, theirSessionID, collision) { var now = new Date(); diff --git a/examples/bot.js b/examples/bot.js index 09c9a51cdd..aadd038eb6 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -228,6 +228,6 @@ function loadSounds() { var SOUND_BASE_URL = HIFI_PUBLIC_BUCKET + "sounds/Cocktail+Party+Snippets/Raws/"; for (var i = 0; i < sound_filenames.length; i++) { - sounds.push(new Sound(SOUND_BASE_URL + sound_filenames[i])); + sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); } } diff --git a/examples/botProceduralWayPoints.js b/examples/botProceduralWayPoints.js index 0f8b369470..e20714bd27 100644 --- a/examples/botProceduralWayPoints.js +++ b/examples/botProceduralWayPoints.js @@ -151,11 +151,11 @@ function loadSounds() { var FOOTSTEP_BASE_URL = HIFI_PUBLIC_BUCKET + "sounds/Footsteps/"; for (var i = 0; i < sound_filenames.length; i++) { - sounds.push(new Sound(SOUND_BASE_URL + sound_filenames[i])); + sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); } for (var i = 0; i < footstep_filenames.length; i++) { - footstepSounds.push(new Sound(FOOTSTEP_BASE_URL + footstep_filenames[i])); + footstepSounds.push(SoundCache.getSound(FOOTSTEP_BASE_URL + footstep_filenames[i])); } } diff --git a/examples/bot_procedural.js b/examples/bot_procedural.js index 80f83fcdfa..eec3c8906d 100644 --- a/examples/bot_procedural.js +++ b/examples/bot_procedural.js @@ -113,11 +113,11 @@ function loadSounds() { var FOOTSTEP_BASE_URL = HIFI_PUBLIC_BUCKET + "sounds/Footsteps/"; for (var i = 0; i < sound_filenames.length; i++) { - sounds.push(new Sound(SOUND_BASE_URL + sound_filenames[i])); + sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); } for (var i = 0; i < footstep_filenames.length; i++) { - footstepSounds.push(new Sound(FOOTSTEP_BASE_URL + footstep_filenames[i])); + footstepSounds.push(SoundCache.getSound(FOOTSTEP_BASE_URL + footstep_filenames[i])); } } diff --git a/examples/clap.js b/examples/clap.js index bf71f13cea..2b011404c0 100644 --- a/examples/clap.js +++ b/examples/clap.js @@ -28,16 +28,16 @@ var lastClapFrame = 0; var lastAnimFrame = 0; var claps = []; -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap1Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap2Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap3Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap4Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap5Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap6Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap7Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap8Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap9Rvb.wav")); -claps.push(new Sound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap10Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap1Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap2Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap3Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap4Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap5Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap6Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap7Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap8Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap9Rvb.wav")); +claps.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/claps/BClap10Rvb.wav")); var numberOfSounds = claps.length; var clappingNow = false; diff --git a/examples/drumStick.js b/examples/drumStick.js index 1af9ffc3dd..463b653e5f 100644 --- a/examples/drumStick.js +++ b/examples/drumStick.js @@ -28,8 +28,8 @@ function vMinus(a, b) { // First, load two percussion sounds to be used on the sticks -var drum1 = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Drums/RackTomHi.raw"); -var drum2 = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Drums/RackTomLo.raw"); +var drum1 = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Drums/RackTomHi.raw"); +var drum2 = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Drums/RackTomLo.raw"); // State Machine: // 0 = not triggered diff --git a/examples/editVoxels.js b/examples/editVoxels.js index 0747b9269f..1fa2df0977 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -78,7 +78,7 @@ function SoundArray() { this.audioOptions = audioOptions this.sounds = new Array(); this.addSound = function (soundURL) { - this.sounds[this.sounds.length] = new Sound(soundURL); + this.sounds[this.sounds.length] = SoundCache.getSound(soundURL); } this.play = function (index) { if (0 <= index && index < this.sounds.length) { diff --git a/examples/entityBirds.js b/examples/entityBirds.js index d18513ba49..9512597af9 100644 --- a/examples/entityBirds.js +++ b/examples/entityBirds.js @@ -70,23 +70,23 @@ function addBird() var size; var which = Math.random(); if (which < 0.2) { - tweet = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); + tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); color = { red: 100, green: 50, blue: 120 }; size = 0.08; } else if (which < 0.4) { - tweet = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/rosyfacedlovebird.raw"); + tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/rosyfacedlovebird.raw"); color = { red: 100, green: 150, blue: 75 }; size = 0.09; } else if (which < 0.6) { - tweet = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/saysphoebe.raw"); + tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/saysphoebe.raw"); color = { red: 84, green: 121, blue: 36 }; size = 0.05; } else if (which < 0.8) { - tweet = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); + tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); color = { red: 23, green: 197, blue: 230 }; size = 0.12; } else { - tweet = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Animals/westernscreechowl.raw"); + tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/westernscreechowl.raw"); color = { red: 50, green: 67, blue: 144 }; size = 0.15; } diff --git a/examples/entityScripts/playSoundOnClick.js b/examples/entityScripts/playSoundOnClick.js index 4ab83a1952..6c1279774b 100644 --- a/examples/entityScripts/playSoundOnClick.js +++ b/examples/entityScripts/playSoundOnClick.js @@ -16,7 +16,7 @@ this.preload = function(entityID) { print("preload("+entityID.id+")"); - bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); + bird = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); }; this.clickDownOnEntity = function(entityID, mouseEvent) { diff --git a/examples/entityScripts/playSoundOnEnterOrLeave.js b/examples/entityScripts/playSoundOnEnterOrLeave.js index 07be090c31..f82c05c580 100644 --- a/examples/entityScripts/playSoundOnEnterOrLeave.js +++ b/examples/entityScripts/playSoundOnEnterOrLeave.js @@ -23,7 +23,7 @@ this.preload = function(entityID) { print("preload("+entityID.id+")"); - bird = new Sound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); + bird = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); }; this.enterEntity = function(entityID) { diff --git a/examples/frisbee.js b/examples/frisbee.js index 7e266de34b..cf271f4f04 100644 --- a/examples/frisbee.js +++ b/examples/frisbee.js @@ -160,9 +160,9 @@ var rightMouseControl = new MouseControl("RIGHT"); var mouseControls = [leftMouseControl, middleMouseControl, rightMouseControl]; var currentMouseControl = false; -var newSound = new Sound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw"); -var catchSound = new Sound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"); -var throwSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Switches%20and%20sliders/slider%20-%20whoosh1.raw"); +var newSound = SoundCache.getSound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw"); +var catchSound = SoundCache.getSound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"); +var throwSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Switches%20and%20sliders/slider%20-%20whoosh1.raw"); var simulatedFrisbees = []; diff --git a/examples/grenadeLauncher.js b/examples/grenadeLauncher.js index e95d8dd79d..3907e41ea6 100644 --- a/examples/grenadeLauncher.js +++ b/examples/grenadeLauncher.js @@ -36,11 +36,11 @@ var RELOAD_INTERVAL = 5; var showScore = false; // Load some sound to use for loading and firing -var fireSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw"); -var loadSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guns/Gun_Reload_Weapon22.raw"); -var impactSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guns/BulletImpact2.raw"); -var targetHitSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); -var targetLaunchSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); +var fireSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw"); +var loadSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/Gun_Reload_Weapon22.raw"); +var impactSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/BulletImpact2.raw"); +var targetHitSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); +var targetLaunchSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; diff --git a/examples/gun.js b/examples/gun.js index 76084ce013..fff78496b2 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -35,11 +35,11 @@ var RELOAD_INTERVAL = 5; var showScore = false; // Load some sound to use for loading and firing -var fireSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw"); -var loadSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guns/Gun_Reload_Weapon22.raw"); -var impactSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guns/BulletImpact2.raw"); -var targetHitSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); -var targetLaunchSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); +var fireSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw"); +var loadSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/Gun_Reload_Weapon22.raw"); +var impactSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/BulletImpact2.raw"); +var targetHitSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); +var targetLaunchSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; diff --git a/examples/headMove.js b/examples/headMove.js index 957686bb20..56f42984e4 100644 --- a/examples/headMove.js +++ b/examples/headMove.js @@ -70,7 +70,7 @@ function activateWarp() { var WATCH_AVATAR_DISTANCE = 2.5; -var sound = new Sound("http://public.highfidelity.io/sounds/Footsteps/FootstepW2Right-12db.wav"); +var sound = SoundCache.getSound("http://public.highfidelity.io/sounds/Footsteps/FootstepW2Right-12db.wav"); function playSound() { Audio.playSound(sound, { position: MyAvatar.position diff --git a/examples/inWorldTestTone.js b/examples/inWorldTestTone.js index b3bf91d14d..4547309faa 100644 --- a/examples/inWorldTestTone.js +++ b/examples/inWorldTestTone.js @@ -13,7 +13,7 @@ Script.include("libraries/globals.js"); -var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); +var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); var soundPlaying = false; diff --git a/examples/libraries/walkApi.js b/examples/libraries/walkApi.js index 0175c56e18..e61335f6f0 100644 --- a/examples/libraries/walkApi.js +++ b/examples/libraries/walkApi.js @@ -335,12 +335,12 @@ walkAssets = (function () { // read in the sounds var _footsteps = []; - _footsteps.push(new Sound(_pathToSounds+"FootstepW2Left-12db.wav")); - _footsteps.push(new Sound(_pathToSounds+"FootstepW2Right-12db.wav")); - _footsteps.push(new Sound(_pathToSounds+"FootstepW3Left-12db.wav")); - _footsteps.push(new Sound(_pathToSounds+"FootstepW3Right-12db.wav")); - _footsteps.push(new Sound(_pathToSounds+"FootstepW5Left-12db.wav")); - _footsteps.push(new Sound(_pathToSounds+"FootstepW5Right-12db.wav")); + _footsteps.push(SoundCache.getSound(_pathToSounds+"FootstepW2Left-12db.wav")); + _footsteps.push(SoundCache.getSound(_pathToSounds+"FootstepW2Right-12db.wav")); + _footsteps.push(SoundCache.getSound(_pathToSounds+"FootstepW3Left-12db.wav")); + _footsteps.push(SoundCache.getSound(_pathToSounds+"FootstepW3Right-12db.wav")); + _footsteps.push(SoundCache.getSound(_pathToSounds+"FootstepW5Left-12db.wav")); + _footsteps.push(SoundCache.getSound(_pathToSounds+"FootstepW5Right-12db.wav")); // load the animation datafiles Script.include(pathToAssets+"animations/dd-female-standard-walk-animation.js"); diff --git a/examples/lobby.js b/examples/lobby.js index 1b6596efa7..bb033971b3 100644 --- a/examples/lobby.js +++ b/examples/lobby.js @@ -39,11 +39,11 @@ var ORB_SHIFT = { x: 0, y: -1.4, z: -0.8}; var HELMET_ATTACHMENT_URL = HIFI_PUBLIC_BUCKET + "models/attachments/IronManMaskOnly.fbx" -var droneSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/drone.raw") +var droneSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/drone.raw") var currentDrone = null; -var latinSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.raw") -var elevatorSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.raw") +var latinSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.raw") +var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.raw") var currentMusak = null; function reticlePosition() { diff --git a/examples/playSoundLoop.js b/examples/playSoundLoop.js index b84c475d1a..f7116cb615 100644 --- a/examples/playSoundLoop.js +++ b/examples/playSoundLoop.js @@ -15,9 +15,9 @@ Script.include("libraries/globals.js"); // A few sample files you may want to try: -var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); -//var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); -//var sound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Cocktail+Party+Snippets/Bandcamp.wav"); +var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); +//var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); +//var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Cocktail+Party+Snippets/Bandcamp.wav"); var soundPlaying = false; var options = { diff --git a/examples/playSoundOrbit.js b/examples/playSoundOrbit.js index d98f7d0768..16ba5e52af 100644 --- a/examples/playSoundOrbit.js +++ b/examples/playSoundOrbit.js @@ -11,7 +11,7 @@ Script.include("libraries/globals.js"); -var soundClip = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Voxels/voxel create 3.raw"); +var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Voxels/voxel create 3.raw"); var currentTime = 1.570079; // pi/2 var deltaTime = 0.05; diff --git a/examples/playSoundWave.js b/examples/playSoundWave.js index c5e69f5cd6..0741b72ef0 100644 --- a/examples/playSoundWave.js +++ b/examples/playSoundWave.js @@ -11,7 +11,7 @@ Script.include("libraries/globals.js"); -var soundClip = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Cocktail%20Party%20Snippets/Walken1.wav"); +var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Cocktail%20Party%20Snippets/Walken1.wav"); function playSound() { Audio.playSound(soundClip, { diff --git a/examples/radio.js b/examples/radio.js index fc09fb184e..0b62d78b0e 100644 --- a/examples/radio.js +++ b/examples/radio.js @@ -23,7 +23,7 @@ var audioOptions = { var injector = null; -var sound = new Sound(soundURL, audioOptions.isStereo); +var sound = SoundCache.getSound(soundURL, audioOptions.isStereo); var entity = null; var properties = null; diff --git a/examples/spaceInvadersExample.js b/examples/spaceInvadersExample.js index dd5ac9e875..832efe7e75 100644 --- a/examples/spaceInvadersExample.js +++ b/examples/spaceInvadersExample.js @@ -84,13 +84,13 @@ var missileFired = false; var myMissile; // sounds -var hitSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); -var shootSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); +var hitSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); +var shootSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); var moveSounds = new Array(); -moveSounds[0] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo1.raw"); -moveSounds[1] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo2.raw"); -moveSounds[2] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo3.raw"); -moveSounds[3] = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo4.raw"); +moveSounds[0] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo1.raw"); +moveSounds[1] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo2.raw"); +moveSounds[2] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo3.raw"); +moveSounds[3] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/Lo4.raw"); var currentMoveSound = 0; var numberOfSounds = 4; var stepsPerSound = invaderStepsPerCycle / numberOfSounds; diff --git a/examples/toyball.js b/examples/toyball.js index 1cd6de16eb..e39ca9c8b4 100644 --- a/examples/toyball.js +++ b/examples/toyball.js @@ -39,9 +39,9 @@ var rightBallAlreadyInHand = false; var leftHandEntity; var rightHandEntity; -var newSound = new Sound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw"); -var catchSound = new Sound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"); -var throwSound = new Sound(HIFI_PUBLIC_BUCKET + "sounds/Switches%20and%20sliders/slider%20-%20whoosh1.raw"); +var newSound = SoundCache.getSound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw"); +var catchSound = SoundCache.getSound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"); +var throwSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Switches%20and%20sliders/slider%20-%20whoosh1.raw"); var targetRadius = 1.0; From 7630aab96397385b5bf5ab5211f44303b8cbe941 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 13 Nov 2014 16:18:19 -0800 Subject: [PATCH 7/7] only debug request sound if there is a network request --- libraries/audio/src/SoundCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/audio/src/SoundCache.cpp b/libraries/audio/src/SoundCache.cpp index 68a35e3c48..4fbd98fea0 100644 --- a/libraries/audio/src/SoundCache.cpp +++ b/libraries/audio/src/SoundCache.cpp @@ -33,11 +33,11 @@ SharedSoundPointer SoundCache::getSound(const QUrl& url) { Q_RETURN_ARG(SharedSoundPointer, result), Q_ARG(const QUrl&, url)); return result; } - qDebug() << "Requesting sound at" << url.toString() << "from SoundCache"; return getResource(url).staticCast(); } QSharedPointer SoundCache::createResource(const QUrl& url, const QSharedPointer& fallback, - bool delayLoad, const void* extra) { + bool delayLoad, const void* extra) { + qDebug() << "Requesting sound at" << url.toString(); return QSharedPointer(new Sound(url), &Resource::allReferencesCleared); } \ No newline at end of file