org.lwjgl.openal.AL Java Examples

The following examples show how to use org.lwjgl.openal.AL. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Mini2DxOpenALAudio.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
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) {
		}
	}
}
 
Example #2
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
* Initialise OpenAL LWJGL styley
*/
  public void init() {
  	try {
	AL.create();
	soundWorks = true;
} catch (LWJGLException e) {
	System.err.println("Failed to initialise LWJGL OpenAL");
	soundWorks = false;
	return;
}

if (soundWorks) {
	IntBuffer sources = BufferUtils.createIntBuffer(1);
	AL10.alGenSources(sources);
	
	if (AL10.alGetError() != AL10.AL_NO_ERROR) {
		System.err.println("Failed to create sources");
		soundWorks = false;
	} else {
		source = sources.get(0);
	}
	
}
  }
 
Example #3
Source File: LevelEditor.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void loop() {
	while(!Display.isCloseRequested()) {
		final long time = System.nanoTime();
		glClear(GL_COLOR_BUFFER_BIT |
		        GL_DEPTH_BUFFER_BIT |
		        GL_STENCIL_BUFFER_BIT);
		glClearDepth(1.0f);
		getInput();
		glPushMatrix();
			currentStage.beginStep(emptyList());
			currentStage.onStep();
			currentStage.processAddStack();
			currentStage.processRemoveStack();
			Renderer.getCamera().lookThrough();
			currentStage.render();
			currentStage.endStep();
		glPopMatrix();
		Display.update();
		timeDelta = System.nanoTime()-time;
	}
	AL.destroy();
	Display.destroy();
}
 
Example #4
Source File: LevelEditor.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void loop() {
	while(!Display.isCloseRequested()) {
		time = System.nanoTime();
		glClear(GL_COLOR_BUFFER_BIT |
		        GL_DEPTH_BUFFER_BIT |
		        GL_STENCIL_BUFFER_BIT);
		glClearDepth(1.0f);
		getInput();
		glPushMatrix();
		if(!paused) {
			currentStage.beginStep();
			currentStage.onStep();
			currentStage.processAddStack();
			currentStage.processRemoveStack();
			Renderer.getCamera().lookThrough();
			currentStage.render();
			currentStage.endStep();
		}
		glPopMatrix();
		Display.update();
		timeDelta = System.nanoTime()-time;
	}
	AL.destroy();
	Display.destroy();
}
 
Example #5
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #6
Source File: AudioManager.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private AudioSource getSource(AudioParameters params) {
	if (!AL.isCreated())
		return null;
	AudioSource best_source = findSource(params);
	stopSource(best_source);
	return best_source;
}
 
Example #7
Source File: LwjglAudioRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void cleanupInThread(){
    if (audioDisabled){
        AL.destroy();
        return;
    }

    // stop any playing channels
    for (int i = 0; i < chanSrcs.length; i++){
        if (chanSrcs[i] != null){
            clearChannel(i);
        }
    }
    
    // delete channel-based sources
    ib.clear();
    ib.put(channels);
    ib.flip();
    alDeleteSources(ib);
    
    // delete audio buffers and filters
    objManager.deleteAllObjects(this);

    if (supportEfx){
        ib.position(0).limit(1);
        ib.put(0, reverbFx);
        EFX10.alDeleteEffects(ib);

        // If this is not allocated, why is it deleted?
        // Commented out to fix native crash in OpenAL.
        ib.position(0).limit(1);
        ib.put(0, reverbFxSlot);
        EFX10.alDeleteAuxiliaryEffectSlots(ib);
    }

    AL.destroy();
}
 
Example #8
Source File: FEMultiplayer.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void loop() {
		while(!Display.isCloseRequested()) {
			time = System.nanoTime();
			glClear(GL_COLOR_BUFFER_BIT |
			        GL_DEPTH_BUFFER_BIT |
			        GL_STENCIL_BUFFER_BIT);
			glClearDepth(1.0f);
			getInput();
			messages.clear();
			if(client != null){
				messages.addAll(client.getMessages());
				for(Message m : messages)
					client.messages.remove(m);
			}
			SoundStore.get().poll(0);
			glPushMatrix();
			//Global resolution scale
//			Renderer.scale(scaleX, scaleY);
			if(!paused) {
				currentStage.beginStep();
				currentStage.onStep();
				currentStage.processAddStack();
				currentStage.processRemoveStack();
				currentStage.render();
//				FEResources.getBitmapFont("stat_numbers").render(
//						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
				currentStage.endStep();
			}
			glPopMatrix();
			Display.update();
			timeDelta = System.nanoTime()-time;
		}
		AL.destroy();
		Display.destroy();
		if(client != null && client.isOpen()) client.quit();
	}
 
Example #9
Source File: OpenALAudioDevice.java    From DareEngine with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void dispose() {
	Iterator<Entry<Integer, AudioChannel>> it = channels.entrySet()
			.iterator();
	while (it.hasNext()) {
		it.next().getValue().dispose();
	}
	AL.destroy(context);
}
 
