Refactor Audio API and remove source-positioning related code
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
package com.bartlomiejpluta.base.api.audio;
|
|
||||||
|
|
||||||
import org.joml.Vector3fc;
|
|
||||||
|
|
||||||
public interface Listener {
|
|
||||||
|
|
||||||
void setPosition(Vector3fc position);
|
|
||||||
|
|
||||||
void setSpeed(Vector3fc speed);
|
|
||||||
|
|
||||||
void setOrientation(Vector3fc at, Vector3fc up);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.bartlomiejpluta.base.api.audio;
|
package com.bartlomiejpluta.base.api.audio;
|
||||||
|
|
||||||
import org.joml.Vector3fc;
|
|
||||||
|
|
||||||
public interface Sound {
|
public interface Sound {
|
||||||
void play();
|
void play();
|
||||||
|
|
||||||
@@ -14,10 +12,4 @@ public interface Sound {
|
|||||||
void setGain(float gain);
|
void setGain(float gain);
|
||||||
|
|
||||||
void setRepeat(boolean repeat);
|
void setRepeat(boolean repeat);
|
||||||
|
|
||||||
void setRelative(boolean relative);
|
|
||||||
|
|
||||||
void setPosition(Vector3fc position);
|
|
||||||
|
|
||||||
void setSpeed(Vector3fc speed);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ public class DefaultAudioEngine implements AudioEngine {
|
|||||||
throw new AppException("Audio buffer with name [%s] does not exist", name);
|
throw new AppException("Audio buffer with name [%s] does not exist", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var source = new AudioSource();
|
var source = new AudioSource(buffer);
|
||||||
source.setBuffer(buffer);
|
|
||||||
|
|
||||||
sources.add(source);
|
sources.add(source);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.bartlomiejpluta.base.engine.core.al.listener;
|
package com.bartlomiejpluta.base.engine.core.al.listener;
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.api.audio.Listener;
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.joml.Vector3fc;
|
import org.joml.Vector3fc;
|
||||||
|
|
||||||
import static org.lwjgl.openal.AL10.*;
|
import static org.lwjgl.openal.AL10.*;
|
||||||
import static org.lwjgl.openal.AL11.alListener3f;
|
import static org.lwjgl.openal.AL11.alListener3f;
|
||||||
|
|
||||||
public class AudioListener implements Listener {
|
public class AudioListener {
|
||||||
|
|
||||||
public AudioListener() {
|
public AudioListener() {
|
||||||
this(new Vector3f(0, 0, 0));
|
this(new Vector3f(0, 0, 0));
|
||||||
@@ -18,17 +17,14 @@ public class AudioListener implements Listener {
|
|||||||
alListener3f(AL_VELOCITY, 0, 0, 0);
|
alListener3f(AL_VELOCITY, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Vector3fc position) {
|
public void setPosition(Vector3fc position) {
|
||||||
alListener3f(AL_POSITION, position.x(), position.y(), position.z());
|
alListener3f(AL_POSITION, position.x(), position.y(), position.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSpeed(Vector3fc speed) {
|
public void setSpeed(Vector3fc speed) {
|
||||||
alListener3f(AL_VELOCITY, speed.x(), speed.y(), speed.z());
|
alListener3f(AL_VELOCITY, speed.x(), speed.y(), speed.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOrientation(Vector3fc at, Vector3fc up) {
|
public void setOrientation(Vector3fc at, Vector3fc up) {
|
||||||
var data = new float[6];
|
var data = new float[6];
|
||||||
data[0] = at.x();
|
data[0] = at.x();
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import static org.lwjgl.openal.AL10.*;
|
|||||||
import static org.lwjgl.openal.AL11.alGenSources;
|
import static org.lwjgl.openal.AL11.alGenSources;
|
||||||
|
|
||||||
public class AudioSource implements Sound, Disposable {
|
public class AudioSource implements Sound, Disposable {
|
||||||
private final int id = alGenSources();
|
private final int id;
|
||||||
|
|
||||||
|
public AudioSource(AudioBuffer buffer) {
|
||||||
|
this.id = alGenSources();
|
||||||
|
|
||||||
public void setBuffer(AudioBuffer buffer) {
|
|
||||||
stop();
|
stop();
|
||||||
alSourcei(id, AL_BUFFER, buffer.getId());
|
alSourcei(id, AL_BUFFER, buffer.getId());
|
||||||
}
|
}
|
||||||
@@ -20,16 +22,18 @@ public class AudioSource implements Sound, Disposable {
|
|||||||
alSourcef(id, param, value);
|
alSourcef(id, param, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Vector3fc position) {
|
public void setPosition(Vector3fc position) {
|
||||||
alSource3f(id, AL_POSITION, position.x(), position.y(), position.z());
|
alSource3f(id, AL_POSITION, position.x(), position.y(), position.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSpeed(Vector3fc speed) {
|
public void setSpeed(Vector3fc speed) {
|
||||||
alSource3f(id, AL_VELOCITY, speed.x(), speed.y(), speed.z());
|
alSource3f(id, AL_VELOCITY, speed.x(), speed.y(), speed.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRelative(boolean relative) {
|
||||||
|
alSourcei(id, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGain(float gain) {
|
public void setGain(float gain) {
|
||||||
alSourcef(id, AL_GAIN, gain);
|
alSourcef(id, AL_GAIN, gain);
|
||||||
@@ -60,11 +64,6 @@ public class AudioSource implements Sound, Disposable {
|
|||||||
alSourcei(id, AL_LOOPING, repeat ? AL_TRUE : AL_FALSE);
|
alSourcei(id, AL_LOOPING, repeat ? AL_TRUE : AL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRelative(boolean relative) {
|
|
||||||
alSourcei(id, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
stop();
|
stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user