can now change loop

This commit is contained in:
ericrius1 2016-02-08 16:22:05 -08:00
parent bad4a5d601
commit b60ba0c5a7
4 changed files with 20 additions and 13 deletions

View file

@ -141,15 +141,19 @@ function handleFoundSoundEntities(entities) {
soundProperties.sound = sound; soundProperties.sound = sound;
soundProperties.readyToPlay = true; soundProperties.readyToPlay = true;
soundProperties.isDownloaded = true; soundProperties.isDownloaded = true;
soundProperties.clipDuration = sound.getClipDuration() * 1000; soundProperties.clipDuration = sound.duration * 1000;
soundEntityMap[entity] = soundProperties; soundEntityMap[entity] = soundProperties;
print("DURATION " + soundProperties.clipDuration);
}); });
} else { } else {
// We already have sound downloaded, so just add it to map right away // We already have sound downloaded, so just add it to map right away
soundProperties.sound = soundUrls[soundData.url]; soundProperties.sound = soundUrls[soundData.url];
soundProperties.clipDuration = soundProperties.sound.duration * 1000;
soundProperties.readyToPlay = true; soundProperties.readyToPlay = true;
soundProperties.isDownloaded = true; soundProperties.isDownloaded = true;
soundEntityMap[entity] = soundProperties; soundEntityMap[entity] = soundProperties;
print("DURATION " + soundProperties.clipDuration);
} }
} else { } else {
//If this sound is in our map already, we want to reset timeWithoutAvatarInRange //If this sound is in our map already, we want to reset timeWithoutAvatarInRange
@ -172,8 +176,8 @@ function checkForSoundPropertyChanges(currentProps, newProps) {
currentProps.readyToPlay = true; currentProps.readyToPlay = true;
} }
if (currentProps.intervalSpread !== currentProps.intervalSpread) { if (currentProps.playbackGapRange !== currentProps.playbackGapRange) {
currentProps.currentPlaybackGap = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread); currentProps.currentPlaybackGap = currentProps.playbackGap + randFloat(-currentProps.playbackGapRange, currentProps.playbackGapRange);
currentProps.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, currentProps.currentPlaybackGap); currentProps.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, currentProps.currentPlaybackGap);
} }
if (currentProps.volume !== newProps.volume) { if (currentProps.volume !== newProps.volume) {
@ -188,14 +192,20 @@ function checkForSoundPropertyChanges(currentProps, newProps) {
currentProps.isDownloaded = false; currentProps.isDownloaded = false;
sound.ready.connect(function() { sound.ready.connect(function() {
currentProps.sound = sound; currentProps.sound = sound;
currentProps.clipDuration = sound.getClipDuration() * 1000; currentProps.clipDuration = sound.duration * 1000;
currentProps.isDownloaded = true; currentProps.isDownloaded = true;
}); });
} else { } else {
currentProps.sound = sound; currentProps.sound = sound;
currentProps.clipDuration = sound.duration * 1000;
} }
needsNewInjector = true; needsNewInjector = true;
} }
if (currentProps.loop !== newProps.loop) {
currentProps.loop = newProps.loop;
needsNewInjector = true;
}
if (needsNewInjector) { if (needsNewInjector) {
// If we were looping we need to stop that so new changes are applied // If we were looping we need to stop that so new changes are applied
currentProps.soundInjector.stop(); currentProps.soundInjector.stop();

View file

@ -25,9 +25,9 @@ var userData = {
soundKey: { soundKey: {
url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove2.wav", url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove2.wav",
volume: 0.3, volume: 0.3,
loop: false, loop: true,
playbackGap: 2000, // In ms - time to wait in between clip plays 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
} }
} }

View file

@ -258,8 +258,7 @@ void Sound::interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& ou
qCDebug(audio) << "Error reading WAV file"; 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 { } else {
qCDebug(audio) << "Could not read wav audio file header."; qCDebug(audio) << "Could not read wav audio file header.";

View file

@ -22,19 +22,17 @@ class Sound : public Resource {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool downloaded READ isReady) Q_PROPERTY(bool downloaded READ isReady)
Q_PROPERTY(float duration READ getDuration)
public: public:
Sound(const QUrl& url, bool isStereo = false); Sound(const QUrl& url, bool isStereo = false);
bool isStereo() const { return _isStereo; } bool isStereo() const { return _isStereo; }
bool isReady() const { return _isReady; } bool isReady() const { return _isReady; }
float getDuration() { return _duration; }
const QByteArray& getByteArray() { return _byteArray; } const QByteArray& getByteArray() { return _byteArray; }
public slots:
// _clipLength is in seconds
float getClipDuration() const { return _clipDuration; }
signals: signals:
void ready(); void ready();
@ -42,7 +40,7 @@ private:
QByteArray _byteArray; QByteArray _byteArray;
bool _isStereo; bool _isStereo;
bool _isReady; bool _isReady;
float _clipDuration; float _duration; // In seconds
void downSample(const QByteArray& rawAudioByteArray); void downSample(const QByteArray& rawAudioByteArray);
void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray); void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray);