remove OPUS, re-add ogg/jorbis

This commit is contained in:
Sen 2025-03-25 12:41:18 +01:00
parent 920405d8c5
commit a6f20d815e
38 changed files with 9910 additions and 46 deletions

View file

@ -4,12 +4,7 @@ import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.util.opus.OpusFile;
import game.audio.CodecJOrbis;
import game.log.Log;
import game.rng.Random;
import game.util.FileUtils;
@ -139,23 +134,22 @@ public enum SoundEvent {
for(int z = 0; z < entry.sounds.length; z++) {
String sound = entry.sounds[z];
Log.SOUND.trace("Lade Sound %s", sound);
entry.buffers[z] = readOpus("sounds/" + sound + ".opus");
entry.buffers[z] = readOgg("sounds/" + sound + ".ogg");
}
}
}
private static short[] readOpus(String filename) {
private static short[] readOgg(String filename) {
InputStream in = null;
byte[] data;
try {
in = new BufferedInputStream(FileUtils.getResource(filename));
data = FileUtils.readBytes(in);
return CodecJOrbis.readAll(in);
}
catch(FileNotFoundException e) {
Log.IO.error("Fehler beim Lesen von OPUS-Datei '%s': Datei nicht gefunden", filename);
return null;
}
catch(IOException e) {
catch(Exception e) {
Log.IO.error("Fehler beim Lesen von OPUS-Datei '%s': %s", filename, e.getMessage());
return null;
}
@ -167,40 +161,6 @@ public enum SoundEvent {
catch(IOException e) {
}
}
ByteBuffer buf = BufferUtils.createByteBuffer(data.length);
buf.put(data);
buf.flip();
long fd = OpusFile.op_open_memory(buf, null);
if(fd == 0L) {
Log.IO.error("Fehler beim Lesen von OPUS-Datei '%s': Falsches oder fehlerhaftes Format", filename);
return null;
}
if(OpusFile.op_channel_count(fd, -1) != 1) {
Log.IO.error("Fehler beim Lesen von OPUS-Datei '%s': Falsches Anzahl von Kanälen (!= 1)", filename);
OpusFile.op_free(fd);
return null;
}
long samples = OpusFile.op_pcm_total(fd, -1);
if(samples < 0L) {
Log.IO.error("Fehler beim Lesen von OPUS-Datei '%s': E/A-Fehler", filename);
OpusFile.op_free(fd);
return null;
}
ShortBuffer pcm = BufferUtils.createShortBuffer((int)samples);
int state;
while((state = OpusFile.op_read(fd, pcm, null)) > 0L) {
pcm.position(pcm.position() + state);
}
if(state < 0L) {
Log.IO.error("Fehler beim Lesen von OPUS-Datei '%s': E/A-Fehler", filename);
OpusFile.op_free(fd);
return null;
}
OpusFile.op_free(fd);
short[] decoded = new short[(int)samples];
pcm.rewind();
pcm.get(decoded);
return decoded;
}
private SoundEvent(String ... sounds) {