Skip to content

Commit

Permalink
muaz-khan#446 StereoAudioRecorder updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Oct 2, 2018
1 parent adbab9c commit 9d9d69c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
32 changes: 21 additions & 11 deletions RecordRTC.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// Last time updated: 2018-09-15 5:28:20 PM UTC
// Last time updated: 2018-10-02 1:32:58 PM UTC

// ________________
// RecordRTC v5.4.9
Expand Down Expand Up @@ -2505,7 +2505,7 @@ function StereoAudioRecorder(mediaStream, config) {
}

if (!config.disableLogs) {
console.log('StereoAudioRecorder is set to record number of channels: ', numberOfAudioChannels);
console.log('StereoAudioRecorder is set to record number of channels: ' + numberOfAudioChannels);
}

// if any Track within the MediaStream is muted or not enabled at any time,
Expand Down Expand Up @@ -2731,7 +2731,7 @@ function StereoAudioRecorder(mediaStream, config) {
});
}

if (isEdge || /*isOpera || */ isSafari || config.noWorker) {
if (config.noWorker) {
mergeAudioBuffers(config, function(data) {
callback(data.buffer, data.view);
});
Expand Down Expand Up @@ -2788,7 +2788,8 @@ function StereoAudioRecorder(mediaStream, config) {
numberOfAudioChannels: numberOfAudioChannels,
internalInterleavedLength: recordingLength,
leftBuffers: leftchannel,
rightBuffers: numberOfAudioChannels === 1 ? [] : rightchannel
rightBuffers: numberOfAudioChannels === 1 ? [] : rightchannel,
noWorker: config.noWorker
}, function(buffer, view) {
/**
* @property {Blob} blob - The recorded blob object.
Expand Down Expand Up @@ -2836,6 +2837,13 @@ function StereoAudioRecorder(mediaStream, config) {
});
};

if(typeof Storage === 'undefined') {
var Storage = {
AudioContextConstructor: null,
AudioContext: window.AudioContext || window.webkitAudioContext
};
}

if (!Storage.AudioContextConstructor) {
Storage.AudioContextConstructor = new Storage.AudioContext();
}
Expand Down Expand Up @@ -2868,7 +2876,7 @@ function StereoAudioRecorder(mediaStream, config) {

if (legalBufferValues.indexOf(bufferSize) === -1) {
if (!config.disableLogs) {
console.warn('Legal values for buffer-size are ' + JSON.stringify(legalBufferValues, null, '\t'));
console.log('Legal values for buffer-size are ' + JSON.stringify(legalBufferValues, null, '\t'));
}
}

Expand Down Expand Up @@ -2909,16 +2917,13 @@ function StereoAudioRecorder(mediaStream, config) {
if (sampleRate < 22050 || sampleRate > 96000) {
// Ref: http://stackoverflow.com/a/26303918/552182
if (!config.disableLogs) {
console.warn('sample-rate must be under range 22050 and 96000.');
console.log('sample-rate must be under range 22050 and 96000.');
}
}

if (!config.disableLogs) {
console.log('sample-rate', sampleRate);
console.log('buffer-size', bufferSize);

if (config.desiredSampRate) {
console.log('Desired sample-rate', config.desiredSampRate);
console.log('Desired sample-rate: ' + config.desiredSampRate);
}
}

Expand Down Expand Up @@ -3089,7 +3094,12 @@ function StereoAudioRecorder(mediaStream, config) {
jsAudioNode.onaudioprocess = onAudioProcessDataAvailable;

// to prevent self audio to be connected with speakers
jsAudioNode.connect(context.destination);
if(context.createMediaStreamDestination) {
jsAudioNode.connect(context.createMediaStreamDestination());
}
else {
jsAudioNode.connect(context.destination);
}

// export raw PCM
this.leftchannel = leftchannel;
Expand Down
8 changes: 4 additions & 4 deletions RecordRTC.min.js

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions dev/StereoAudioRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function StereoAudioRecorder(mediaStream, config) {
}

if (!config.disableLogs) {
console.log('StereoAudioRecorder is set to record number of channels: ', numberOfAudioChannels);
console.log('StereoAudioRecorder is set to record number of channels: ' + numberOfAudioChannels);
}

// if any Track within the MediaStream is muted or not enabled at any time,
Expand Down Expand Up @@ -294,7 +294,7 @@ function StereoAudioRecorder(mediaStream, config) {
});
}

if (isEdge || /*isOpera || */ isSafari || config.noWorker) {
if (config.noWorker) {
mergeAudioBuffers(config, function(data) {
callback(data.buffer, data.view);
});
Expand Down Expand Up @@ -351,7 +351,8 @@ function StereoAudioRecorder(mediaStream, config) {
numberOfAudioChannels: numberOfAudioChannels,
internalInterleavedLength: recordingLength,
leftBuffers: leftchannel,
rightBuffers: numberOfAudioChannels === 1 ? [] : rightchannel
rightBuffers: numberOfAudioChannels === 1 ? [] : rightchannel,
noWorker: config.noWorker
}, function(buffer, view) {
/**
* @property {Blob} blob - The recorded blob object.
Expand Down Expand Up @@ -399,6 +400,13 @@ function StereoAudioRecorder(mediaStream, config) {
});
};

if (typeof Storage === 'undefined') {
var Storage = {
AudioContextConstructor: null,
AudioContext: window.AudioContext || window.webkitAudioContext
};
}

if (!Storage.AudioContextConstructor) {
Storage.AudioContextConstructor = new Storage.AudioContext();
}
Expand Down Expand Up @@ -431,7 +439,7 @@ function StereoAudioRecorder(mediaStream, config) {

if (legalBufferValues.indexOf(bufferSize) === -1) {
if (!config.disableLogs) {
console.warn('Legal values for buffer-size are ' + JSON.stringify(legalBufferValues, null, '\t'));
console.log('Legal values for buffer-size are ' + JSON.stringify(legalBufferValues, null, '\t'));
}
}

Expand Down Expand Up @@ -472,16 +480,13 @@ function StereoAudioRecorder(mediaStream, config) {
if (sampleRate < 22050 || sampleRate > 96000) {
// Ref: http://stackoverflow.com/a/26303918/552182
if (!config.disableLogs) {
console.warn('sample-rate must be under range 22050 and 96000.');
console.log('sample-rate must be under range 22050 and 96000.');
}
}

if (!config.disableLogs) {
console.log('sample-rate', sampleRate);
console.log('buffer-size', bufferSize);

if (config.desiredSampRate) {
console.log('Desired sample-rate', config.desiredSampRate);
console.log('Desired sample-rate: ' + config.desiredSampRate);
}
}

Expand Down Expand Up @@ -652,7 +657,11 @@ function StereoAudioRecorder(mediaStream, config) {
jsAudioNode.onaudioprocess = onAudioProcessDataAvailable;

// to prevent self audio to be connected with speakers
jsAudioNode.connect(context.destination);
if (context.createMediaStreamDestination) {
jsAudioNode.connect(context.createMediaStreamDestination());
} else {
jsAudioNode.connect(context.destination);
}

// export raw PCM
this.leftchannel = leftchannel;
Expand Down
10 changes: 10 additions & 0 deletions simple-demos/audio-recording.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,20 @@ <h1>Simple Audio Recording using RecordRTC</h1>
bufferSize: 16384
};

if(isSafari || isEdge) {
options.recorderType = StereoAudioRecorder;
}

if(navigator.platform && navigator.platform.toString().toLowerCase().indexOf('win') === -1) {
options.sampleRate = 48000; // or 44100 or remove this line for default
}

if(isSafari) {
options.sampleRate = 44100;
options.bufferSize = 4096;
options.numberOfAudioChannels = 2;
}

if(recorder) {
recorder.destroy();
recorder = null;
Expand Down

0 comments on commit 9d9d69c

Please sign in to comment.