Example #10
Source File: LwjglALC.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void createALC() {
    try {
        AL.create();
    } catch (LWJGLException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #11
Source File: AmbientAudio.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void updateSoundListener(CameraState camera, HeightMap heightmap) {
	if (AL.isCreated() && Settings.getSettings().play_sfx) {
		AL10.alListener3f(AL10.AL_POSITION, camera.getCurrentX(), camera.getCurrentY(), camera.getCurrentZ());
		camera.updateDirectionAndNormal(f, u, s);
		orientation_buffer.put(0, f.x);
		orientation_buffer.put(1, f.y);
		orientation_buffer.put(2, f.z);
		orientation_buffer.put(3, u.x);
		orientation_buffer.put(4, u.y);
		orientation_buffer.put(5, u.z);
		AL10.alListener(AL10.AL_ORIENTATION, orientation_buffer);

		int meters_per_world = heightmap.getMetersPerWorld();
		float dx = StrictMath.abs(camera.getCurrentX() - meters_per_world/2);
		float dy = StrictMath.abs(camera.getCurrentY() - meters_per_world/2);
		float dr = 2f*(float)Math.sqrt(dx*dx + dy*dy)/meters_per_world; //can use Math here - not gamestate affecting

		// update placement and gain of ambient forest source
		ambient_forest.setPos(0f, 0f, heightmap.getNearestHeight(camera.getCurrentX(), camera.getCurrentY()) - camera.getCurrentZ() + 8f);
		ambient_forest.setGain(AudioPlayer.AUDIO_GAIN_AMBIENT_FOREST * StrictMath.min(1f, StrictMath.max(0f, 1f - dr + 0.5f)));

		// update placement and gain of ambient beach source
		float factor = 1f;
		if (dr != 0)
			factor = 1f/dr - 1f;
		float beach_x = camera.getCurrentX()*factor;
		float beach_y = camera.getCurrentY()*factor;
		float beach_z = heightmap.getNearestHeight(camera.getCurrentX(), camera.getCurrentY()) - camera.getCurrentZ();
		float beach_gain = AudioPlayer.AUDIO_GAIN_AMBIENT_BEACH * StrictMath.min(1f, StrictMath.max(0f, 1f - StrictMath.abs(4f*dr - 3.75f)));
		ambient_beach.setPos(beach_x, beach_y, beach_z);
		ambient_beach.setGain(beach_gain);

		// update placement of ambient wind source
		ambient_wind.setPos(0f, 0f, StrictMath.max(0f, 50f + GameCamera.MAX_Z - camera.getCurrentZ()));
		ambient_wind.setGain(AudioPlayer.AUDIO_GAIN_AMBIENT_WIND);
	}
}
 
Example #12
Source File: AudioSource.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public AudioSource() {
	IntBuffer source_buffer = BufferUtils.createIntBuffer(1);
	if (AL.isCreated())
		AL10.alGenSources(source_buffer);
	// if alGenSources fails, the source object will be null (default value)
	source = source_buffer;
}
 
Example #13
Source File: Audio.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Audio(int num_buffers) {
	al_buffers = BufferUtils.createIntBuffer(num_buffers);

	if (!AL.isCreated())
		return;
	AL10.alGenBuffers(al_buffers);
}
 
Example #14
Source File: Audio.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Audio(URL file) {
	this(1);
	if (!AL.isCreated())
		return;
	Wave wave;
	try {
		wave = new Wave(file);
	} catch (Exception e) {
		// Assume it's an ogg vorbis file
		wave = loadOGG(file);
	}
	AL10.alBufferData(al_buffers.get(0), wave.getFormat(), wave.getData(), wave.getSampleRate());
}
 
Example #15
Source File: AudioManager.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private AudioSource getSource(CameraState camera_state, AudioParameters params) {
	if (!AL.isCreated())
		return null;
	float this_dist_squared;
	if (params.relative)
		this_dist_squared = params.x*params.x + params.y*params.y + params.z*params.z;
	else
		this_dist_squared = getCamDistSquared(camera_state, params.x, params.y, params.z);

	if (this_dist_squared > params.distance*params.distance) {
	   return null;
	}

	AudioSource best_source = findSource(params);

	if (best_source == null) {
		float max_dist_squared = this_dist_squared;
		FloatBuffer position = BufferUtils.createFloatBuffer(3);
		for (int i = 0; i < sources.length; i++) {
			AudioSource source = (AudioSource)sources[i];
			if (source.getRank() == params.rank) {
				int source_index = source.getSource();
				AL10.alGetSource(source_index, AL10.AL_POSITION, position);

				float dist_squared = getCamDistSquared(camera_state, position.get(0), position.get(1), position.get(2));
				if (dist_squared > max_dist_squared) {
					max_dist_squared = dist_squared;
					best_source = source;
				}
			}
		}
	}
	stopSource(best_source);
	return best_source;
}
 
Example #16
Source File: Renderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final static void setMusicPath(String music_path, float delay) {
	if (AL.isCreated()) {
		if (music != null && Settings.getSettings().play_music) {
			music.stop(2.5f, Settings.getSettings().music_gain);
		}
		Renderer.music_path = music_path;
		if (Settings.getSettings().play_music) {
			if (music_timer != null)
				music_timer.stop();
			music_timer = new TimerAnimation(new MusicTimer(), delay);
			music_timer.start();
		}
	}
}
 
Example #17
Source File: ProgressForm.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private ProgressForm(NetworkSelector network, final GUI gui, final Fadable load_fadable, boolean first_progress, ProgressBarInfo[] info, String texture_name, int texture_width, int texture_height, int image_width, int image_height, int progress_x, int progress_y, int progress_width, boolean show_tip) {
		if (AL.isCreated())
			AudioManager.getManager().stopSources();
		final GUIRoot gui_root;
		if (!first_progress) {
			gui_root = gui.newFade(load_fadable, null);
		} else {
			gui_root = gui.getGUIRoot();
		}
		CameraDelegate delegate = new NullDelegate(gui_root, false);
		gui_root.pushDelegate(delegate);
		int screen_width = LocalInput.getViewWidth();
		int screen_height = LocalInput.getViewHeight();
		progress_width = (int)(progress_width*(float)screen_width/image_width);
		progress_x = (int)(progress_x*(float)screen_width/image_width);
		progress_y = (int)(progress_y*(float)screen_height/image_height);

		image = new GUIImage(screen_width, screen_height, 0f, 0f, (float)image_width/texture_width, (float)image_height/texture_height, texture_name);
		image.setPos(0, 0);
		
		progress_bar = new ProgressBar(network, gui, progress_width, info, false);
		progress_y -= progress_bar.getHeight();
		progress_bar.setPos(progress_x, progress_y);
		delegate.addChild(image);
		delegate.addChild(progress_bar);
		if (show_tip) {
			Random random = new Random(LocalEventQueue.getQueue().getHighPrecisionManager().getTick());
//			CharSequence tip_string = LOADING_TIPS[7];
			CharSequence tip_string = LOADING_TIPS[random.nextInt(LOADING_TIPS.length)];
			int tip_width = Skin.getSkin().getEditFont().getWidth(tip_string);
			tip_width = StrictMath.min(LocalInput.getViewWidth() - 10, tip_width);
			LabelBox tip = new LabelBox(tip_string, Skin.getSkin().getEditFont(), tip_width);
//			Label tip = new Label(LOADING_TIPS[random.nextInt(LOADING_TIPS.length)], Skin.getSkin().getEditFont());
			tip.setPos(progress_bar.getX() + progress_bar.getWidth()/2 - tip.getWidth()/2, progress_bar.getY() - tip.getHeight() - PROGRESSBAR_LOADINGTIP_SPACING);
			delegate.addChild(tip);
		}
	}
 
Example #18
Source File: Sonics.java    From AnyaBasic with MIT License 5 votes vote down vote up
public Sonics()
{
    // Initialize OpenAL and clear the error bit.
    try
    {
        AL.create();
    }
    catch (LWJGLException e)
    {
        e.printStackTrace();
        return;
    }
    AL10.alGetError();

}
 
Example #19
Source File: Sonics.java    From AnyaBasic with MIT License 5 votes vote down vote up
public void shutDown()
{
    for( int i = 0; i < names.size(); i++ )
    {
        samples.get( names.get(i) ).destroy();
    }
    AL.destroy();
}
 
Example #20
Source File: FEMultiplayer.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void loop() {
		while(!Display.isCloseRequested()) {
			final long time = System.nanoTime();
			glClear(GL_COLOR_BUFFER_BIT |
			        GL_DEPTH_BUFFER_BIT |
			        GL_STENCIL_BUFFER_BIT);
			glClearDepth(1.0f);
			getInput();
			final ArrayList<Message> messages = new ArrayList<>();
			if(client != null){
				synchronized (client.messagesLock) {
					messages.addAll(client.messages);
					for(Message m : messages)
						client.messages.remove(m);
				}
			}
			SoundStore.get().poll(0);
			glPushMatrix();
			//Global resolution scale
//			Renderer.scale(scaleX, scaleY);
				currentStage.beginStep(messages);
				currentStage.onStep();
				currentStage.processAddStack();
				currentStage.processRemoveStack();
				currentStage.render();
//				FEResources.getBitmapFont("stat_numbers").render(
//						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
				currentStage.endStep();
				postRenderRunnables.runAll();
			glPopMatrix();
			Display.update();
			Display.sync(FEResources.getTargetFPS());
			timeDelta = System.nanoTime()-time;
		}
		AL.destroy();
		Display.destroy();
		if(client != null && client.isOpen()) client.quit();
	}
 
Example #21
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #22
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #23
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #24
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #25
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #26
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #27
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #28
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #29
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #30
Source File: Renderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final void initAL() {
		if (AL.isCreated()) {
			AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE);
//			resetMusicPath();
//			if (Settings.getSettings().play_music)
//				initMusicPlayer();
		}
	}