From b60ba0c5a7d694f9983b7bc7b544ac7aef74ad6c Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 8 Feb 2016 16:22:05 -0800 Subject: [PATCH] can now change loop --- .../acAudioSearching/ACAudioSearchAndInject.js | 18 ++++++++++++++---- .../acAudioSearchCompatibleEntitySpawner.js | 4 ++-- libraries/audio/src/Sound.cpp | 3 +-- libraries/audio/src/Sound.h | 8 +++----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js b/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js index 545ac7b46e..d20e132113 100644 --- a/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js +++ b/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js @@ -141,15 +141,19 @@ function handleFoundSoundEntities(entities) { soundProperties.sound = sound; soundProperties.readyToPlay = true; soundProperties.isDownloaded = true; - soundProperties.clipDuration = sound.getClipDuration() * 1000; + soundProperties.clipDuration = sound.duration * 1000; soundEntityMap[entity] = soundProperties; + + print("DURATION " + soundProperties.clipDuration); }); } else { // We already have sound downloaded, so just add it to map right away soundProperties.sound = soundUrls[soundData.url]; + soundProperties.clipDuration = soundProperties.sound.duration * 1000; soundProperties.readyToPlay = true; soundProperties.isDownloaded = true; soundEntityMap[entity] = soundProperties; + print("DURATION " + soundProperties.clipDuration); } } else { //If this sound is in our map already, we want to reset timeWithoutAvatarInRange @@ -172,8 +176,8 @@ function checkForSoundPropertyChanges(currentProps, newProps) { currentProps.readyToPlay = true; } - if (currentProps.intervalSpread !== currentProps.intervalSpread) { - currentProps.currentPlaybackGap = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread); + if (currentProps.playbackGapRange !== currentProps.playbackGapRange) { + currentProps.currentPlaybackGap = currentProps.playbackGap + randFloat(-currentProps.playbackGapRange, currentProps.playbackGapRange); currentProps.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, currentProps.currentPlaybackGap); } if (currentProps.volume !== newProps.volume) { @@ -188,14 +192,20 @@ function checkForSoundPropertyChanges(currentProps, newProps) { currentProps.isDownloaded = false; sound.ready.connect(function() { currentProps.sound = sound; - currentProps.clipDuration = sound.getClipDuration() * 1000; + currentProps.clipDuration = sound.duration * 1000; currentProps.isDownloaded = true; }); } else { currentProps.sound = sound; + currentProps.clipDuration = sound.duration * 1000; } needsNewInjector = true; } + + if (currentProps.loop !== newProps.loop) { + currentProps.loop = newProps.loop; + needsNewInjector = true; + } if (needsNewInjector) { // If we were looping we need to stop that so new changes are applied currentProps.soundInjector.stop(); diff --git a/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js b/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js index 2f957ecbed..455ff13427 100644 --- a/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js +++ b/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js @@ -25,9 +25,9 @@ var userData = { soundKey: { url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove2.wav", volume: 0.3, - loop: false, + loop: true, playbackGap: 2000, // In ms - time to wait in between clip plays - playbackGapRange: 1000 // In ms - the range to wait in between clip plays + playbackGapRange: 0 // In ms - the range to wait in between clip plays } } diff --git a/libraries/audio/src/Sound.cpp b/libraries/audio/src/Sound.cpp index e3efe9b141..808fd2aa0c 100644 --- a/libraries/audio/src/Sound.cpp +++ b/libraries/audio/src/Sound.cpp @@ -258,8 +258,7 @@ void Sound::interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& ou qCDebug(audio) << "Error reading WAV file"; } - _clipLength = (float) (outputAudioByteArraySize / (fileHeader.wave.sampleRate * fileHeader.wave.numChannels * fileHeader.wave.bitsPerSample / 8.0f)); - + _duration = (float) (outputAudioByteArraySize / (fileHeader.wave.sampleRate * fileHeader.wave.numChannels * fileHeader.wave.bitsPerSample / 8.0f)); } else { qCDebug(audio) << "Could not read wav audio file header."; diff --git a/libraries/audio/src/Sound.h b/libraries/audio/src/Sound.h index 8c13f4b257..91456f2fff 100644 --- a/libraries/audio/src/Sound.h +++ b/libraries/audio/src/Sound.h @@ -22,19 +22,17 @@ class Sound : public Resource { Q_OBJECT Q_PROPERTY(bool downloaded READ isReady) + Q_PROPERTY(float duration READ getDuration) public: Sound(const QUrl& url, bool isStereo = false); bool isStereo() const { return _isStereo; } bool isReady() const { return _isReady; } + float getDuration() { return _duration; } const QByteArray& getByteArray() { return _byteArray; } -public slots: - // _clipLength is in seconds - float getClipDuration() const { return _clipDuration; } - signals: void ready(); @@ -42,7 +40,7 @@ private: QByteArray _byteArray; bool _isStereo; bool _isReady; - float _clipDuration; + float _duration; // In seconds void downSample(const QByteArray& rawAudioByteArray); void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray);