private static void setEnvironment(int sourceID, float sendGain0, float sendGain1, float sendGain2, float sendGain3, float sendCutoff0, float sendCutoff1, float sendCutoff2, float sendCutoff3, float directCutoff, float directGain) { //Set reverb send filter values and set source to send to all reverb fx slots EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAIN, sendGain0); EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAINHF, sendCutoff0); AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot0, 0, sendFilter0); EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAIN, sendGain1); EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAINHF, sendCutoff1); AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot1, 1, sendFilter1); EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAIN, sendGain2); EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAINHF, sendCutoff2); AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot2, 2, sendFilter2); EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAIN, sendGain3); EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAINHF, sendCutoff3); AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot3, 3, sendFilter3); EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAIN, directGain); EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff); AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, SoundPhysicsCore.Config.airAbsorption); }
@Override public void initAudioApp(){ assetManager.registerLocator("C:\\", FileLocator.class); Quaternion q = new Quaternion(); q.lookAt(new Vector3f(0, 0, -1f), Vector3f.UNIT_Y); listener.setRotation(q); audioRenderer.setEnvironment(Environment.Dungeon); AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE); ufo = new AudioNode(audioRenderer, assetManager, "test.ogg", false); ufo.setPositional(true); ufo.setLooping(true); ufo.setReverbEnabled(true); ufo.setRefDistance(100000000); ufo.setMaxDistance(100000000); audioRenderer.playSource(ufo); }
@Override public SoundSource setPlaybackPosition(int position) { boolean playing = isPlaying(); if (playing) { AL10.alSourceStop(getSourceId()); } AL10.alSourceRewind(getSourceId()); AL10.alSourcei(getSourceId(), AL11.AL_SAMPLE_OFFSET, audio.getSamplingRate() * position); OpenALException.checkState("Setting sound playback absolute position"); if (playing) { play(); } return this; }
@Override public SoundSource setPlaybackPosition(float position) { boolean playing = isPlaying(); if (playing) { AL10.alSourceStop(getSourceId()); } AL10.alSourceRewind(getSourceId()); AL10.alSourcei(getSourceId(), AL11.AL_BYTE_OFFSET, (int) (audio.getBufferSize() * position)); OpenALException.checkState("Setting sound playback relaive position"); if (playing) { play(); } return this; }
/** * @see org.newdawn.slick.openal.Audio#setPosition(float) */ public boolean setPosition(float position) { position = position % length; AL10.alSourcef(store.getSource(index), AL11.AL_SEC_OFFSET, position); if (AL10.alGetError() != 0) { return false; } return true; }
private void clearChannel(int index){ // make room at this channel if (chanSrcs[index] != null){ AudioNode src = chanSrcs[index]; int sourceId = channels[index]; alSourceStop(sourceId); if (src.getAudioData() instanceof AudioStream){ AudioStream str = (AudioStream) src.getAudioData(); ib.position(0).limit(STREAMING_BUFFER_COUNT); ib.put(str.getIds()).flip(); alSourceUnqueueBuffers(sourceId, ib); }else if (src.getAudioData() instanceof AudioBuffer){ alSourcei(sourceId, AL_BUFFER, 0); } if (src.getDryFilter() != null){ // detach filter alSourcei(sourceId, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL); } if (src.isPositional()){ AudioNode pas = (AudioNode) src; if (pas.isReverbEnabled()) { AL11.alSource3i(sourceId, EFX10.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX10.AL_FILTER_NULL); } } chanSrcs[index] = null; } }
public void setPosition (float position) { if (audio.noDevice) return; if (sourceID == -1) return; boolean wasPlaying = isPlaying; isPlaying = false; alSourceStop(sourceID); alSourceUnqueueBuffers(sourceID, buffers); renderedSeconds += (secondsPerBuffer * bufferCount); if (position <= renderedSeconds) { reset(); renderedSeconds = 0; } while (renderedSeconds < (position - secondsPerBuffer)) { if (read(tempBytes) <= 0) break; renderedSeconds += secondsPerBuffer; } boolean filled = false; for (int i = 0; i < bufferCount; i++) { int bufferID = buffers.get(i); if (!fill(bufferID)) break; filled = true; alSourceQueueBuffers(sourceID, bufferID); } if (!filled) { stop(); if (onCompletionListener != null) onCompletionListener.onCompletion(this); } alSourcef(sourceID, AL11.AL_SEC_OFFSET, position - renderedSeconds); if (wasPlaying) { alSourcePlay(sourceID); isPlaying = true; } }
/** play a sound relative to the listener */ public void playAt(ALSound sound, Vector3f pos, Vector3f velocity) { this.setInteger(AL10.AL_DISTANCE_MODEL, AL11.AL_LINEAR_DISTANCE); this.setFloatVector(AL10.AL_POSITION, pos); this.setFloatVector(AL10.AL_VELOCITY, velocity); this.play(sound, AL10.AL_TRUE); }
@Override public void setPosition(float position) { if (audio.noDevice) { return; } if (sourceID == -1) { return; } boolean wasPlaying = isPlaying; isPlaying = false; alSourceStop(sourceID); renderedSeconds += secondsPerBuffer; if (position <= renderedSeconds) { reset(); renderedSeconds = 0; } while (renderedSeconds < (position - secondsPerBuffer)) { if (read(tempBytes) <= 0) { break; } renderedSeconds += secondsPerBuffer; } update(); alSourcef(sourceID, AL11.AL_SEC_OFFSET, position - renderedSeconds); if (wasPlaying) { alSourcePlay(sourceID); isPlaying = true; } }
@Override public float getPosition() { if (audio.noDevice) { return 0; } if (sourceID == -1) { return 0; } return renderedSeconds + alGetSourcef(sourceID, AL11.AL_SEC_OFFSET); }
/** * Calculates the number of milliseconds since the channel began playing. * @return Milliseconds, or -1 if unable to calculate. */ @Override public float millisecondsPlayed() { // get number of samples played in current buffer float offset = (float)AL10.alGetSourcei( ALSource.get( 0 ), AL11.AL_BYTE_OFFSET ); float bytesPerFrame = 1f; switch( ALformat ) { case AL10.AL_FORMAT_MONO8 : bytesPerFrame = 1f; break; case AL10.AL_FORMAT_MONO16 : bytesPerFrame = 2f; break; case AL10.AL_FORMAT_STEREO8 : bytesPerFrame = 2f; break; case AL10.AL_FORMAT_STEREO16 : bytesPerFrame = 4f; break; default : break; } offset = ( ( (float) offset / bytesPerFrame ) / (float) sampleRate ) * 1000; // add the milliseconds from stream-buffers that played previously if( channelType == SoundSystemConfig.TYPE_STREAMING ) offset += millisPreviouslyPlayed; // Return millis played: return( offset ); }
public static boolean sourceSeek(int source, float secOffset) { if (source==-1) return false; AL10.alSourcef(source, AL11.AL_SEC_OFFSET, secOffset); if (AL10.alGetError() != 0) { return false; } return true; }
private void clearChannel(int index){ // make room at this channel if (chanSrcs[index] != null){ AudioNode src = chanSrcs[index]; int sourceId = channels[index]; alSourceStop(sourceId); if (src.getAudioData() instanceof AudioStream){ AudioStream str = (AudioStream) src.getAudioData(); ib.position(0).limit(STREAMING_BUFFER_COUNT); ib.put(str.getIds()).flip(); alSourceUnqueueBuffers(sourceId, ib); }else if (src.getAudioData() instanceof AudioBuffer){ alSourcei(sourceId, AL_BUFFER, 0); } if (src.getDryFilter() != null && supportEfx){ // detach filter alSourcei(sourceId, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL); } if (src.isPositional()){ AudioNode pas = (AudioNode) src; if (pas.isReverbEnabled() && supportEfx) { AL11.alSource3i(sourceId, EFX10.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX10.AL_FILTER_NULL); } } chanSrcs[index] = null; } }
@Override public void simpleInitApp(){ audioRenderer.setEnvironment(Environment.Dungeon); AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE); ufo = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false); ufo.setPositional(true); ufo.setLooping(true); ufo.setReverbEnabled(true); ufo.setRefDistance(100000000); ufo.setMaxDistance(100000000); ufo.play(); }
/** * @see org.newdawn.slick.openal.Audio#getPosition() */ public float getPosition() { return AL10.alGetSourcef(store.getSource(index), AL11.AL_SEC_OFFSET); }
/** * Return the current playing position in the sound * * @return The current position in seconds. */ public float getALPosition() { float playedTime = ((float) playedPos / (float) sampleSize) / sampleRate; float timePosition = playedTime + AL10.alGetSourcef(source, AL11.AL_SEC_OFFSET); return timePosition; }
/** * Plays a sound with various effects applied to it. */ private static void playbackTest() throws Exception { setupEfx(); // Create a source and buffer audio data final int source = AL10.alGenSources(); final int buffer = AL10.alGenBuffers(); WaveData waveFile = WaveData.create("Footsteps.wav"); if (waveFile == null) { System.out.println("Failed to load Footsteps.wav! Skipping playback test."); AL.destroy(); return; } AL10.alBufferData(buffer, waveFile.format, waveFile.data, waveFile.samplerate); waveFile.dispose(); AL10.alSourcei(source, AL10.AL_BUFFER, buffer); AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_TRUE); System.out.println("Playing sound unaffected by EFX ..."); AL10.alSourcePlay(source); Thread.sleep(7500); // Add reverb effect final int effectSlot = EFX10.alGenAuxiliaryEffectSlots(); final int reverbEffect = EFX10.alGenEffects(); EFX10.alEffecti(reverbEffect, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_REVERB); EFX10.alEffectf(reverbEffect, EFX10.AL_REVERB_DECAY_TIME, 5.0f); EFX10.alAuxiliaryEffectSloti(effectSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbEffect); AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, effectSlot, 0, EFX10.AL_FILTER_NULL); System.out.println("Playing sound with reverb ..."); AL10.alSourcePlay(source); Thread.sleep(7500); // Add low-pass filter directly to source final int filter = EFX10.alGenFilters(); EFX10.alFilteri(filter, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAIN, 0.5f); EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAINHF, 0.5f); AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, filter); System.out.println("Playing sound with reverb and direct low pass filter ..."); AL10.alSourcePlay(source); Thread.sleep(7500); AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL); // Add low-pass filter to source send //AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, effectSlot, 0, filter); // //System.out.println("Playing sound with reverb and aux send low pass filter ..."); //AL10.alSourcePlay(source); //Thread.sleep(7500); // Cleanup AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 0, EFX10.AL_FILTER_NULL); EFX10.alAuxiliaryEffectSloti(effectSlot, EFX10.AL_EFFECTSLOT_EFFECT, EFX10.AL_EFFECT_NULL); EFX10.alDeleteEffects(reverbEffect); EFX10.alDeleteFilters(filter); // Echo effect final int echoEffect = EFX10.alGenEffects(); EFX10.alEffecti(echoEffect, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_ECHO); //EFX10.alEffectf(echoEffect, EFX10.AL_ECHO_DELAY, 5.0f); EFX10.alAuxiliaryEffectSloti(effectSlot, EFX10.AL_EFFECTSLOT_EFFECT, echoEffect); AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, effectSlot, 0, EFX10.AL_FILTER_NULL); System.out.println("Playing sound with echo effect ..."); AL10.alSourcePlay(source); Thread.sleep(7500); AL.destroy(); }
public float getPosition () { if (sourceID == -1) return 0; return renderedSeconds + alGetSourcef(sourceID, AL11.AL_SEC_OFFSET); }
public float getPosition () { if (audio.noDevice) return 0; if (sourceID == -1) return 0; return renderedSeconds + alGetSourcef(sourceID, AL11.AL_SEC_OFFSET); }