I'm looking everywhere for solutions for audio downsampling. However for one reason or another they are incomplete, sometimes buggy, and sometimes are in a programming language I cannot understand.
So here's my use case:
I have an array containing two channels (left-right, it is a microphone) with Float32 data that gets interleaved and then converted to PCM like this:
function interleave(left, right) { var length = left.length + right.length; var result = new Float32Array(length); var _index = 0; for(var index = 0; index < length;) { result[index++] = left[_index]; result[index++] = right[_index]; _index++; } return result; } function convertToPCM(raw) { var output = new Buffer(raw.length*2); for (var i = 0, offset = 0; i < raw.length; i++, offset += 2){ var s = Math.max(-1, Math.min(1, raw[i])); output.writeInt16LE(s < 0 ? s*0x8000 : s*0x7FFF, offset); } return output; } This is NodeJS\Javascript, but I think it's pretty clear how it works.
Now here's the issue. The output of these function needs to generate a WAV file downsampled to 22000 or 16000, but the source has a sample rate of 44100.
Could you please highlight what algorithm should I use in order to achieve this?
Thank you very much!