mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 22:27:13 +02:00
can now change loop
This commit is contained in:
parent
bad4a5d601
commit
b60ba0c5a7
4 changed files with 20 additions and 13 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.";
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue