diff options
author | RaindropsSys <raindrops@equestria.dev> | 2023-10-30 23:08:45 +0100 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2023-10-30 23:08:45 +0100 |
commit | 41c51b8bdb9c8e9fa4a7d56f260d594739d4107e (patch) | |
tree | 4bb3e824d636c7cf8cb39fd0e1aa25c49c339164 /normalizer | |
parent | 4d4308c46d4f7801c657cc79d2243e1a81831334 (diff) | |
download | mist-41c51b8bdb9c8e9fa4a7d56f260d594739d4107e.tar.gz mist-41c51b8bdb9c8e9fa4a7d56f260d594739d4107e.tar.bz2 mist-41c51b8bdb9c8e9fa4a7d56f260d594739d4107e.zip |
Updated 35 files and added 28 files (automated)
Diffstat (limited to 'normalizer')
-rwxr-xr-x | normalizer/normalizer.html | 171 | ||||
-rwxr-xr-x | normalizer/sample-a.mp3 | bin | 0 -> 37473 bytes | |||
-rwxr-xr-x | normalizer/sample-b.mp3 | bin | 0 -> 25377 bytes | |||
-rwxr-xr-x | normalizer/sample-c.mp3 | bin | 0 -> 26145 bytes | |||
-rwxr-xr-x | normalizer/sample-d.mp3 | bin | 0 -> 36705 bytes | |||
-rwxr-xr-x | normalizer/sample-e.mp3 | bin | 0 -> 49761 bytes | |||
-rwxr-xr-x | normalizer/sample-f.mp3 | bin | 0 -> 32993 bytes | |||
-rwxr-xr-x | normalizer/sample-g.mp3 | bin | 0 -> 53793 bytes |
8 files changed, 171 insertions, 0 deletions
diff --git a/normalizer/normalizer.html b/normalizer/normalizer.html new file mode 100755 index 0000000..d166c65 --- /dev/null +++ b/normalizer/normalizer.html @@ -0,0 +1,171 @@ +<script type="text/javascript"> +</script> +<table> + +<tr> +<th> +Not normalized +</th> +<th> +Normalized +</th> +<th> +Computed gain +</th> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-a.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-a-n" controls> <source src="sample-a.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-a-d"></div> +</td> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-b.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-b-n" controls> <source src="sample-b.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-b-d"></div> +</td> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-c.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-c-n" controls> <source src="sample-c.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-c-d"></div> +</td> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-d.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-d-n" controls> <source src="sample-d.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-d-d"></div> +</td> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-e.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-e-n" controls> <source src="sample-e.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-e-d"></div> +</td> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-f.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-f-n" controls> <source src="sample-f.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-f-d"></div> +</td> +</tr> + +<tr> +<td> +<audio controls> <source src="sample-g.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<audio id="sample-g-n" controls> <source src="sample-g.mp3" type="audio/mpeg">Audio element not supported</audio> +</td> +<td> +<div id="sample-g-d"></div> +</td> +</tr> + +</table> +<script type="text/javascript"> + function start() { + var audioCtx = new AudioContext(); + +// http://wiki.hydrogenaud.io/index.php?title=ReplayGain_specification +// TODO: do the loudness filtering (Butterworth, Yulewalk) IIR filters + + function normalizedAudioElement(name) { + var audioElem = document.getElementById(name + "-n"); + var src = audioCtx.createMediaElementSource(audioElem); + var gainNode = audioCtx.createGain(); + gainNode.gain.value = 1.0; + + audioElem.addEventListener("play", function() { + src.connect(gainNode); + gainNode.connect(audioCtx.destination); + }, true); + audioElem.addEventListener("pause", function() { + // disconnect the nodes on pause, otherwise all nodes always run + src.disconnect(gainNode); + gainNode.disconnect(audioCtx.destination); + }, true); + fetch(name + ".mp3") + .then(function(res) { return res.arrayBuffer(); }) + .then(function(buf) { + return audioCtx.decodeAudioData(buf); + }).then(function(decodedData) { + var decodedBuffer = decodedData.getChannelData(0); + var sliceLen = Math.floor(decodedData.sampleRate * 0.05); + var averages = []; + var sum = 0.0; + for (var i = 0; i < decodedBuffer.length; i++) { + sum += decodedBuffer[i] ** 2; + if (i % sliceLen === 0) { + sum = Math.sqrt(sum / sliceLen); + averages.push(sum); + sum = 0; + } + } + // Ascending sort of the averages array + averages.sort(function(a, b) { return a - b; }); + // Take the average at the 95th percentile + var a = averages[Math.floor(averages.length * 0.95)]; + + var gain = 1.0 / a; + // Perform some clamping + // gain = Math.max(gain, 0.02); + // gain = Math.min(gain, 100.0); + + // ReplayGain uses pink noise for this one one but we just take + // some arbitrary value... we're no standard + // Important is only that we don't output on levels + // too different from other websites + gain = gain / 10.0; + console.log("gain determined", name, a, gain); + gainNode.gain.value = gain; + var gainTextElem = document.getElementById(name + "-d"); + gainTextElem.textContent = gain.toPrecision(4); + }); + } + + normalizedAudioElement("sample-a"); + normalizedAudioElement("sample-b"); + normalizedAudioElement("sample-c"); + normalizedAudioElement("sample-d"); + normalizedAudioElement("sample-e"); + normalizedAudioElement("sample-f"); + normalizedAudioElement("sample-g"); + } +</script> diff --git a/normalizer/sample-a.mp3 b/normalizer/sample-a.mp3 Binary files differnew file mode 100755 index 0000000..6b6041e --- /dev/null +++ b/normalizer/sample-a.mp3 diff --git a/normalizer/sample-b.mp3 b/normalizer/sample-b.mp3 Binary files differnew file mode 100755 index 0000000..bb8c766 --- /dev/null +++ b/normalizer/sample-b.mp3 diff --git a/normalizer/sample-c.mp3 b/normalizer/sample-c.mp3 Binary files differnew file mode 100755 index 0000000..bc488f1 --- /dev/null +++ b/normalizer/sample-c.mp3 diff --git a/normalizer/sample-d.mp3 b/normalizer/sample-d.mp3 Binary files differnew file mode 100755 index 0000000..b51df1c --- /dev/null +++ b/normalizer/sample-d.mp3 diff --git a/normalizer/sample-e.mp3 b/normalizer/sample-e.mp3 Binary files differnew file mode 100755 index 0000000..85ef615 --- /dev/null +++ b/normalizer/sample-e.mp3 diff --git a/normalizer/sample-f.mp3 b/normalizer/sample-f.mp3 Binary files differnew file mode 100755 index 0000000..17e5e96 --- /dev/null +++ b/normalizer/sample-f.mp3 diff --git a/normalizer/sample-g.mp3 b/normalizer/sample-g.mp3 Binary files differnew file mode 100755 index 0000000..e610b33 --- /dev/null +++ b/normalizer/sample-g.mp3 |