Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
117 lines
3.9 KiB
Java
117 lines
3.9 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* javax.annotation.Nullable
|
|
*/
|
|
package de.maxhenkel.voicechat.plugins.impl.opus;
|
|
|
|
import de.maxhenkel.voicechat.Voicechat;
|
|
import de.maxhenkel.voicechat.api.opus.OpusDecoder;
|
|
import de.maxhenkel.voicechat.concentus.OpusException;
|
|
import javax.annotation.Nullable;
|
|
|
|
public class JavaOpusDecoderImpl
|
|
implements OpusDecoder {
|
|
protected de.maxhenkel.voicechat.concentus.OpusDecoder opusDecoder;
|
|
protected short[] buffer;
|
|
protected int sampleRate;
|
|
|
|
public JavaOpusDecoderImpl(int sampleRate, int frameSize) {
|
|
this.sampleRate = sampleRate;
|
|
this.buffer = new short[frameSize];
|
|
this.open();
|
|
}
|
|
|
|
private void open() {
|
|
if (this.opusDecoder != null) {
|
|
return;
|
|
}
|
|
try {
|
|
this.opusDecoder = new de.maxhenkel.voicechat.concentus.OpusDecoder(this.sampleRate, 1);
|
|
}
|
|
catch (OpusException e) {
|
|
throw new IllegalStateException("Failed to create Opus decoder", e);
|
|
}
|
|
Voicechat.LOGGER.debug("Initializing Java Opus decoder with sample rate {} Hz, frame size {} bytes", this.sampleRate, this.buffer.length);
|
|
}
|
|
|
|
@Override
|
|
public short[] decode(@Nullable byte[] data) {
|
|
int result;
|
|
if (this.isClosed()) {
|
|
throw new IllegalStateException("Decoder is closed");
|
|
}
|
|
try {
|
|
result = data == null || data.length == 0 ? this.opusDecoder.decode(null, 0, 0, this.buffer, 0, this.buffer.length, true) : this.opusDecoder.decode(data, 0, data.length, this.buffer, 0, this.buffer.length, false);
|
|
}
|
|
catch (Exception e) {
|
|
throw new RuntimeException("Failed to decode audio", e);
|
|
}
|
|
short[] audio = new short[result];
|
|
System.arraycopy(this.buffer, 0, audio, 0, result);
|
|
return audio;
|
|
}
|
|
|
|
@Override
|
|
public short[][] decode(byte[] data, int frames) {
|
|
if (this.isClosed()) {
|
|
throw new IllegalStateException("Decoder is closed");
|
|
}
|
|
if (frames <= 0) {
|
|
throw new IllegalArgumentException("Frames must be greater than 0");
|
|
}
|
|
if (data == null || data.length == 0) {
|
|
throw new IllegalArgumentException("Data must not be null or empty");
|
|
}
|
|
short[][] recovered = new short[frames][];
|
|
try {
|
|
int result;
|
|
if (frames > 2) {
|
|
for (int i = 0; i < frames - 2; ++i) {
|
|
result = this.opusDecoder.decode(null, 0, 0, this.buffer, 0, this.buffer.length, true);
|
|
short[] audio = new short[result];
|
|
System.arraycopy(this.buffer, 0, audio, 0, result);
|
|
recovered[i] = audio;
|
|
}
|
|
}
|
|
if (frames > 1) {
|
|
result = this.opusDecoder.decode(data, 0, data.length, this.buffer, 0, this.buffer.length, true);
|
|
short[] audio = new short[result];
|
|
System.arraycopy(this.buffer, 0, audio, 0, result);
|
|
recovered[frames - 2] = audio;
|
|
}
|
|
result = this.opusDecoder.decode(data, 0, data.length, this.buffer, 0, this.buffer.length, false);
|
|
short[] audio = new short[result];
|
|
System.arraycopy(this.buffer, 0, audio, 0, result);
|
|
recovered[frames - 1] = audio;
|
|
}
|
|
catch (Exception e) {
|
|
throw new RuntimeException("Failed to decode audio", e);
|
|
}
|
|
return recovered;
|
|
}
|
|
|
|
@Override
|
|
public boolean isClosed() {
|
|
return this.opusDecoder == null;
|
|
}
|
|
|
|
@Override
|
|
public void close() {
|
|
if (this.isClosed()) {
|
|
return;
|
|
}
|
|
this.opusDecoder = null;
|
|
}
|
|
|
|
@Override
|
|
public void resetState() {
|
|
if (this.isClosed()) {
|
|
throw new IllegalStateException("Decoder is closed");
|
|
}
|
|
this.opusDecoder.resetState();
|
|
}
|
|
}
|
|
|