diff --git a/asm/libraries/opus b/asm/libraries/opus index b97dd67f..655cc54c 160000 --- a/asm/libraries/opus +++ b/asm/libraries/opus @@ -1 +1 @@ -Subproject commit b97dd67fdc75a39d0fc99ceee573921ba3e73b1f +Subproject commit 655cc54c564b84ef2827f0b2152ce3811046201e diff --git a/asm/src/opus.cpp b/asm/src/opus.cpp index a86e8b2f..f10d40de 100644 --- a/asm/src/opus.cpp +++ b/asm/src/opus.cpp @@ -73,6 +73,7 @@ extern "C" { printf("Initialize opus. (Channel count: %d Sample rate: %d Type: %d)!\n", channelCount, 48000, type); auto codec = new OpusHandle{}; codec->opusType = type; + codec->channelCount = channelCount; if(!reinitialize_decoder(codec)) return nullptr; if(!reinitialize_encoder(codec)) return nullptr; return codec; diff --git a/shared/js/codec/CodecWrapper.ts b/shared/js/codec/CodecWrapper.ts index 8394eb26..a1824e7c 100644 --- a/shared/js/codec/CodecWrapper.ts +++ b/shared/js/codec/CodecWrapper.ts @@ -68,9 +68,11 @@ class CodecWrapper extends BasicCodec { array[index] = data.data[index]; let audioBuf = this._audioContext.createBuffer(this.channelCount, array.length / this.channelCount, this._codecSampleRate); - for (let channel = 0; channel < this.channelCount; channel++) - for (let offset = 0; offset < audioBuf.length; offset++) - audioBuf.getChannelData(channel)[offset] = array[channel * audioBuf.length + offset]; + for (let channel = 0; channel < this.channelCount; channel++) { + for (let offset = 0; offset < audioBuf.length; offset++) { + audioBuf.getChannelData(channel)[offset] = array[channel + offset * 2]; + } + } resolve(audioBuf); } else { reject(data.message); diff --git a/shared/js/voice/VoiceRecorder.ts b/shared/js/voice/VoiceRecorder.ts index 33f1836e..bf28d8d8 100644 --- a/shared/js/voice/VoiceRecorder.ts +++ b/shared/js/voice/VoiceRecorder.ts @@ -36,7 +36,7 @@ if(!AudioBuffer.prototype.copyToChannel) { //Webkit does not implement this func class VoiceRecorder { private static readonly CHANNEL = 0; - private static readonly CHANNELS = 1; + private static readonly CHANNELS = 2; private static readonly BUFFER_SIZE = 1024 * 4; handle: VoiceConnection; diff --git a/shared/js/workers/codec/OpusCodec.ts b/shared/js/workers/codec/OpusCodec.ts index 9ca65348..4af2c042 100644 --- a/shared/js/workers/codec/OpusCodec.ts +++ b/shared/js/workers/codec/OpusCodec.ts @@ -95,6 +95,7 @@ class OpusWorker implements CodecWorker { if (result < 0) { return "invalid result on decode (" + result + ")"; } + console.log("Result: %o | Channel count %o", result, this.channelCount); return Module.HEAPF32.slice(this.decodeBuffer.byteOffset / 4, (this.decodeBuffer.byteOffset / 4) + (result * this.channelCount)); }