Przeglądaj źródła

fix sampleRate issues in flac and wav

master
Radium Zheng 7 lat temu
rodzic
commit
e03126e422

+ 42
- 3
react/features/local-recording/recording/WavAdapter.js Wyświetl plik

@@ -139,6 +139,43 @@ export class WavAdapter extends RecordingAdapter {
139 139
         return Promise.resolve();
140 140
     }
141 141
 
142
+    /**
143
+     * Implements {@link RecordingAdapter#setMicDevice()}.
144
+     *
145
+     * @inheritdoc
146
+     */
147
+    setMicDevice(micDeviceId) {
148
+        return this._replaceMic(micDeviceId);
149
+    }
150
+
151
+    /**
152
+     * Replaces the current microphone MediaStream.
153
+     *
154
+     * @param {*} micDeviceId - New microphone ID.
155
+     * @returns {Promise}
156
+     */
157
+    _replaceMic(micDeviceId) {
158
+        if (this._audioContext && this._audioProcessingNode) {
159
+            return new Promise((resolve, reject) => {
160
+                this._getAudioStream(micDeviceId).then(newStream => {
161
+                    const newSource = this._audioContext
162
+                        .createMediaStreamSource(newStream);
163
+
164
+                    this._audioSource.disconnect();
165
+                    newSource.connect(this._audioProcessingNode);
166
+                    this._stream = newStream;
167
+                    this._audioSource = newSource;
168
+                    resolve();
169
+                })
170
+                .catch(() => {
171
+                    reject();
172
+                });
173
+            });
174
+        }
175
+
176
+        return Promise.resolve();
177
+    }
178
+
142 179
     /**
143 180
      * Creates a WAVE file header.
144 181
      *
@@ -209,7 +246,9 @@ export class WavAdapter extends RecordingAdapter {
209 246
             this._getAudioStream(micDeviceId)
210 247
             .then(stream => {
211 248
                 this._stream = stream;
212
-                this._audioContext = new AudioContext();
249
+                this._audioContext = new AudioContext({
250
+                    sampleRate: WAV_SAMPLE_RATE
251
+                });
213 252
                 this._audioSource
214 253
                     = this._audioContext.createMediaStreamSource(stream);
215 254
                 this._audioProcessingNode
@@ -255,7 +294,7 @@ export class WavAdapter extends RecordingAdapter {
255 294
      *
256 295
      * @private
257 296
      * @param {*} buffers - The stored buffers.
258
-     * @param {*} length - Total length (in bytes).
297
+     * @param {*} length - Total length (number of samples).
259 298
      * @returns {Blob}
260 299
      */
261 300
     _exportMonoWAV(buffers, length) {
@@ -265,7 +304,7 @@ export class WavAdapter extends RecordingAdapter {
265 304
         //  ...
266 305
         //  buffers[n] = Float32Array object (audio data)
267 306
 
268
-        const dataLength = length * 2; // why multiply by 2 here?
307
+        const dataLength = length * 2; // each sample = 16 bit = 2 bytes
269 308
         const buffer = new ArrayBuffer(44 + dataLength);
270 309
         const view = new DataView(buffer);
271 310
 

+ 22
- 1
react/features/local-recording/recording/flac/FlacAdapter.js Wyświetl plik

@@ -16,10 +16,29 @@ const logger = require('jitsi-meet-logger').getLogger(__filename);
16 16
  */
17 17
 export class FlacAdapter extends RecordingAdapter {
18 18
 
19
+    /**
20
+     * Instance of flacEncodeWorker.
21
+     */
19 22
     _encoder = null;
23
+
24
+    /**
25
+     * The {@code AudioContext} instance.
26
+     */
20 27
     _audioContext = null;
28
+
29
+    /**
30
+     * The {@code ScriptProcessorNode} instance.
31
+     */
21 32
     _audioProcessingNode = null;
33
+
34
+    /**
35
+     * The {@code MediaStreamAudioSourceNode} instance.
36
+     */
22 37
     _audioSource = null;
38
+
39
+    /**
40
+     * The {@code MediaStream} instance, representing the current audio device.
41
+     */
23 42
     _stream = null;
24 43
 
25 44
     /**
@@ -206,7 +225,9 @@ export class FlacAdapter extends RecordingAdapter {
206 225
             this._getAudioStream(micDeviceId)
207 226
             .then(stream => {
208 227
                 this._stream = stream;
209
-                this._audioContext = new AudioContext();
228
+                this._audioContext = new AudioContext({
229
+                    sampleRate: 44100
230
+                });
210 231
                 this._audioSource
211 232
                     = this._audioContext.createMediaStreamSource(stream);
212 233
                 this._audioProcessingNode

Ładowanie…
Anuluj
Zapisz