int obtainSource(boolean isMusic) { if (noDevice) return 0; for (int i = 0, n = idleSources.size; i < n; i++) { int sourceId = idleSources.get(i); int state = alGetSourcei(sourceId, AL_SOURCE_STATE); if (state != AL_PLAYING && state != AL_PAUSED) { if (isMusic) { idleSources.removeIndex(i); } else { if (sourceToSoundId.containsKey(sourceId)) { long soundId = sourceToSoundId.get(sourceId); sourceToSoundId.remove(sourceId); soundIdToSource.remove(soundId); } long soundId = nextSoundId++; sourceToSoundId.put(sourceId, soundId); soundIdToSource.put(soundId, sourceId); } alSourceStop(sourceId); alSourcei(sourceId, AL_BUFFER, 0); AL10.alSourcef(sourceId, AL10.AL_GAIN, 1); AL10.alSourcef(sourceId, AL10.AL_PITCH, 1); AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 1f); return sourceId; } } return -1; }
public void setSoundPan(long soundId, float pan, float volume) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); AL10.alSource3f( sourceId, AL10.AL_POSITION, MathUtils.cos((pan - 1) * MathUtils.PI / 2), 0, MathUtils.sin((pan + 1) * MathUtils.PI / 2)); AL10.alSourcef(sourceId, AL10.AL_GAIN, volume); }
void freeSource(int sourceID) { if (noDevice) return; alSourceStop(sourceID); alSourcei(sourceID, AL_BUFFER, 0); if (sourceToSoundId.containsKey(sourceID)) { long soundId = sourceToSoundId.remove(sourceID); soundIdToSource.remove(soundId); } idleSources.add(sourceID); }
void stopSourcesWithBuffer(int bufferID) { if (noDevice) return; for (int i = 0, n = idleSources.size; i < n; i++) { int sourceID = idleSources.get(i); if (alGetSourcei(sourceID, AL_BUFFER) == bufferID) { if (sourceToSoundId.containsKey(sourceID)) { long soundId = sourceToSoundId.remove(sourceID); soundIdToSource.remove(soundId); } alSourceStop(sourceID); } } }
public void dispose() { if (noDevice) return; for (int i = 0, n = allSources.size; i < n; i++) { int sourceID = allSources.get(i); int state = alGetSourcei(sourceID, AL_SOURCE_STATE); if (state != AL_STOPPED) alSourceStop(sourceID); alDeleteSources(sourceID); } sourceToSoundId.clear(); soundIdToSource.clear(); AL.destroy(); while (AL.isCreated()) { try { Thread.sleep(10); } catch (InterruptedException e) { } } }
/** * Remove the instance to the managed instances. Be careful using this method. This method is * intended for internal purposes only. */ public static void removeInstance(final btCollisionObject obj) { instances.remove(getCPtr(obj)); }
/** * Add the instance to the managed instances. You should avoid using this method. This method is * intended for internal purposes only. */ public static void addInstance(final btCollisionObject obj) { instances.put(getCPtr(obj), obj); }
/** * @return The existing instance for the specified pointer, or a newly created instance if the * instance didn't exist */ public static btCollisionObject getInstance(final long swigCPtr, boolean owner) { if (swigCPtr == 0) return null; btCollisionObject result = instances.get(swigCPtr); if (result == null) result = new btCollisionObject(swigCPtr, owner); return result; }
/** * @return The existing instance for the specified pointer, or null if the instance doesn't exist */ public static btCollisionObject getInstance(final long swigCPtr) { return swigCPtr == 0 ? null : instances.get(swigCPtr); }
public void setSoundPitch(long soundId, float pitch) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); AL10.alSourcef(sourceId, AL10.AL_PITCH, pitch); }
public void setSoundLooping(long soundId, boolean looping) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); alSourcei(sourceId, AL10.AL_LOOPING, looping ? AL10.AL_TRUE : AL10.AL_FALSE); }
public void setSoundGain(long soundId, float volume) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); AL10.alSourcef(sourceId, AL10.AL_GAIN, volume); }
public void resumeSound(long soundId) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); if (alGetSourcei(sourceId, AL_SOURCE_STATE) == AL_PAUSED) alSourcePlay(sourceId); }
public void pauseSound(long soundId) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); alSourcePause(sourceId); }
public void stopSound(long soundId) { if (!soundIdToSource.containsKey(soundId)) return; int sourceId = soundIdToSource.get(soundId); alSourceStop(sourceId); }