mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUAC-1511: Apply basic resampling when copying audio from source to destination.
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user