Java源码示例:org.lwjgl.openal.AL

示例1
@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();
}
 
示例2
@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();
}
 
示例3
/**
* 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);
	}
	
}
  }
 
示例4
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) {
		}
	}
}
 
示例5
public Sonics()
{
    // Initialize OpenAL and clear the error bit.
    try
    {
        AL.create();
    }
    catch (LWJGLException e)
    {
        e.printStackTrace();
        return;
    }
    AL10.alGetError();

}
 
示例6
public void shutDown()
{
    for( int i = 0; i < names.size(); i++ )
    {
        samples.get( names.get(i) ).destroy();
    }
    AL.destroy();
}
 
示例7
@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();
	}
 
示例8
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);
}
 
示例9
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);
}
 
示例10
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);
}
 
示例11
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);
}
 
示例12
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);
}
 
示例13
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);
}
 
示例14
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);
}
 
示例15
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);
}
 
示例16
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);
}
 
示例17
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);
}
 
示例18
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);
		}
	}
 
示例19
private final void initAL() {
		if (AL.isCreated()) {
			AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE);
//			resetMusicPath();
//			if (Settings.getSettings().play_music)
//				initMusicPlayer();
		}
	}
 
示例20
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();
		}
	}
}
 
示例21
private AudioSource getSource(AudioParameters params) {
	if (!AL.isCreated())
		return null;
	AudioSource best_source = findSource(params);
	stopSource(best_source);
	return best_source;
}
 
示例22
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;
}
 
示例23
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());
}
 
示例24
public Audio(int num_buffers) {
	al_buffers = BufferUtils.createIntBuffer(num_buffers);

	if (!AL.isCreated())
		return;
	AL10.alGenBuffers(al_buffers);
}
 
示例25
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;
}
 
示例26
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);
	}
}
 
示例27
@Override
public void createALC() {
    try {
        AL.create();
    } catch (LWJGLException ex) {
        throw new RuntimeException(ex);
    }
}
 
示例28
@Override
public void dispose() {
	Iterator<Entry<Integer, AudioChannel>> it = channels.entrySet()
			.iterator();
	while (it.hasNext()) {
		it.next().getValue().dispose();
	}
	AL.destroy(context);
}
 
示例29
@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();
	}
 
示例30
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();
}