use SoundCheck/ReplayGain for normalization

This commit is contained in:
vapormusic 2021-12-29 23:16:52 +07:00
parent f777f832e4
commit 610633b9e3
4 changed files with 51 additions and 25 deletions

View file

@ -28,32 +28,8 @@ var CiderAudio = {
CiderAudio.normalizerOn()
}
},
normalizerOn: function (){
let tuna = Tuna(CiderAudio.context)
if (!CiderAudio.audioNodes.compressorNode){
CiderAudio.audioNodes.compressorNode = new tuna.Compressor({
threshold: -80, //-100 to 0
makeupGain: 5, //0 and up (in decibels)
attack: 2, //0 to 1000
release: 200, //0 to 3000
ratio: 8, //1 to 20
knee: 0, //0 to 40
automakeup: false, //true/false
bypass: 0
});
}
try{
CiderAudio.audioNodes.gainNode.disconnect(CiderAudio.context.destination);
} catch (e){}
CiderAudio.audioNodes.gainNode.connect(CiderAudio.audioNodes.compressorNode);
CiderAudio.audioNodes.compressorNode.connect(CiderAudio.context.destination);
},
normalizerOn: function (){},
normalizerOff: function (){
try{
CiderAudio.audioNodes.compressorNode.disconnect();
CiderAudio.audioNodes.compressorNode = null
} catch (e){}
CiderAudio.audioNodes.gainNode.connect(CiderAudio.context.destination);
}
}

View file

@ -463,6 +463,15 @@ const app = new Vue({
MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player")
ipcRenderer.on('SoundCheckTag', (event, tag) => {
console.log(tag)
let replaygain = self.parseSCTagToRG(tag)
try {
CiderAudio.audioNodes.gainNode.gain.value = (1 - Math.min(Math.pow(10, (replaygain.gain / 20)), (1 / replaygain.peak)))
} catch (e){
}
})
this.mk.addEventListener(MusicKit.Events.playbackTimeDidChange, (a) => {
self.lyriccurrenttime = self.mk.currentPlaybackTime
@ -480,6 +489,10 @@ const app = new Vue({
} catch (_) {
}
if (app.cfg.audio.normalization){
try{ ipcRenderer.send('getPreviewURL', self.mk.nowPlayingItem.previewURL)} catch(e){}
}
let type = (self.mk.nowPlayingItem != null) ? self.mk.nowPlayingItem["type"] ?? '' : '';
if (type.includes("musicVideo") || type.includes("uploadedVideo") || type.includes("music-movie")) {
@ -2501,6 +2514,22 @@ const app = new Vue({
element.innerHTML = `Disconnect\n<p style="font-size: 8px"><i>(Authed: ${lfmAuthKey})</i></p>`;
element.onclick = app.LastFMDeauthorize;
});
},
parseSCTagToRG: function(tag){
let soundcheck = tag.split(" ")
let numbers = []
for (item of soundcheck){
numbers.push(parseInt(item, 16))
}
numbers.shift()
let gain = Math.log10((Math.max(numbers[0],numbers[1]) ?? 1000) / 1000.0) * -10
let peak = Math.max(numbers[6],numbers[7]) / 32768.0
console.log(gain,peak)
return {
gain: gain,
peak: peak
}
}
}