0

My sampleRate in AudioContext.SampleRate() is always 48khz. Then I change the definitions in windows, going to "recording devices" and change there the SampleRate of the Mic. But, with any reason to happen, the AudioContext.SampleRate() remains the same. Why? This value is related only to the device and not with the windows definitions?

carduh
  • 529
  • 1
  • 4
  • 13

2 Answers2

2

The audio context sample rate is determined by the output device, not the input device. The input device is resampled to the output device rate.

cwilso
  • 13,610
  • 1
  • 30
  • 35
  • I change the sample Rate in windows, but this time I made the change in speakers devices. And everything goes right. Thanks again @cwilso – carduh Dec 03 '15 at 14:46
  • No problem. In the future, the sample rate will be selectable for the audiocontext, but I'd still expect the output device to drive the clock, so the input will always be resampled. – cwilso Dec 04 '15 at 19:01
-1

You can use https://github.com/taisel/XAudioJS/blob/master/resampler.js

var resampler = new Resampler(44100, 48000, 1, 2229);

function startUsermedia(stream) {
    var input = audio_context.createMediaStreamSource(stream);
    recorder = audio_context.createScriptProcessor(2048);
    recorder.onaudioprocess = recorderProcess;
    recorder.connect(audio_context.destination);
}

function recorderProcess(e) {
    var buffer = e.inputBuffer.getChannelData(0);
    var resampled = resampler.resampler(buffer);
}

Note:
Creds for code: https://stackoverflow.com/a/30032095/1501285

Community
  • 1
  • 1
Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101