You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/05/24 03:27:54 UTC
[4/6] incubator-guacamole-client git commit: GUACAMOLE-25: Compensate
for underflow/overflow induced by rounding error.
GUACAMOLE-25: Compensate for underflow/overflow induced by rounding error.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/8442f7c3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/8442f7c3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/8442f7c3
Branch: refs/heads/master
Commit: 8442f7c33f7afdb348c362536468c8d1258b3aab
Parents: b36a955
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Apr 29 18:20:25 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Mon May 23 15:00:00 2016 -0700
----------------------------------------------------------------------
.../src/main/webapp/modules/AudioRecorder.js | 31 ++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/8442f7c3/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
index f64e6ee..704d7e7 100644
--- a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
+++ b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
@@ -184,6 +184,24 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) {
var maxSampleValue = (format.bytesPerSample === 1) ? 128 : 32768;
/**
+ * The total number of audio samples read from the local audio input device
+ * over the life of this audio recorder.
+ *
+ * @private
+ * @type {Number}
+ */
+ var readSamples = 0;
+
+ /**
+ * The total number of audio samples written to the underlying Guacamole
+ * connection over the life of this audio recorder.
+ *
+ * @private
+ * @type {Number}
+ */
+ var writtenSamples = 0;
+
+ /**
* Determines the value of the waveform represented by the audio data at
* the given location. If the value cannot be determined exactly as it does
* not correspond to an exact sample within the audio data, the value will
@@ -237,9 +255,18 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) {
*/
var toSampleArray = function toSampleArray(audioBuffer) {
- // Calculate the number of samples in both input and output
+ // Track overall amount of data read
var inSamples = audioBuffer.length;
- var outSamples = Math.floor(audioBuffer.duration * format.rate);
+ readSamples += inSamples;
+
+ // Calculate the total number of samples that should be written as of
+ // the audio data just received and adjust the size of the output
+ // packet accordingly
+ var expectedWrittenSamples = Math.round(readSamples * format.rate / audioBuffer.sampleRate);
+ var outSamples = expectedWrittenSamples - writtenSamples;
+
+ // Update number of samples written
+ writtenSamples += outSamples;
// Get array for raw PCM storage
var data = new SampleArray(outSamples * format.channels);