public void stopSource(AudioSource src) { synchronized (threadLock) { if (audioDisabled) { return; } if (src.getStatus() != Status.Stopped) { int chan = src.getChannel(); assert chan != -1; // if it's not stopped, must have id src.setStatus(Status.Stopped); src.setChannel(-1); clearChannel(chan); freeChannel(chan); if (src.getAudioData() instanceof AudioStream) { // If the stream is seekable, then rewind it. // Otherwise, close it, as it is no longer valid. AudioStream stream = (AudioStream)src.getAudioData(); if (stream.isSeekable()) { stream.setTime(0); } else { stream.close(); } } } } }
private void setSourceParams(int id, AudioSource src, boolean forceNonLoop) { if (src.isPositional()) { Vector3f pos = src.getPosition(); Vector3f vel = src.getVelocity(); al.alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); al.alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z); al.alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance()); al.alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance()); al.alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE); if (src.isReverbEnabled() && supportEfx) { int filter = EFX.AL_FILTER_NULL; if (src.getReverbFilter() != null) { Filter f = src.getReverbFilter(); if (f.isUpdateNeeded()) { updateFilter(f); if (src.getDryFilter() != null && supportEfx) { Filter f = src.getDryFilter(); if (f.isUpdateNeeded()) { updateFilter(f); if (forceNonLoop || src.getAudioData() instanceof AudioStream) { al.alSourcei(id, AL_LOOPING, AL_FALSE); } else { al.alSourcei(id, AL_LOOPING, src.isLooping() ? AL_TRUE : AL_FALSE); al.alSourcef(id, AL_GAIN, src.getVolume()); al.alSourcef(id, AL_PITCH, src.getPitch()); al.alSourcef(id, AL_SEC_OFFSET, src.getTimeOffset());
public void pauseSource(AudioSource src) { checkDead(); synchronized (threadLock) { if (audioDisabled) { return; } if (src.getStatus() == Status.Playing) { assert src.getChannel() != -1; al.alSourcePause(channels[src.getChannel()]); src.setStatus(Status.Paused); } } }
private void clearChannel(int index) { // make room at this channel if (chanSrcs[index] != null) { AudioSource src = chanSrcs[index]; int sourceId = channels[index]; al.alSourceStop(sourceId); // For streaming sources, this will clear all queued buffers. al.alSourcei(sourceId, AL_BUFFER, 0); if (src.getDryFilter() != null && supportEfx) { // detach filter al.alSourcei(sourceId, EFX.AL_DIRECT_FILTER, EFX.AL_FILTER_NULL); } if (src.isPositional()) { AudioSource pas = (AudioSource) src; if (pas.isReverbEnabled() && supportEfx) { al.alSource3i(sourceId, EFX.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX.AL_FILTER_NULL); } } chanSrcs[index] = null; } }
AudioSource src = chanSrcs[i]; if (src == null || !(src.getAudioData() instanceof AudioStream)) { continue; AudioStream stream = (AudioStream) src.getAudioData(); Status jmeStatus = src.getStatus(); boolean buffersWereFilled = fillStreamingSource(sourceId, stream, src.isLooping());
if (src.getChannel() < 0) { return 0; int id = channels[src.getChannel()]; AudioData data = src.getAudioData(); int playbackOffsetBytes = 0;
public void playSourceInstance(AudioSource src) { checkDead(); synchronized (threadLock) { if (audioDisabled) { return; } if (src.getAudioData() instanceof AudioStream) { throw new UnsupportedOperationException( "Cannot play instances " + "of audio streams. Use play() instead."); } if (src.getAudioData().isUpdateNeeded()) { updateAudioData(src.getAudioData()); } // create a new index for an audio-channel int index = newChannel(); if (index == -1) { return; } int sourceId = channels[index]; clearChannel(index); // set parameters, like position and max distance setSourceParams(sourceId, src, true); attachAudioToSource(sourceId, src.getAudioData(), false); chanSrcs[index] = src; // play the channel al.alSourcePlay(sourceId); } }
public void pauseSource(AudioSource src) { checkDead(); synchronized (threadLock) { if (audioDisabled) { return; } if (src.getStatus() == Status.Playing) { assert src.getChannel() != -1; al.alSourcePause(channels[src.getChannel()]); src.setStatus(Status.Paused); } } }
AudioSource src = chanSrcs[i]; if (src == null || !(src.getAudioData() instanceof AudioStream)) { continue; AudioStream stream = (AudioStream) src.getAudioData(); Status jmeStatus = src.getStatus(); boolean buffersWereFilled = fillStreamingSource(sourceId, stream, src.isLooping());
private void clearChannel(int index) { // make room at this channel if (chanSrcs[index] != null) { AudioSource src = chanSrcs[index]; int sourceId = channels[index]; al.alSourceStop(sourceId); // For streaming sources, this will clear all queued buffers. al.alSourcei(sourceId, AL_BUFFER, 0); if (src.getDryFilter() != null && supportEfx) { // detach filter al.alSourcei(sourceId, EFX.AL_DIRECT_FILTER, EFX.AL_FILTER_NULL); } if (src.isPositional()) { AudioSource pas = (AudioSource) src; if (pas.isReverbEnabled() && supportEfx) { al.alSource3i(sourceId, EFX.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX.AL_FILTER_NULL); } } chanSrcs[index] = null; } }
if (src.getChannel() < 0) { return 0; int id = channels[src.getChannel()]; AudioData data = src.getAudioData(); int playbackOffsetBytes = 0;
public void playSourceInstance(AudioSource src) { checkDead(); synchronized (threadLock) { if (audioDisabled) { return; } if (src.getAudioData() instanceof AudioStream) { throw new UnsupportedOperationException( "Cannot play instances " + "of audio streams. Use play() instead."); } if (src.getAudioData().isUpdateNeeded()) { updateAudioData(src.getAudioData()); } // create a new index for an audio-channel int index = newChannel(); if (index == -1) { return; } int sourceId = channels[index]; clearChannel(index); // set parameters, like position and max distance setSourceParams(sourceId, src, true); attachAudioToSource(sourceId, src.getAudioData(), false); chanSrcs[index] = src; // play the channel al.alSourcePlay(sourceId); } }
if (src.getChannel() < 0) { return; assert src.getChannel() >= 0; int id = channels[src.getChannel()]; switch (param) { case Position: if (!src.isPositional()) { return; Vector3f pos = src.getPosition(); al.alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); break; case Velocity: if (!src.isPositional()) { return; Vector3f vel = src.getVelocity(); al.alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z); break; case MaxDistance: if (!src.isPositional()) { return; al.alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance()); break; case RefDistance: if (!src.isPositional()) {
if (src.getStatus() == Status.Playing) { return; } else if (src.getStatus() == Status.Stopped) { src.setChannel(index); AudioData data = src.getAudioData(); if (data.isUpdateNeeded()) { updateAudioData(data); attachAudioToSource(channels[index], data, src.isLooping()); al.alSourcePlay(channels[src.getChannel()]); src.setStatus(Status.Playing);
private void setSourceParams(int id, AudioSource src, boolean forceNonLoop) { if (src.isPositional()) { Vector3f pos = src.getPosition(); Vector3f vel = src.getVelocity(); al.alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); al.alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z); al.alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance()); al.alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance()); al.alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE); if (src.isReverbEnabled() && supportEfx) { int filter = EFX.AL_FILTER_NULL; if (src.getReverbFilter() != null) { Filter f = src.getReverbFilter(); if (f.isUpdateNeeded()) { updateFilter(f); if (src.getDryFilter() != null && supportEfx) { Filter f = src.getDryFilter(); if (f.isUpdateNeeded()) { updateFilter(f); if (forceNonLoop || src.getAudioData() instanceof AudioStream) { al.alSourcei(id, AL_LOOPING, AL_FALSE); } else { al.alSourcei(id, AL_LOOPING, src.isLooping() ? AL_TRUE : AL_FALSE); al.alSourcef(id, AL_GAIN, src.getVolume()); al.alSourcef(id, AL_PITCH, src.getPitch()); al.alSourcef(id, AL_SEC_OFFSET, src.getTimeOffset());
boolean boundSource = i == src.getChannel(); boolean reclaimChannel = false; Status jmeStatus = src.getStatus(); if (oalStatus == Status.Stopped && jmeStatus == Status.Playing) { if (src.getAudioData() instanceof AudioStream) { AudioStream stream = (AudioStream) src.getAudioData(); if (stream.isEOF() && !src.isLooping()) { if (src.isLooping()) { src.setStatus(Status.Stopped); src.setChannel(-1); clearChannel(i); freeChannel(i);
if (src.getChannel() < 0) { return; assert src.getChannel() >= 0; int id = channels[src.getChannel()]; switch (param) { case Position: if (!src.isPositional()) { return; Vector3f pos = src.getPosition(); al.alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); break; case Velocity: if (!src.isPositional()) { return; Vector3f vel = src.getVelocity(); al.alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z); break; case MaxDistance: if (!src.isPositional()) { return; al.alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance()); break; case RefDistance: if (!src.isPositional()) {
public void stopSource(AudioSource src) { synchronized (threadLock) { if (audioDisabled) { return; } if (src.getStatus() != Status.Stopped) { int chan = src.getChannel(); assert chan != -1; // if it's not stopped, must have id src.setStatus(Status.Stopped); src.setChannel(-1); clearChannel(chan); freeChannel(chan); if (src.getAudioData() instanceof AudioStream) { // If the stream is seekable, then rewind it. // Otherwise, close it, as it is no longer valid. AudioStream stream = (AudioStream)src.getAudioData(); if (stream.isSeekable()) { stream.setTime(0); } else { stream.close(); } } } } }
if (src.getStatus() == Status.Playing) { return; } else if (src.getStatus() == Status.Stopped) { src.setChannel(index); AudioData data = src.getAudioData(); if (data.isUpdateNeeded()) { updateAudioData(data); attachAudioToSource(channels[index], data, src.isLooping()); al.alSourcePlay(channels[src.getChannel()]); src.setStatus(Status.Playing);