Entire project

This commit is contained in:
Gnarwhal 2024-08-07 04:59:26 +00:00
commit cba41886e5
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
69 changed files with 3982 additions and 0 deletions

View file

@ -0,0 +1,38 @@
package com.gnarly.engine.audio;
import org.lwjgl.openal.AL10;
public class Sound {
private int buffer;
private int sourceId;
public Sound(String path) {
sourceId = AL10.alGenSources();
buffer = AL10.alGenBuffers();
WaveData waveData = WaveData.create(path);
AL10.alBufferData(buffer, waveData.format, waveData.data, waveData.samplerate);
AL10.alSourcei(sourceId, AL10.AL_BUFFER, buffer);
AL10.alSourcef(sourceId, AL10.AL_GAIN, 1);
AL10.alSourcef(sourceId, AL10.AL_PITCH, 1);
}
public void play(boolean loop) {
AL10.alSourcei(sourceId, AL10.AL_LOOPING, loop ? 1 : 0);
AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 0);
AL10.alSourcePlay(sourceId);
}
public void stop() {
AL10.alSourceStop(sourceId);
}
public void setVolume(float volume) {
AL10.alSourcef(sourceId, AL10.AL_GAIN, volume);
}
public void destroy() {
AL10.alDeleteBuffers(buffer);
AL10.alDeleteSources(sourceId);
}
}