fix beat syncing using accurate song time, prevent bug from using vars-on-top style
This commit is contained in:
@@ -133,19 +133,21 @@ AFRAME.registerComponent('beat-loader', {
|
|||||||
* Generate beats and stuff according to timestamp.
|
* Generate beats and stuff according to timestamp.
|
||||||
*/
|
*/
|
||||||
tick: function (time, delta) {
|
tick: function (time, delta) {
|
||||||
const beatsTime = this.beatsTime;
|
|
||||||
var i;
|
var i;
|
||||||
var noteTime;
|
var noteTime;
|
||||||
|
|
||||||
if (!this.data.isPlaying || !this.data.challengeId || !this.beatData) { return; }
|
if (!this.data.isPlaying || !this.data.challengeId || !this.beatData) { return; }
|
||||||
|
|
||||||
// Re-sync song with beats playback.
|
// Re-sync song with beats playback.
|
||||||
if (this.beatsTimeOffset !== undefined &&
|
const songComponent = this.el.components.song;
|
||||||
this.songCurrentTime !== this.el.components.song.context.currentTime) {
|
const currentTime = songComponent.context.currentTime - songComponent.songStartTime;
|
||||||
this.songCurrentTime = this.el.components.song.context.currentTime;
|
if (songComponent.songStartTime && this.beatsTimeOffset !== undefined &&
|
||||||
|
this.songCurrentTime !== currentTime) {
|
||||||
|
this.songCurrentTime = currentTime;
|
||||||
this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000;
|
this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const beatsTime = this.beatsTime;
|
||||||
const bpm = this.beatData._beatsPerMinute;
|
const bpm = this.beatData._beatsPerMinute;
|
||||||
const msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute;
|
const msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute;
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ AFRAME.registerComponent('song', {
|
|||||||
this.audioAnalyser = this.data.analyserEl.components.audioanalyser;
|
this.audioAnalyser = this.data.analyserEl.components.audioanalyser;
|
||||||
this.context = this.audioAnalyser.context;
|
this.context = this.audioAnalyser.context;
|
||||||
this.songLoadingIndicator = document.getElementById('songLoadingIndicator');
|
this.songLoadingIndicator = document.getElementById('songLoadingIndicator');
|
||||||
|
this.songStartTime = 0;
|
||||||
|
|
||||||
this.victory = this.victory.bind(this);
|
this.victory = this.victory.bind(this);
|
||||||
|
|
||||||
@@ -194,6 +195,7 @@ AFRAME.registerComponent('song', {
|
|||||||
startAudio: function () {
|
startAudio: function () {
|
||||||
const gain = this.audioAnalyser.gainNode.gain;
|
const gain = this.audioAnalyser.gainNode.gain;
|
||||||
gain.setValueAtTime(BASE_VOLUME, this.context.currentTime);
|
gain.setValueAtTime(BASE_VOLUME, this.context.currentTime);
|
||||||
|
this.songStartTime = this.context.currentTime;
|
||||||
this.source.start();
|
this.source.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user