Sfoglia il codice sorgente

fix: FlacAdapter get sampleRate

j8
Radium Zheng 6 anni fa
parent
commit
1e804e552e

+ 14
- 4
react/features/local-recording/recording/flac/FlacAdapter.js Vedi File

@@ -51,6 +51,8 @@ export class FlacAdapter extends RecordingAdapter {
51 51
      */
52 52
     _initPromise = null;
53 53
 
54
+    _sampleRate = 44100;
55
+
54 56
     /**
55 57
      * Implements {@link RecordingAdapter#start()}.
56 58
      *
@@ -179,6 +181,17 @@ export class FlacAdapter extends RecordingAdapter {
179 181
             return Promise.resolve();
180 182
         }
181 183
 
184
+        // sampleRate is browser and OS dependent.
185
+        // Setting sampleRate explicitly is in the specs but not implemented
186
+        // by browsers.
187
+        // See: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/
188
+        //    AudioContext#Browser_compatibility
189
+        // And https://bugs.chromium.org/p/chromium/issues/detail?id=432248
190
+
191
+        this._audioContext = new AudioContext();
192
+        this._sampleRate = this._audioContext.sampleRate;
193
+        logger.log(`Current sampleRate ${this._sampleRate}.`);
194
+
182 195
         const promiseInitWorker = new Promise((resolve, reject) => {
183 196
             try {
184 197
                 this._loadWebWorker();
@@ -212,7 +225,7 @@ export class FlacAdapter extends RecordingAdapter {
212 225
             this._encoder.postMessage({
213 226
                 command: MAIN_THREAD_INIT,
214 227
                 config: {
215
-                    sampleRate: 44100,
228
+                    sampleRate: this._sampleRate,
216 229
                     bps: 16
217 230
                 }
218 231
             });
@@ -222,9 +235,6 @@ export class FlacAdapter extends RecordingAdapter {
222 235
             this._getAudioStream(micDeviceId)
223 236
             .then(stream => {
224 237
                 this._stream = stream;
225
-                this._audioContext = new AudioContext({
226
-                    sampleRate: 44100
227
-                });
228 238
                 this._audioSource
229 239
                     = this._audioContext.createMediaStreamSource(stream);
230 240
                 this._audioProcessingNode

Loading…
Annulla
Salva