Files
AsminVoicechat/source/decompiled/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java
T
asminme bbccd4a815
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
first commit
2026-10-24 15:18:03 +02:00

83 lines
2.4 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package de.maxhenkel.voicechat.plugins.impl.opus;
import de.maxhenkel.voicechat.concentus.OpusApplication;
import de.maxhenkel.voicechat.concentus.OpusEncoder;
public class JavaOpusEncoderImpl
implements de.maxhenkel.voicechat.api.opus.OpusEncoder {
protected OpusEncoder opusEncoder;
protected byte[] buffer;
protected int sampleRate;
protected int frameSize;
protected int maxPayloadSize;
protected OpusApplication application;
public JavaOpusEncoderImpl(int sampleRate, int frameSize, int maxPayloadSize, OpusApplication application) {
this.sampleRate = sampleRate;
this.frameSize = frameSize;
this.maxPayloadSize = maxPayloadSize;
this.application = application;
this.buffer = new byte[maxPayloadSize];
this.open();
}
private void open() {
if (this.opusEncoder != null) {
return;
}
try {
this.opusEncoder = new OpusEncoder(this.sampleRate, 1, this.application);
this.opusEncoder.setUseInbandFEC(true);
this.opusEncoder.setPacketLossPercent(5);
}
catch (Exception e) {
throw new IllegalStateException("Opus encoder error " + e.getMessage());
}
}
@Override
public byte[] encode(short[] rawAudio) {
int result;
if (this.isClosed()) {
throw new IllegalStateException("Encoder is closed");
}
try {
result = this.opusEncoder.encode(rawAudio, 0, this.frameSize, this.buffer, 0, this.buffer.length);
}
catch (Exception e) {
throw new RuntimeException("Failed to encode audio data: " + e.getMessage());
}
if (result < 0) {
throw new RuntimeException("Failed to encode audio data");
}
byte[] audio = new byte[result];
System.arraycopy(this.buffer, 0, audio, 0, result);
return audio;
}
@Override
public void resetState() {
if (this.isClosed()) {
throw new IllegalStateException("Encoder is closed");
}
this.opusEncoder.resetState();
}
@Override
public boolean isClosed() {
return this.opusEncoder == null;
}
@Override
public void close() {
if (this.isClosed()) {
return;
}
this.opusEncoder = null;
}
}