From 77cc8ef72062d64a3afc0fe61a629a11951beda7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 3 Apr 2016 15:04:01 -0700 Subject: [PATCH] GUAC-1511: Use constant buffer size. --- .../src/main/webapp/modules/AudioRecorder.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js index 5b7b1ca7e..9e5fba663 100644 --- a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js +++ b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js @@ -114,6 +114,18 @@ Guacamole.AudioRecorder.getInstance = function getInstance(stream, mimetype) { */ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { + /** + * The size of audio buffer to request from the Web Audio API when + * recording or processing audio, in sample-frames. This must be a power of + * two between 256 and 16384 inclusive, as required by + * AudioContext.createScriptProcessor(). + * + * @private + * @constant + * @type {Number} + */ + var BUFFER_SIZE = 512; + /** * The format of audio this recorder will encode. * @@ -171,16 +183,6 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { */ var maxSampleValue = (format.bytesPerSample === 1) ? 128 : 32768; - /** - * The size of audio buffer to request from the Web Audio API when - * recording audio. This must be a power of two between 256 and 16384 - * inclusive, as required by AudioContext.createScriptProcessor(). - * - * @private - * @type {Number} - */ - var bufferSize = format.bytesPerSample * 256; - /** * Converts the given AudioBuffer into an audio packet, ready for streaming * along the underlying output stream. Unlike the raw audio packets used by @@ -232,7 +234,7 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { getUserMedia({ 'audio' : true }, function streamReceived(mediaStream) { // Create processing node which receives appropriately-sized audio buffers - var processor = context.createScriptProcessor(bufferSize, format.channels, format.channels); + var processor = context.createScriptProcessor(BUFFER_SIZE, format.channels, format.channels); processor.connect(context.destination); // Send blobs when audio buffers are received