mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
changed ac script to take into account duration
This commit is contained in:
parent
c169a7cdd5
commit
bad4a5d601
3 changed files with 27 additions and 24 deletions
|
@ -25,10 +25,10 @@ Agent.isAvatar = true;
|
||||||
var DEFAULT_SOUND_DATA = {
|
var DEFAULT_SOUND_DATA = {
|
||||||
volume: 0.5,
|
volume: 0.5,
|
||||||
loop: false,
|
loop: false,
|
||||||
interval: -1, // An interval of -1 means this sound only plays once (if it's non-looping) (In seconds)
|
playbackGap: 1000, // in ms
|
||||||
intervalSpread: 0 // amount of randomness to add to the interval
|
playbackGapRange: 0 // in ms
|
||||||
};
|
};
|
||||||
var MIN_PLAY_INTERVAL = 200;
|
var MIN_PLAYBACK_GAP = 0;
|
||||||
|
|
||||||
var UPDATE_TIME = 100;
|
var UPDATE_TIME = 100;
|
||||||
var EXPIRATION_TIME = 5000;
|
var EXPIRATION_TIME = 5000;
|
||||||
|
@ -90,16 +90,16 @@ function handleActiveSoundEntities() {
|
||||||
soundProperties.soundInjector.restart();
|
soundProperties.soundInjector.restart();
|
||||||
}
|
}
|
||||||
soundProperties.readyToPlay = false;
|
soundProperties.readyToPlay = false;
|
||||||
} else if (soundProperties.sound && soundProperties.loop === false && soundProperties.interval !== -1) {
|
} else if (soundProperties.sound && soundProperties.loop === false) {
|
||||||
// We need to check all of our entities that are not looping but have an interval associated with them
|
// We need to check all of our entities that are not looping but have an interval associated with them
|
||||||
// to see if it's time for them to play again
|
// to see if it's time for them to play again
|
||||||
soundProperties.timeSinceLastPlay += UPDATE_TIME;
|
soundProperties.timeSinceLastPlay += UPDATE_TIME;
|
||||||
if (soundProperties.timeSinceLastPlay > soundProperties.currentInterval) {
|
if (soundProperties.timeSinceLastPlay > soundProperties.clipDuration + soundProperties.currentPlaybackGap) {
|
||||||
soundProperties.readyToPlay = true;
|
soundProperties.readyToPlay = true;
|
||||||
soundProperties.timeSinceLastPlay = 0;
|
soundProperties.timeSinceLastPlay = 0;
|
||||||
// Now let's get our new current interval
|
// Now let's get our new current interval
|
||||||
soundProperties.currentInterval = soundProperties.interval + randFloat(-soundProperties.intervalSpread, soundProperties.intervalSpread);
|
soundProperties.currentPlaybackGap = soundProperties.playbackGap + randFloat(-soundProperties.playbackGapRange, soundProperties.playbackGapRange);
|
||||||
soundProperties.currentInterval = Math.max(MIN_PLAY_INTERVAL, soundProperties.currentInterval);
|
soundProperties.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, soundProperties.currentPlaybackGap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,8 +117,8 @@ function handleFoundSoundEntities(entities) {
|
||||||
url: soundData.url,
|
url: soundData.url,
|
||||||
volume: soundData.volume || DEFAULT_SOUND_DATA.volume,
|
volume: soundData.volume || DEFAULT_SOUND_DATA.volume,
|
||||||
loop: soundData.loop || DEFAULT_SOUND_DATA.loop,
|
loop: soundData.loop || DEFAULT_SOUND_DATA.loop,
|
||||||
interval: soundData.interval || DEFAULT_SOUND_DATA.interval,
|
playbackGap: soundData.playbackGap || DEFAULT_SOUND_DATA.playbackGap,
|
||||||
intervalSpread: soundData.intervalSpread || DEFAULT_SOUND_DATA.intervalSpread,
|
playbackGapRange: soundData.playbackGapRange || DEFAULT_SOUND_DATA.playbackGapRange,
|
||||||
readyToPlay: false,
|
readyToPlay: false,
|
||||||
position: Entities.getEntityProperties(entity, "position").position,
|
position: Entities.getEntityProperties(entity, "position").position,
|
||||||
timeSinceLastPlay: 0,
|
timeSinceLastPlay: 0,
|
||||||
|
@ -126,10 +126,10 @@ function handleFoundSoundEntities(entities) {
|
||||||
isDownloaded: false
|
isDownloaded: false
|
||||||
};
|
};
|
||||||
|
|
||||||
if (soundProperties.interval !== -1) {
|
|
||||||
soundProperties.currentInterval = soundProperties.interval + randFloat(-soundProperties.intervalSpread, soundProperties.intervalSpread);
|
soundProperties.currentPlaybackGap = soundProperties.playbackGap + randFloat(-soundProperties.playbackGapRange, soundProperties.playbackGapRange);
|
||||||
soundProperties.currentInterval = Math.max(MIN_PLAY_INTERVAL, soundProperties.currentInterval);
|
soundProperties.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, soundProperties.currentPlaybackGap);
|
||||||
}
|
|
||||||
|
|
||||||
soundEntityMap[entity] = soundProperties;
|
soundEntityMap[entity] = soundProperties;
|
||||||
if (!soundUrls[soundData.url]) {
|
if (!soundUrls[soundData.url]) {
|
||||||
|
@ -141,6 +141,7 @@ 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;
|
||||||
soundEntityMap[entity] = soundProperties;
|
soundEntityMap[entity] = soundProperties;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -163,17 +164,17 @@ function handleFoundSoundEntities(entities) {
|
||||||
function checkForSoundPropertyChanges(currentProps, newProps) {
|
function checkForSoundPropertyChanges(currentProps, newProps) {
|
||||||
var needsNewInjector = false;
|
var needsNewInjector = false;
|
||||||
|
|
||||||
if (currentProps.interval !== newProps.interval && !currentProps.loop) {
|
if (currentProps.playbackGap !== newProps.playbackGap && !currentProps.loop) {
|
||||||
// interval only applies to non looping sounds
|
// playbackGap only applies to non looping sounds
|
||||||
currentProps.interval = newProps.interval;
|
currentProps.playbackGap = newProps.playbackGap;
|
||||||
currentProps.currentInterval = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread);
|
currentProps.currentPlaybackGap = currentProps.playbackGap + randFloat(-currentProps.playbackGapRange, currentProps.playbackGapRange);
|
||||||
currentProps.currentInterval = Math.max(MIN_PLAY_INTERVAL, currentProps.currentInterval);
|
currentProps.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, currentProps.currentPlaybackGap);
|
||||||
currentProps.readyToPlay = true;
|
currentProps.readyToPlay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentProps.intervalSpread !== currentProps.intervalSpread) {
|
if (currentProps.intervalSpread !== currentProps.intervalSpread) {
|
||||||
currentProps.currentInterval = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread);
|
currentProps.currentPlaybackGap = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread);
|
||||||
currentProps.currentInterval = Math.max(MIN_PLAY_INTERVAL, currentProps.currentInterval);
|
currentProps.currentPlaybackGap = Math.max(MIN_PLAYBACK_GAP, currentProps.currentPlaybackGap);
|
||||||
}
|
}
|
||||||
if (currentProps.volume !== newProps.volume) {
|
if (currentProps.volume !== newProps.volume) {
|
||||||
currentProps.volume = newProps.volume;
|
currentProps.volume = newProps.volume;
|
||||||
|
@ -187,6 +188,7 @@ 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.isDownloaded = true;
|
currentProps.isDownloaded = true;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,8 +26,8 @@ var userData = {
|
||||||
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: false,
|
||||||
interval: 2000, // In ms
|
playbackGap: 2000, // In ms - time to wait in between clip plays
|
||||||
intervalSpread: 1000 // In ms
|
playbackGapRange: 1000 // In ms - the range to wait in between clip plays
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ public:
|
||||||
const QByteArray& getByteArray() { return _byteArray; }
|
const QByteArray& getByteArray() { return _byteArray; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
float getClipLength() const { return _clipLength; }
|
// _clipLength is in seconds
|
||||||
|
float getClipDuration() const { return _clipDuration; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ready();
|
void ready();
|
||||||
|
@ -41,7 +42,7 @@ private:
|
||||||
QByteArray _byteArray;
|
QByteArray _byteArray;
|
||||||
bool _isStereo;
|
bool _isStereo;
|
||||||
bool _isReady;
|
bool _isReady;
|
||||||
float _clipLength;
|
float _clipDuration;
|
||||||
|
|
||||||
void downSample(const QByteArray& rawAudioByteArray);
|
void downSample(const QByteArray& rawAudioByteArray);
|
||||||
void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray);
|
void interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& outputAudioByteArray);
|
||||||
|
|
Loading…
Reference in a new issue