Cleaned up and formatted code
This commit is contained in:
parent
12dc816760
commit
503963f992
@ -1,6 +1,5 @@
|
||||
package ru.windcorp.progressia.client;
|
||||
|
||||
import ru.windcorp.progressia.client.audio.backend.ALTest;
|
||||
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||
import ru.windcorp.progressia.client.graphics.world.Camera;
|
||||
|
@ -10,29 +10,39 @@ import static org.lwjgl.stb.STBVorbis.*;
|
||||
import static org.lwjgl.openal.AL10.*;
|
||||
|
||||
public class AudioReader {
|
||||
private AudioReader() {};
|
||||
|
||||
//TODO fix converting from mono-stereo
|
||||
private AudioReader() {};
|
||||
|
||||
public static SoundType readAsMono(String AudioFile) {
|
||||
IntBuffer channelBuffer = BufferUtils.createIntBuffer(1);
|
||||
IntBuffer rateBuffer = BufferUtils.createIntBuffer(1);
|
||||
Resource res = ResourceManager.getResource(AudioFile);
|
||||
ShortBuffer rawMonoAudio = decodeVorbis(res, channelBuffer, rateBuffer);
|
||||
// TODO fix converting from mono-stereo
|
||||
|
||||
return new SoundType(rawMonoAudio, AL_FORMAT_MONO16, rateBuffer.get(0));
|
||||
}
|
||||
private static SoundType readAsSpecified(String audioName, int format) {
|
||||
IntBuffer channelBuffer = BufferUtils.createIntBuffer(1);
|
||||
IntBuffer rateBuffer = BufferUtils.createIntBuffer(1);
|
||||
|
||||
public static SoundType readAsStereo(String AudioFile) {
|
||||
IntBuffer channelsBuffer = BufferUtils.createIntBuffer(2);
|
||||
IntBuffer rateBuffer = BufferUtils.createIntBuffer(1);
|
||||
Resource res = ResourceManager.getResource(AudioFile);
|
||||
ShortBuffer rawStereoAudio = decodeVorbis(res, channelsBuffer, rateBuffer);
|
||||
Resource res = ResourceManager.getResource(audioName);
|
||||
|
||||
return new SoundType(rawStereoAudio, AL_FORMAT_STEREO16, rateBuffer.get(0));
|
||||
}
|
||||
ShortBuffer rawAudio = decodeVorbis(res, channelBuffer, rateBuffer);
|
||||
|
||||
private static ShortBuffer decodeVorbis(Resource dataToDecode, IntBuffer channelsBuffer, IntBuffer rateBuffer) {
|
||||
return stb_vorbis_decode_memory(dataToDecode.readAsBytes(), channelsBuffer, rateBuffer);
|
||||
}
|
||||
return new SoundType(rawAudio, format, rateBuffer.get(0));
|
||||
}
|
||||
|
||||
public static SoundType readAsMono(String audioName) {
|
||||
return readAsSpecified(audioName, AL_FORMAT_MONO16);
|
||||
}
|
||||
|
||||
public static SoundType readAsStereo(String audioName) {
|
||||
return readAsSpecified(audioName, AL_FORMAT_STEREO16);
|
||||
}
|
||||
|
||||
private static ShortBuffer decodeVorbis(
|
||||
Resource dataToDecode,
|
||||
IntBuffer channelsBuffer,
|
||||
IntBuffer rateBuffer
|
||||
) {
|
||||
return stb_vorbis_decode_memory(
|
||||
dataToDecode.readAsBytes(),
|
||||
channelsBuffer,
|
||||
rateBuffer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,58 +11,66 @@ import static org.lwjgl.openal.AL10.*;
|
||||
|
||||
public class Listener {
|
||||
|
||||
private static final Listener instance = new Listener();
|
||||
private Listener() {}
|
||||
public static Listener getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private static final Listener INSTANCE = new Listener();
|
||||
|
||||
//Params
|
||||
private final Vec3 position = new Vec3();
|
||||
private final Vec3 velocity = new Vec3();
|
||||
private final Vec3 oriAt = new Vec3();
|
||||
private final Vec3 oriUp = new Vec3();
|
||||
private Listener() {}
|
||||
|
||||
private boolean isClientConnected = false;
|
||||
private Camera.Anchor anchor;
|
||||
public static Listener getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
Client client = ClientState.getInstance();
|
||||
if (client == null) {
|
||||
if (isClientConnected) {
|
||||
isClientConnected = false;
|
||||
resetParams();
|
||||
applyParams();
|
||||
}
|
||||
} else {
|
||||
isClientConnected = true;
|
||||
if (anchor == null) {
|
||||
anchor = client.getCamera().getAnchor();
|
||||
} else {
|
||||
anchor.getCameraPosition(position);
|
||||
float pitch = anchor.getCameraPitch();
|
||||
float yaw = anchor.getCameraYaw();
|
||||
oriAt.set((float) (Math.cos(pitch) * Math.cos(yaw)),
|
||||
(float) (Math.cos(pitch) * Math.sin(yaw)),
|
||||
(float) Math.sin(pitch));
|
||||
oriUp.set((float) (Math.cos(pitch + Math.PI / 2) * Math.cos(yaw)),
|
||||
(float) (Math.cos(pitch + Math.PI / 2) * Math.sin(yaw)),
|
||||
(float) Math.sin(pitch + Math.PI / 2));
|
||||
applyParams();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Params
|
||||
private final Vec3 position = new Vec3();
|
||||
private final Vec3 velocity = new Vec3();
|
||||
private final Vec3 oriAt = new Vec3();
|
||||
private final Vec3 oriUp = new Vec3();
|
||||
|
||||
private void resetParams() {
|
||||
position.set(0f, 0f, 0f);
|
||||
velocity.set(0f, 0f, 0f);
|
||||
oriAt.set(0f, 0f, 0f);
|
||||
oriUp.set(0f, 0f, 0f);
|
||||
}
|
||||
private boolean isClientConnected = false;
|
||||
private Camera.Anchor anchor;
|
||||
|
||||
private void applyParams() {
|
||||
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
||||
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
||||
alListenerfv(AL_ORIENTATION, new float[]{oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z});
|
||||
}
|
||||
public void update() {
|
||||
Client client = ClientState.getInstance();
|
||||
if (client == null) {
|
||||
if (isClientConnected) {
|
||||
isClientConnected = false;
|
||||
resetParams();
|
||||
applyParams();
|
||||
}
|
||||
} else {
|
||||
isClientConnected = true;
|
||||
if (anchor == null) {
|
||||
anchor = client.getCamera().getAnchor();
|
||||
} else {
|
||||
anchor.getCameraPosition(position);
|
||||
float pitch = anchor.getCameraPitch();
|
||||
float yaw = anchor.getCameraYaw();
|
||||
oriAt.set(
|
||||
(float) (Math.cos(pitch) * Math.cos(yaw)),
|
||||
(float) (Math.cos(pitch) * Math.sin(yaw)),
|
||||
(float) Math.sin(pitch)
|
||||
);
|
||||
oriUp.set(
|
||||
(float) (Math.cos(pitch + Math.PI / 2) * Math.cos(yaw)),
|
||||
(float) (Math.cos(pitch + Math.PI / 2) * Math.sin(yaw)),
|
||||
(float) Math.sin(pitch + Math.PI / 2)
|
||||
);
|
||||
applyParams();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetParams() {
|
||||
position.set(0);
|
||||
velocity.set(0);
|
||||
oriAt.set(0);
|
||||
oriUp.set(0);
|
||||
}
|
||||
|
||||
private void applyParams() {
|
||||
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
||||
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
||||
alListenerfv(AL_ORIENTATION, new float[] {
|
||||
oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z
|
||||
});
|
||||
}
|
||||
}
|
@ -7,122 +7,136 @@ import java.nio.FloatBuffer;
|
||||
import static org.lwjgl.openal.AL11.*;
|
||||
|
||||
public class Sound {
|
||||
//Buffers
|
||||
private int audio;
|
||||
private int source;
|
||||
//Characteristics
|
||||
private FloatBuffer position =
|
||||
(FloatBuffer) BufferUtils.createFloatBuffer(3)
|
||||
.put(new float[]{0.0f, 0.0f, 0.0f}).rewind();
|
||||
private FloatBuffer velocity =
|
||||
(FloatBuffer) BufferUtils.createFloatBuffer(3)
|
||||
.put(new float[]{0.0f, 0.0f, 0.0f}).rewind();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
|
||||
public Sound() {
|
||||
}
|
||||
// Buffers
|
||||
private int audio;
|
||||
private int source;
|
||||
|
||||
public Sound(int audio, int source) {
|
||||
setAudio(audio);
|
||||
setSource(source);
|
||||
}
|
||||
// Characteristics
|
||||
private FloatBuffer position = (FloatBuffer) BufferUtils.createFloatBuffer(
|
||||
3
|
||||
).put(new float[] {
|
||||
0.0f, 0.0f, 0.0f
|
||||
}).rewind();
|
||||
|
||||
public Sound(int audio, FloatBuffer position, FloatBuffer velocity, float pitch, float gain)
|
||||
{
|
||||
setAudio(audio);
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
private FloatBuffer velocity = (FloatBuffer) BufferUtils.createFloatBuffer(
|
||||
3
|
||||
).put(new float[] {
|
||||
0.0f, 0.0f, 0.0f
|
||||
}).rewind();
|
||||
|
||||
public Sound(FloatBuffer position, FloatBuffer velocity, float pitch, float gain) {
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
|
||||
public void playOnce() {
|
||||
alSourcePlay(source);
|
||||
}
|
||||
public Sound() {}
|
||||
|
||||
public void playLoop() {
|
||||
alSourcei(source, AL_LOOPING, AL_TRUE);
|
||||
playOnce();
|
||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
public Sound(int audio, int source) {
|
||||
setAudio(audio);
|
||||
setSource(source);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
alSourceStop(source);
|
||||
}
|
||||
public Sound(
|
||||
int audio,
|
||||
FloatBuffer position,
|
||||
FloatBuffer velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
setAudio(audio);
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
alSourcePause(source);
|
||||
}
|
||||
public Sound(
|
||||
FloatBuffer position,
|
||||
FloatBuffer velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
final int state = alGetSourcei(source, AL_SOURCE_STATE);
|
||||
return state == AL_PLAYING;
|
||||
}
|
||||
public void playOnce() {
|
||||
alSourcePlay(source);
|
||||
}
|
||||
|
||||
public int getAudio() {
|
||||
return audio;
|
||||
}
|
||||
public void playLoop() {
|
||||
alSourcei(source, AL_LOOPING, AL_TRUE);
|
||||
playOnce();
|
||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
|
||||
public void setAudio(int audio) {
|
||||
this.audio = audio;
|
||||
}
|
||||
public void stop() {
|
||||
alSourceStop(source);
|
||||
}
|
||||
|
||||
public void setSource(int source) {
|
||||
this.source = source;
|
||||
alSourcei(this.source, AL_BUFFER, audio);
|
||||
}
|
||||
public void pause() {
|
||||
alSourcePause(source);
|
||||
}
|
||||
|
||||
public int getSource() {
|
||||
return source;
|
||||
}
|
||||
public boolean isPlaying() {
|
||||
final int state = alGetSourcei(source, AL_SOURCE_STATE);
|
||||
return state == AL_PLAYING;
|
||||
}
|
||||
|
||||
public int getAudio() {
|
||||
return audio;
|
||||
}
|
||||
|
||||
//OTHER
|
||||
public void setAudio(int audio) {
|
||||
this.audio = audio;
|
||||
}
|
||||
|
||||
public void setPosition(FloatBuffer position) {
|
||||
this.position = position;
|
||||
alSourcefv(source, AL_POSITION, position);
|
||||
}
|
||||
public void setSource(int source) {
|
||||
this.source = source;
|
||||
alSourcei(this.source, AL_BUFFER, audio);
|
||||
}
|
||||
|
||||
public FloatBuffer getPosition() {
|
||||
return position;
|
||||
}
|
||||
public int getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
// OTHER
|
||||
|
||||
public void setVelocity(FloatBuffer velocity) {
|
||||
alSourcefv(source, AL_VELOCITY, velocity);
|
||||
this.velocity = velocity;
|
||||
}
|
||||
public void setPosition(FloatBuffer position) {
|
||||
this.position = position;
|
||||
alSourcefv(source, AL_POSITION, position);
|
||||
}
|
||||
|
||||
public FloatBuffer getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
public FloatBuffer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setVelocity(FloatBuffer velocity) {
|
||||
alSourcefv(source, AL_VELOCITY, velocity);
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
this.pitch = pitch;
|
||||
}
|
||||
public FloatBuffer getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
public void setPitch(float pitch) {
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setGain(float gain) {
|
||||
alSourcef(source, AL_GAIN, gain);
|
||||
this.gain = gain;
|
||||
}
|
||||
public void setGain(float gain) {
|
||||
alSourcef(source, AL_GAIN, gain);
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package ru.windcorp.progressia.client.audio;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.openal.AL;
|
||||
import org.lwjgl.openal.ALC;
|
||||
import org.lwjgl.openal.ALCCapabilities;
|
||||
@ -12,73 +11,97 @@ import static org.lwjgl.openal.ALC10.*;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
||||
public class SoundManager {
|
||||
private static final int SOURCES_NUM = 64;
|
||||
private static int lastSourceIndex = -1;
|
||||
private static final int[] SOURCES = new int[SOURCES_NUM];
|
||||
private static final ArrayBlockingQueue<Sound> SOUNDS = new ArrayBlockingQueue<>(SOURCES_NUM);
|
||||
|
||||
private static long DEVICE;
|
||||
private static final int SOURCES_NUM = 64;
|
||||
private static int lastSourceIndex = -1;
|
||||
private static final int[] SOURCES = new int[SOURCES_NUM];
|
||||
|
||||
public static void initAL() {
|
||||
String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
DEVICE = alcOpenDevice(defaultDeviceName);
|
||||
int[] attributes = {0};
|
||||
long context = alcCreateContext(DEVICE, attributes);
|
||||
alcMakeContextCurrent(context);
|
||||
ALCCapabilities deviceCaps = ALC.createCapabilities(DEVICE);
|
||||
ALCapabilities alcaps = AL.createCapabilities(deviceCaps);
|
||||
checkALError();
|
||||
alGenSources(SOURCES);
|
||||
}
|
||||
private static final ArrayBlockingQueue<Sound> SOUNDS =
|
||||
new ArrayBlockingQueue<>(SOURCES_NUM);
|
||||
|
||||
public static void update() {
|
||||
//Position of the listener
|
||||
Listener.getInstance().update();
|
||||
}
|
||||
private static long device;
|
||||
|
||||
private static void addSound(Sound sound) {
|
||||
if (!SOUNDS.offer(sound)) {
|
||||
Sound polled = SOUNDS.poll();
|
||||
assert polled != null;
|
||||
polled.stop();
|
||||
if (!SOUNDS.offer(sound)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static ALCCapabilities deviceCapabilities;
|
||||
private static ALCapabilities alCapabilities;
|
||||
|
||||
private static int getNextSource() {
|
||||
if (++lastSourceIndex > SOURCES_NUM) lastSourceIndex = 0;
|
||||
return SOURCES[lastSourceIndex];
|
||||
}
|
||||
public static void initAL() {
|
||||
String defaultDeviceName = alcGetString(
|
||||
0,
|
||||
ALC_DEFAULT_DEVICE_SPECIFIER
|
||||
);
|
||||
|
||||
public static Sound createSound(SoundType soundType) {
|
||||
Sound sound = soundType.genSoundSource(getNextSource());
|
||||
addSound(sound);
|
||||
return sound;
|
||||
}
|
||||
device = alcOpenDevice(defaultDeviceName);
|
||||
|
||||
public static void clearSounds() {
|
||||
Sound polled = SOUNDS.poll();
|
||||
while (polled != null) {
|
||||
polled.stop();
|
||||
polled = SOUNDS.poll();
|
||||
}
|
||||
}
|
||||
int[] attributes = new int[1];
|
||||
long context = alcCreateContext(device, attributes);
|
||||
alcMakeContextCurrent(context);
|
||||
|
||||
public static void checkALError() {
|
||||
int errorCode = alGetError();
|
||||
if(alGetError() != AL_NO_ERROR) {
|
||||
throw new RuntimeException(String.valueOf(errorCode));
|
||||
}
|
||||
}
|
||||
deviceCapabilities = ALC.createCapabilities(device);
|
||||
alCapabilities = AL.createCapabilities(deviceCapabilities);
|
||||
|
||||
checkALError();
|
||||
|
||||
alGenSources(SOURCES);
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
// Position of the listener
|
||||
Listener.getInstance().update();
|
||||
}
|
||||
|
||||
private static void addSound(Sound sound) {
|
||||
if (!SOUNDS.offer(sound)) {
|
||||
Sound polled = SOUNDS.poll();
|
||||
assert polled != null;
|
||||
polled.stop();
|
||||
if (!SOUNDS.offer(sound)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getNextSource() {
|
||||
if (++lastSourceIndex > SOURCES_NUM)
|
||||
lastSourceIndex = 0;
|
||||
return SOURCES[lastSourceIndex];
|
||||
}
|
||||
|
||||
public static Sound createSound(SoundType soundType) {
|
||||
Sound sound = soundType.genSoundSource(getNextSource());
|
||||
addSound(sound);
|
||||
return sound;
|
||||
}
|
||||
|
||||
public static void clearSounds() {
|
||||
Sound polled = SOUNDS.poll();
|
||||
while (polled != null) {
|
||||
polled.stop();
|
||||
polled = SOUNDS.poll();
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkALError() {
|
||||
int errorCode = alGetError();
|
||||
if (alGetError() != AL_NO_ERROR) {
|
||||
throw new RuntimeException(String.valueOf(errorCode));
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeAL() {
|
||||
clearSounds();
|
||||
alDeleteSources(SOURCES);
|
||||
for (Sound s : SOUNDS) {
|
||||
alDeleteBuffers(s.getAudio());
|
||||
}
|
||||
alcCloseDevice(device);
|
||||
}
|
||||
|
||||
public static ALCapabilities getALCapabilities() {
|
||||
return alCapabilities;
|
||||
}
|
||||
|
||||
public static ALCCapabilities getDeviceCapabilities() {
|
||||
return deviceCapabilities;
|
||||
}
|
||||
|
||||
public static void closeAL() {
|
||||
clearSounds();
|
||||
alDeleteSources(SOURCES);
|
||||
for(Sound s : SOUNDS) {
|
||||
alDeleteBuffers(s.getAudio());
|
||||
}
|
||||
alcCloseDevice(DEVICE);
|
||||
}
|
||||
}
|
||||
|
@ -4,42 +4,48 @@ import java.nio.ShortBuffer;
|
||||
import static org.lwjgl.openal.AL11.*;
|
||||
|
||||
public class SoundType {
|
||||
private ShortBuffer rawAudio;
|
||||
private int sampleRate;
|
||||
private int format;
|
||||
|
||||
public SoundType(ShortBuffer rawAudio, int format, int sampleRate) {
|
||||
this.rawAudio = rawAudio;
|
||||
this.sampleRate = sampleRate;
|
||||
this.format = format;
|
||||
}
|
||||
private ShortBuffer rawAudio;
|
||||
private int sampleRate;
|
||||
private int format;
|
||||
|
||||
public static int genEmptyAudio() {
|
||||
return alGenBuffers();
|
||||
}
|
||||
public SoundType(ShortBuffer rawAudio, int format, int sampleRate) {
|
||||
this.rawAudio = rawAudio;
|
||||
this.sampleRate = sampleRate;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public static int genEmptySource() {
|
||||
return alGenSources();
|
||||
}
|
||||
public static int genEmptyAudio() {
|
||||
return alGenBuffers();
|
||||
}
|
||||
|
||||
public int genAudio() {
|
||||
int audio = alGenBuffers();
|
||||
alBufferData(audio, format, rawAudio, sampleRate);
|
||||
return audio;
|
||||
}
|
||||
public static int genEmptySource() {
|
||||
return alGenSources();
|
||||
}
|
||||
|
||||
public Sound genSoundSource() {
|
||||
return new Sound(genAudio(), alGenSources());
|
||||
}
|
||||
public int genAudio() {
|
||||
int audio = alGenBuffers();
|
||||
alBufferData(audio, format, rawAudio, sampleRate);
|
||||
return audio;
|
||||
}
|
||||
|
||||
public Sound genSoundSource(int source) {
|
||||
if(!alIsSource(source)) throw new RuntimeException();
|
||||
return new Sound(genAudio(), source);
|
||||
}
|
||||
public Sound genSoundSource() {
|
||||
return new Sound(genAudio(), alGenSources());
|
||||
}
|
||||
|
||||
public Sound genSoundSource(int source) {
|
||||
if (!alIsSource(source))
|
||||
throw new RuntimeException();
|
||||
|
||||
return new Sound(genAudio(), source);
|
||||
}
|
||||
|
||||
public Sound genSoundSource(int source, int audio) {
|
||||
if (!alIsBuffer(audio) || !alIsSource(source))
|
||||
throw new RuntimeException();
|
||||
|
||||
alBufferData(audio, format, rawAudio, sampleRate);
|
||||
return new Sound(audio, alGenSources());
|
||||
}
|
||||
|
||||
public Sound genSoundSource(int source, int audio) {
|
||||
if(!alIsBuffer(audio) || !alIsSource(source)) throw new RuntimeException();
|
||||
alBufferData(audio, format, rawAudio, sampleRate);
|
||||
return new Sound(audio, alGenSources());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user