Java Code Examples for org.lwjgl.openal.AL#isCreated()

The following examples show how to use org.lwjgl.openal.AL#isCreated() . 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: 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 3
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();
		}
	}
 
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: Renderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static void destroyAL() {
	if (AL.isCreated()) {
		AudioManager.getManager().destroy();
		AL.destroy();
	}
}
 
Example 12
Source File: Audio.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
protected final void doDelete() {
	if (AL.isCreated()) {
		al_buffers.clear();
		AL10.alDeleteBuffers(al_buffers);
	}
}
 
Example 13
Source File: LwjglALC.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean isCreated() {
    return AL.isCreated();
}
 
Example 14
Source File: MusicController.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Stops and releases all sources, clears each of the specified Audio
 * buffers, destroys the OpenAL context, and resets SoundStore for future use.
 *
 * Calling SoundStore.get().init() will re-initialize the OpenAL context
 * after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
 *
 * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
 */
private static void destroyOpenAL() {
	if (!trackExists())
		return;
	stop();

	if (!AL.isCreated())
		return;

	try {
		// get Music object's (private) Audio object reference
		Field sound = player.getClass().getDeclaredField("sound");
		sound.setAccessible(true);
		Audio audio = (Audio) (sound.get(player));

		// first clear the sources allocated by SoundStore
		int max = SoundStore.get().getSourceCount();
		IntBuffer buf = BufferUtils.createIntBuffer(max);
		for (int i = 0; i < max; i++) {
			int source = SoundStore.get().getSource(i);
			buf.put(source);

			// stop and detach any buffers at this source
			AL10.alSourceStop(source);
			AL10.alSourcei(source, AL10.AL_BUFFER, 0);
		}
		buf.flip();
		AL10.alDeleteSources(buf);
		int exc = AL10.alGetError();
		if (exc != AL10.AL_NO_ERROR) {
			throw new SlickException(
					"Could not clear SoundStore sources, err: " + exc);
		}

		// delete any buffer data stored in memory, too...
		if (audio != null && audio.getBufferID() != 0) {
			buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
			buf.flip();
			AL10.alDeleteBuffers(buf);
			exc = AL10.alGetError();
			if (exc != AL10.AL_NO_ERROR) {
				throw new SlickException("Could not clear buffer "
						+ audio.getBufferID()
						+ ", err: "+exc);
			}
		}

		// clear OpenAL
		AL.destroy();

		// reset SoundStore so that next time we create a Sound/Music, it will reinit
		SoundStore.get().clear();

		player = null;
	} catch (Exception e) {
		ErrorHandler.error("Failed to destroy the OpenAL context.", e, true);
	}
}