From 5379d8cc3dc4c8343d1c830f8266fdc8a3981ca1 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 6 Jan 2020 16:29:23 +0100 Subject: [PATCH] step one: implement upsampling --- htdocs/lib/AudioEngine.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/htdocs/lib/AudioEngine.js b/htdocs/lib/AudioEngine.js index 6226825..132df15 100644 --- a/htdocs/lib/AudioEngine.js +++ b/htdocs/lib/AudioEngine.js @@ -18,7 +18,8 @@ function AudioEngine(maxBufferLength, audioReporter) { this.compression = 'none'; this.setupResampling(); - this.resampler = new sdrjs.RationalResamplerFF(this.resamplingFactor, 1); + //this.resampler = new sdrjs.RationalResamplerFF(this.resamplingFactor, 1); + this.resampler = new Interpolator(this.resamplingFactor); this.maxBufferSize = maxBufferLength * this.getSampleRate(); } @@ -203,7 +204,7 @@ AudioEngine.prototype.pushAudio = function(data) { } else { buffer = new Int16Array(data); } - buffer = this.resampler.process(sdrjs.ConvertI16_F(buffer)); + buffer = this.resampler.process(buffer); if (this.audioNode.port) { // AudioWorklets supported this.audioNode.port.postMessage(buffer); @@ -278,4 +279,16 @@ ImaAdpcmCodec.prototype.decodeNibble = function(nibble) { this.step = ImaAdpcmCodec.imaStepTable[this.stepIndex]; return this.predictor; -}; \ No newline at end of file +}; + +function Interpolator(factor) { + this.factor = factor; +} + +Interpolator.prototype.process = function(data) { + var output = new Float32Array(data.length * this.factor); + for (var i = 0; i < data.length; i++) { + output[i * this.factor] = (data[i] + 0.5) / 32768; + } + return output; +} \ No newline at end of file