From 1e804e552e32c78b2618ea2056f9245be2cc2261 Mon Sep 17 00:00:00 2001 From: Radium Zheng Date: Wed, 8 Aug 2018 08:14:57 +1000 Subject: [PATCH] fix: FlacAdapter get sampleRate --- .../recording/flac/FlacAdapter.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/react/features/local-recording/recording/flac/FlacAdapter.js b/react/features/local-recording/recording/flac/FlacAdapter.js index bd6f07928..a46f493c4 100644 --- a/react/features/local-recording/recording/flac/FlacAdapter.js +++ b/react/features/local-recording/recording/flac/FlacAdapter.js @@ -51,6 +51,8 @@ export class FlacAdapter extends RecordingAdapter { */ _initPromise = null; + _sampleRate = 44100; + /** * Implements {@link RecordingAdapter#start()}. * @@ -179,6 +181,17 @@ export class FlacAdapter extends RecordingAdapter { return Promise.resolve(); } + // sampleRate is browser and OS dependent. + // Setting sampleRate explicitly is in the specs but not implemented + // by browsers. + // See: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/ + // AudioContext#Browser_compatibility + // And https://bugs.chromium.org/p/chromium/issues/detail?id=432248 + + this._audioContext = new AudioContext(); + this._sampleRate = this._audioContext.sampleRate; + logger.log(`Current sampleRate ${this._sampleRate}.`); + const promiseInitWorker = new Promise((resolve, reject) => { try { this._loadWebWorker(); @@ -212,7 +225,7 @@ export class FlacAdapter extends RecordingAdapter { this._encoder.postMessage({ command: MAIN_THREAD_INIT, config: { - sampleRate: 44100, + sampleRate: this._sampleRate, bps: 16 } }); @@ -222,9 +235,6 @@ export class FlacAdapter extends RecordingAdapter { this._getAudioStream(micDeviceId) .then(stream => { this._stream = stream; - this._audioContext = new AudioContext({ - sampleRate: 44100 - }); this._audioSource = this._audioContext.createMediaStreamSource(stream); this._audioProcessingNode