GUAC-1511: Apply basic resampling when copying audio from source to destination.

This commit is contained in:
Michael Jumper
2016-04-03 16:16:35 -07:00
parent 77cc8ef720
commit 1047afbb43

View File

@@ -200,8 +200,12 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) {
*/ */
var toSampleArray = function toSampleArray(audioBuffer) { var toSampleArray = function toSampleArray(audioBuffer) {
// Calculate the number of samples in both input and output
var inSamples = audioBuffer.length;
var outSamples = Math.floor(audioBuffer.duration * format.rate);
// Get array for raw PCM storage // Get array for raw PCM storage
var data = new SampleArray(audioBuffer.length * format.channels); var data = new SampleArray(outSamples * format.channels);
// Convert each channel // Convert each channel
for (var channel = 0; channel < format.channels; channel++) { for (var channel = 0; channel < format.channels; channel++) {
@@ -210,9 +214,14 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) {
// Fill array with data from audio buffer channel // Fill array with data from audio buffer channel
var offset = channel; var offset = channel;
for (var i = 0; i < audioData.length; i++) { for (var i = 0; i < outSamples; i++) {
data[offset] = audioData[i] * maxSampleValue;
// Apply naiive resampling
var inOffset = Math.floor(i / outSamples * inSamples);
data[offset] = Math.floor(audioData[inOffset] * maxSampleValue);
offset += format.channels; offset += format.channels;
} }
} }