All Projects → felix307253927 → resampler

felix307253927 / resampler

Licence: other
js audio resampler

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to resampler

python-soxr
Fast and high quality sample-rate conversion library for Python
Stars: ✭ 25 (+56.25%)
Mutual labels:  resampler
prospectr
R package: Misc. Functions for Processing and Sample Selection of Spectroscopic Data
Stars: ✭ 26 (+62.5%)
Mutual labels:  resample
ReSampler
High quality command-line audio sample rate converter
Stars: ✭ 120 (+650%)
Mutual labels:  resample
downscale
Better image downscale with canvas.
Stars: ✭ 80 (+400%)
Mutual labels:  resample

resampler

js audio resampler

example

if (!navigator.mediaDevices) {
  navigator.mediaDevices = {};
}
if (!navigator.mediaDevices.getUserMedia) {
  navigator.mediaDevices.getUserMedia = function(constraints) {
    let getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
    if (!getUserMedia) {
      return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
    }
    return new Promise(function(resolve, reject) {
      getUserMedia.call(navigator, constraints, resolve, reject);
    });
  }
}

navigator.mediaDevices.getUserMedia({audio: true})
    .then((stream) => { 
      let context    = new AudioContext(),
          bufSize    = 4096,
          microphone = context.createMediaStreamSource(stream),
          processor  = context.createScriptProcessor(bufSize, 1, 1),
          res        = new Resampler(context.sampleRate, 16000, 1, bufSize),
          bufferArray= [];
      
      processor.onaudioprocess = (event) => {
        // const right = event.inputBuffer.getChannelData(1);
        const outBuf = res.resample(event.inputBuffer.getChannelData(0));
        // TODO something
        bufferArray.push.apply(bufferArray, outBuf);
      }
      
      this.start   = () => {
        if (processor && microphone) {
          bufferArray = [];
          microphone.connect(processor);
          processor.connect(context.destination);
        }
      };
      
       this.stop    = () => {
        if (processor && microphone) {
          microphone.disconnect();
          processor.disconnect();
        }
      };
      
      this.getPcm = () => {
        return new Float32Array(bufferArray);
      };
      this.get16BitPcm = () => {
        //floatTo16BitPCM  in util.js file
        return floatTo16BitPCM(bufferArray);
      }
    })
    .catch((err)=>{
      console.log(err.name + ": " + err.message);
    })
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].