From 7bf03b02ae210c853c1a36645bec725ef5cc76c2 Mon Sep 17 00:00:00 2001 From: Mid <> Date: Sun, 22 Dec 2024 11:20:09 +0200 Subject: [PATCH] Do not require 48KHz --- blarf.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/blarf.js b/blarf.js index f482f2e..efbca28 100644 --- a/blarf.js +++ b/blarf.js @@ -17,14 +17,17 @@ var AudCtx var AudScript + var AudHz function create_audio(hz, channels) { if(AudCtx) { AudCtx.close() } + AudHz = hz + AudCtx = new AudioContext({sampleRate: hz}) - AudScript = AudCtx.createScriptProcessor(1024, 2, 2) + AudScript = AudCtx.createScriptProcessor(1024, channels, channels) AudScript.onaudioprocess = function(e) { var outL = e.outputBuffer.getChannelData(0) var outR = channels > 1 ? e.outputBuffer.getChannelData(1) : null @@ -106,7 +109,7 @@ if(AudCtx && AudCtx.state != "running") { var durationInAudioQueue = AudioQueue.length ? AudioQueue.reduce((acc, el) => acc + el.left.length, 0) : 0 - var durationToRemove = Math.max(durationInAudioQueue - (VideoQueue.length ? (VideoQueue[VideoQueue.length - 1].t - VideoQueue[0].t) : 0) * 48, 0) + var durationToRemove = Math.max(durationInAudioQueue - (VideoQueue.length ? (VideoQueue[VideoQueue.length - 1].t - VideoQueue[0].t) : 0) * AudHz / 1000, 0) while(AudioQueue.length && durationToRemove) { var amount = Math.min(durationToRemove, AudioQueue[0].left.length) @@ -137,7 +140,7 @@ text = text + k + ":" + (Math.floor(100 * Statistics[k].sum / Statistics[k].count) / 100) + "," } stats.innerText = text*/ - stats.innerHTML = (VideoQueue.length ? (VideoQueue[VideoQueue.length - 1].t - VideoQueue[0].t) : "0") + "v" + (AudioQueue.reduce(function(acc, obj) {return acc + obj.left.length / 48}, 0)|0) + "a" + stats.innerHTML = (VideoQueue.length ? (VideoQueue[VideoQueue.length - 1].t - VideoQueue[0].t) : "0") + "v" + (AudioQueue.reduce(function(acc, obj) {return acc + obj.left.length * AudHz / 1000}, 0)|0) + "a" } } @@ -290,7 +293,6 @@ } ondata(elID, data) { - if(EBMLParser.vi_to_i(data) == 48000) debugger if(elID == 0xD7) { // Track Entry -> Track Number this.tracks[this.tracks.length - 1].id = EBMLParser.vi_to_i(data)