[Audio] Fix #1207 (discussions)

Eliminates audio stuttering even when AudioContext is enabled. Make lyrics account for the extra latency introduced by Audio Lab.
This commit is contained in:
maikirakiwi 2022-07-02 23:08:40 -07:00
parent 4d459a3a21
commit e28b484d92
2 changed files with 15 additions and 18 deletions

View file

@ -24,7 +24,7 @@ const CiderAudio = {
CiderAudio.connectContext(document.getElementById("apple-music-player"), 0); CiderAudio.connectContext(document.getElementById("apple-music-player"), 0);
cb(); cb();
clearInterval(searchInt); clearInterval(searchInt);
} }
}, 1000); }, 1000);
}, },
@ -49,7 +49,8 @@ const CiderAudio = {
}, },
connectContext: function (mediaElem) { connectContext: function (mediaElem) {
if (!CiderAudio.context) { if (!CiderAudio.context) {
CiderAudio.context = new window.AudioContext({ sampleRate: 96000 }); // Don't ever remove the sample rate arg. Ask Maikiwi. CiderAudio.context = new window.AudioContext({ sampleRate: 96000, latencyHint: "playback"}); // Don't ever remove the sample rate arg. Ask Maikiwi.
app.lyricOffset = CiderAudio.context.baseLatency
} }
if (!CiderAudio.source) { if (!CiderAudio.source) {
CiderAudio.source = CiderAudio.context.createMediaElementSource(mediaElem); CiderAudio.source = CiderAudio.context.createMediaElementSource(mediaElem);

View file

@ -147,6 +147,7 @@ const app = new Vue({
start: 0, start: 0,
end: 0 end: 0
}, },
lyricOffset: 0.02,
v3: { v3: {
requestBody: { requestBody: {
platform: "web" platform: "web"
@ -920,7 +921,7 @@ const app = new Vue({
}) })
this.mk.addEventListener(MusicKit.Events.playbackTimeDidChange, (a) => { this.mk.addEventListener(MusicKit.Events.playbackTimeDidChange, (a) => {
self.lyriccurrenttime = self.mk.currentPlaybackTime self.lyriccurrenttime = self.mk.currentPlaybackTime + app.lyricOffset
this.currentSongInfo = a this.currentSongInfo = a
self.playerLCD.playbackDuration = (self.mk.currentPlaybackTime) self.playerLCD.playbackDuration = (self.mk.currentPlaybackTime)
// wsapi // wsapi
@ -957,24 +958,19 @@ const app = new Vue({
} }
this.currentSongInfo = a this.currentSongInfo = a
if (this.currentSongInfo === null || this.currentSongInfo === undefined) { return; } // EVIL EMPTY OBJECTS BE GONE if (this.currentSongInfo === null || this.currentSongInfo === undefined) { return; } // EVIL EMPTY OBJECTS BE GONE
try {
console.debug("songinfo: " + JSON.stringify(a)) if (app.mk.nowPlayingItem.flavor.includes("64")) {
if (app.cfg.advanced.AudioContext) { localStorage.setItem("playingBitrate", "64")
try { } else if (app.mk.nowPlayingItem.flavor.includes("256")) {
if (app.mk.nowPlayingItem.flavor.includes("64")) { localStorage.setItem("playingBitrate", "256")
localStorage.setItem("playingBitrate", "64") } else {
} else if (app.mk.nowPlayingItem.flavor.includes("256")) {
localStorage.setItem("playingBitrate", "256")
} else {
localStorage.setItem("playingBitrate", "256")
}
} catch (e) {
localStorage.setItem("playingBitrate", "256") localStorage.setItem("playingBitrate", "256")
} }
if (!app.cfg.audio.normalization) { CiderAudio.hierarchical_loading(); } } catch (e) {
localStorage.setItem("playingBitrate", "256")
} }
if (!app.cfg.audio.normalization) { CiderAudio.hierarchical_loading(); }
if (app.cfg.audio.normalization) { if (app.cfg.audio.normalization) {
// get unencrypted audio previews to get SoundCheck's normalization tag // get unencrypted audio previews to get SoundCheck's normalization tag
try { try {