fix sampleRate issues in flac and wav
This commit is contained in:
parent
61652c69b3
commit
e03126e422
|
@ -139,6 +139,43 @@ export class WavAdapter extends RecordingAdapter {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements {@link RecordingAdapter#setMicDevice()}.
|
||||||
|
*
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
setMicDevice(micDeviceId) {
|
||||||
|
return this._replaceMic(micDeviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces the current microphone MediaStream.
|
||||||
|
*
|
||||||
|
* @param {*} micDeviceId - New microphone ID.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
_replaceMic(micDeviceId) {
|
||||||
|
if (this._audioContext && this._audioProcessingNode) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._getAudioStream(micDeviceId).then(newStream => {
|
||||||
|
const newSource = this._audioContext
|
||||||
|
.createMediaStreamSource(newStream);
|
||||||
|
|
||||||
|
this._audioSource.disconnect();
|
||||||
|
newSource.connect(this._audioProcessingNode);
|
||||||
|
this._stream = newStream;
|
||||||
|
this._audioSource = newSource;
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a WAVE file header.
|
* Creates a WAVE file header.
|
||||||
*
|
*
|
||||||
|
@ -209,7 +246,9 @@ export class WavAdapter extends RecordingAdapter {
|
||||||
this._getAudioStream(micDeviceId)
|
this._getAudioStream(micDeviceId)
|
||||||
.then(stream => {
|
.then(stream => {
|
||||||
this._stream = stream;
|
this._stream = stream;
|
||||||
this._audioContext = new AudioContext();
|
this._audioContext = new AudioContext({
|
||||||
|
sampleRate: WAV_SAMPLE_RATE
|
||||||
|
});
|
||||||
this._audioSource
|
this._audioSource
|
||||||
= this._audioContext.createMediaStreamSource(stream);
|
= this._audioContext.createMediaStreamSource(stream);
|
||||||
this._audioProcessingNode
|
this._audioProcessingNode
|
||||||
|
@ -255,7 +294,7 @@ export class WavAdapter extends RecordingAdapter {
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} buffers - The stored buffers.
|
* @param {*} buffers - The stored buffers.
|
||||||
* @param {*} length - Total length (in bytes).
|
* @param {*} length - Total length (number of samples).
|
||||||
* @returns {Blob}
|
* @returns {Blob}
|
||||||
*/
|
*/
|
||||||
_exportMonoWAV(buffers, length) {
|
_exportMonoWAV(buffers, length) {
|
||||||
|
@ -265,7 +304,7 @@ export class WavAdapter extends RecordingAdapter {
|
||||||
// ...
|
// ...
|
||||||
// buffers[n] = Float32Array object (audio data)
|
// buffers[n] = Float32Array object (audio data)
|
||||||
|
|
||||||
const dataLength = length * 2; // why multiply by 2 here?
|
const dataLength = length * 2; // each sample = 16 bit = 2 bytes
|
||||||
const buffer = new ArrayBuffer(44 + dataLength);
|
const buffer = new ArrayBuffer(44 + dataLength);
|
||||||
const view = new DataView(buffer);
|
const view = new DataView(buffer);
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,29 @@ const logger = require('jitsi-meet-logger').getLogger(__filename);
|
||||||
*/
|
*/
|
||||||
export class FlacAdapter extends RecordingAdapter {
|
export class FlacAdapter extends RecordingAdapter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of flacEncodeWorker.
|
||||||
|
*/
|
||||||
_encoder = null;
|
_encoder = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@code AudioContext} instance.
|
||||||
|
*/
|
||||||
_audioContext = null;
|
_audioContext = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@code ScriptProcessorNode} instance.
|
||||||
|
*/
|
||||||
_audioProcessingNode = null;
|
_audioProcessingNode = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@code MediaStreamAudioSourceNode} instance.
|
||||||
|
*/
|
||||||
_audioSource = null;
|
_audioSource = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@code MediaStream} instance, representing the current audio device.
|
||||||
|
*/
|
||||||
_stream = null;
|
_stream = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,7 +225,9 @@ export class FlacAdapter extends RecordingAdapter {
|
||||||
this._getAudioStream(micDeviceId)
|
this._getAudioStream(micDeviceId)
|
||||||
.then(stream => {
|
.then(stream => {
|
||||||
this._stream = stream;
|
this._stream = stream;
|
||||||
this._audioContext = new AudioContext();
|
this._audioContext = new AudioContext({
|
||||||
|
sampleRate: 44100
|
||||||
|
});
|
||||||
this._audioSource
|
this._audioSource
|
||||||
= this._audioContext.createMediaStreamSource(stream);
|
= this._audioContext.createMediaStreamSource(stream);
|
||||||
this._audioProcessingNode
|
this._audioProcessingNode
|
||||||
|
|
Loading…
Reference in New Issue