org.lwjgl.openal.AL10 Java Examples

The following examples show how to use org.lwjgl.openal.AL10. 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: SoundStore.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the Sound based on a specified OGG file
 * 
 * @param ref The reference to the OGG file in the classpath
 * @return The Sound read from the OGG file
 * @throws IOException Indicates a failure to load the OGG
 */
public Audio getOggStream(URL ref) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	
	setMOD(null);
	setStream(null);
	
	if (currentMusic != -1) {
		AL10.alSourceStop(sources.get(0));
	}
	
	getMusicSource();
	currentMusic = sources.get(0);
	
	return new StreamSound(new OpenALStreamPlayer(currentMusic, ref));
}
 
Example #2
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the Sound based on a specified OGG file
 * 
 * @param ref The reference to the OGG file in the classpath
 * @return The Sound read from the OGG file
 * @throws IOException Indicates a failure to load the OGG
 */
public Audio getOggStream(String ref) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	
	setMOD(null);
	setStream(null);
	
	if (currentMusic != -1) {
		AL10.alSourceStop(sources.get(0));
	}
	
	getMusicSource();
	currentMusic = sources.get(0);
	
	return new StreamSound(new OpenALStreamPlayer(currentMusic, ref));
}
 
Example #3
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Play the specified buffer as music (i.e. use the music channel)
 * 
 * @param buffer The buffer to be played
 * @param pitch The pitch to play the music at
 * @param gain The gaing to play the music at
 * @param loop True if we should loop the music
 */
void playAsMusic(int buffer,float pitch,float gain, boolean loop) {
	paused = false;
	
	setMOD(null);
	
	if (soundWorks) {
		if (currentMusic != -1) {
			AL10.alSourceStop(sources.get(0));
		}
		
		getMusicSource();
		
		AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffer);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		
		currentMusic = sources.get(0);
		
		if (!music) {
			pauseLoop();
		} else {
			AL10.alSourcePlay(sources.get(0)); 
		}
	}
}
 
Example #4
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 #5
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Play the specified buffer as music (i.e. use the music channel)
 * 
 * @param buffer The buffer to be played
 * @param pitch The pitch to play the music at
 * @param gain The gaing to play the music at
 * @param loop True if we should loop the music
 */
void playAsMusic(int buffer,float pitch,float gain, boolean loop) {
	paused = false;
	
	setMOD(null);
	
	if (soundWorks) {
		if (currentMusic != -1) {
			AL10.alSourceStop(sources.get(0));
		}
		
		getMusicSource();
		
		AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffer);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		
		currentMusic = sources.get(0);
		
		if (!music) {
			pauseLoop();
		} else {
			AL10.alSourcePlay(sources.get(0)); 
		}
	}
}
 
Example #6
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Play the specified buffer as music (i.e. use the music channel)
 * 
 * @param buffer The buffer to be played
 * @param pitch The pitch to play the music at
 * @param gain The gaing to play the music at
 * @param loop True if we should loop the music
 */
void playAsMusic(int buffer,float pitch,float gain, boolean loop) {
	paused = false;
	
	setMOD(null);
	
	if (soundWorks) {
		if (currentMusic != -1) {
			AL10.alSourceStop(sources.get(0));
		}
		
		getMusicSource();
		
		AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffer);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		
		currentMusic = sources.get(0);
		
		if (!music) {
			pauseLoop();
		} else {
			AL10.alSourcePlay(sources.get(0)); 
		}
	}
}
 
Example #7
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Pause the music loop that is currently playing
 */
public void pauseLoop() {
	if ((soundWorks) && (currentMusic != -1)){
		paused = true;
		if (stream != null)
			stream.pausing();
		AL10.alSourcePause(currentMusic);
	}
}
 
Example #8
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Play the specified buffer as a sound effect with the specified
 * pitch and gain.
 * 
 * @param buffer The ID of the buffer to play
 * @param pitch The pitch to play at
 * @param gain The gain to play at
 * @param loop True if the sound should loop
 * @param x The x position to play the sound from
 * @param y The y position to play the sound from
 * @param z The z position to play the sound from
 * @return source The source that will be used
 */
int playAsSoundAt(int buffer,float pitch,float gain,boolean loop,float x, float y, float z) {
	gain *= soundVolume;
	if (gain == 0) {
		gain = 0.001f;
	}
	if (soundWorks) {
		if (sounds) {
			int nextSource = findFreeSource();
			if (nextSource == -1) {
				return -1;
			}
			
			AL10.alSourceStop(sources.get(nextSource));
			
			AL10.alSourcei(sources.get(nextSource), AL10.AL_BUFFER, buffer);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_PITCH, pitch);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_GAIN, gain); 
		    AL10.alSourcei(sources.get(nextSource), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		    
		    sourcePos.clear();
		    sourceVel.clear();
			sourceVel.put(new float[] { 0, 0, 0 });
			sourcePos.put(new float[] { x, y, z });
		    sourcePos.flip();
		    sourceVel.flip();
		    AL10.alSource(sources.get(nextSource), AL10.AL_POSITION, sourcePos);
   			AL10.alSource(sources.get(nextSource), AL10.AL_VELOCITY, sourceVel);
		    
			AL10.alSourcePlay(sources.get(nextSource)); 
			
			return nextSource;
		}
	}
	
	return -1;
}
 
Example #9
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Play the specified buffer as a sound effect with the specified
 * pitch and gain.
 * 
 * @param buffer The ID of the buffer to play
 * @param pitch The pitch to play at
 * @param gain The gain to play at
 * @param loop True if the sound should loop
 * @param x The x position to play the sound from
 * @param y The y position to play the sound from
 * @param z The z position to play the sound from
 * @return source The source that will be used
 */
int playAsSoundAt(int buffer,float pitch,float gain,boolean loop,float x, float y, float z) {
	gain *= soundVolume;
	if (gain == 0) {
		gain = 0.001f;
	}
	if (soundWorks) {
		if (sounds) {
			int nextSource = findFreeSource();
			if (nextSource == -1) {
				return -1;
			}
			
			AL10.alSourceStop(sources.get(nextSource));
			
			AL10.alSourcei(sources.get(nextSource), AL10.AL_BUFFER, buffer);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_PITCH, pitch);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_GAIN, gain); 
		    AL10.alSourcei(sources.get(nextSource), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		    
		    sourcePos.clear();
		    sourceVel.clear();
			sourceVel.put(new float[] { 0, 0, 0 });
			sourcePos.put(new float[] { x, y, z });
		    sourcePos.flip();
		    sourceVel.flip();
		    AL10.alSource(sources.get(nextSource), AL10.AL_POSITION, sourcePos);
   			AL10.alSource(sources.get(nextSource), AL10.AL_VELOCITY, sourceVel);
		    
			AL10.alSourcePlay(sources.get(nextSource)); 
			
			return nextSource;
		}
	}
	
	return -1;
}
 
Example #10
Source File: AudioManager.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void startSources() {
	if (sound_play_counter == 0) {
		for (int i = 0; i < ambients.size(); i++) {
			AL10.alSourcePlay(((AudioSource)ambients.get(i)).getSource());
		}
	}
	sound_play_counter++;
}
 
Example #11
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if the music is currently playing
 * 
 * @return True if the music is playing
 */
public boolean isMusicPlaying() 
{
	if (!soundWorks) {
		return false;
	}
	
	int state = AL10.alGetSourcei(sources.get(0), AL10.AL_SOURCE_STATE);
	return ((state == AL10.AL_PLAYING) || (state == AL10.AL_PAUSED));
}
 
Example #12
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the pitch at which the current music is being played
 * 
 * @param pitch The pitch at which the current music is being played
 */
public void setMusicPitch(float pitch) {
	if (soundWorks) {
		stream.setup(pitch);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	}
}
 
Example #13
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Find a free sound source
 * 
 * @return The index of the free sound source
 */
private int findFreeSource() {
	for (int i=1;i<sourceCount-1;i++) {
		int state = AL10.alGetSourcei(sources.get(i), AL10.AL_SOURCE_STATE);
		
		if ((state != AL10.AL_PLAYING) && (state != AL10.AL_PAUSED)) {
			return i;
		}
	}
	
	return -1;
}
 
Example #14
Source File: MODSound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Clean up the buffers applied to the sound source
 */
private void cleanUpSource() {
	AL10.alSourceStop(store.getSource(0));
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	int queued = AL10.alGetSourcei(store.getSource(0), AL10.AL_BUFFERS_QUEUED);
	
	while (queued > 0)
	{
		AL10.alSourceUnqueueBuffers(store.getSource(0), buffer);
		queued--;
	}
	
	AL10.alSourcei(store.getSource(0), AL10.AL_BUFFER, 0);
}
 
Example #15
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Poll the bufferNames - check if we need to fill the bufferNames with another
 * section. 
 * 
 * Most of the time this should be reasonably quick
 */
public synchronized void update() {
	if (done) {
		return;
	}

	int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
	while (processed > 0) {
		unqueued.clear();
		AL10.alSourceUnqueueBuffers(source, unqueued);
		
		int bufferIndex = unqueued.get(0);

		int bufferLength = AL10.alGetBufferi(bufferIndex, AL10.AL_SIZE);

		playedPos += bufferLength;

		if (musicLength > 0 && playedPos > musicLength)
			playedPos -= musicLength;

		if (stream(bufferIndex)) {
			AL10.alSourceQueueBuffers(source, unqueued);
		} else {
			remainingBufferCount--;
			if (remainingBufferCount == 0) {
				done = true;
			}
		}
		processed--;
	}
	
	int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
	
	if (state != AL10.AL_PLAYING) {
		AL10.alSourcePlay(source);
	}
}
 
Example #16
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 #17
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the music volume of the current playing music. Does NOT affect the global volume
 * 
 * @param volume The volume for the current playing music
 */
public void setCurrentMusicVolume(float volume) {
	if (volume < 0) {
		volume = 0;
	}
	if (volume > 1) {
		volume = 1;
	}
	
	if (soundWorks) {
		lastCurrentMusicVolume = volume;
		AL10.alSourcef(sources.get(0), AL10.AL_GAIN, lastCurrentMusicVolume * musicVolume); 
	}
}
 
Example #18
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Stream one section from the mod/xm into an OpenAL buffer
 * 
 * @param bufferId The ID of the buffer to fill
 * @return True if another section was available
 */
public boolean stream(int bufferId) {
	int frames = sectionSize;
	boolean reset = false;
	boolean more = true;
	
	if (frames > songDuration) {
		frames = songDuration;
		reset = true;
	}
	
	ibxm.get_audio(data, frames);
	bufferData.clear();
	bufferData.put(data);
	bufferData.limit(frames * 4);
	
	if (reset) {
		if (loop) {
			ibxm.seek(0); 
			ibxm.set_module(module);
			songDuration = ibxm.calculate_song_duration();
		} else {
			more = false;
			songDuration -= frames;
		}
	} else {
		songDuration -= frames;
	}

	bufferData.flip();
	AL10.alBufferData(bufferId, AL10.AL_FORMAT_STEREO16, bufferData, 48000);
	
	return more;
}
 
Example #19
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the pitch at which the current music is being played
 * 
 * @param pitch The pitch at which the current music is being played
 */
public void setMusicPitch(float pitch) {
	if (soundWorks) {
		stream.setup(pitch);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	}
}
 
Example #20
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Poll the bufferNames - check if we need to fill the bufferNames with another
 * section. 
 * 
 * Most of the time this should be reasonably quick
 */
public synchronized void update() {
	if (done) {
		return;
	}

	int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
	while (processed > 0) {
		unqueued.clear();
		AL10.alSourceUnqueueBuffers(source, unqueued);
		
		int bufferIndex = unqueued.get(0);

		int bufferLength = AL10.alGetBufferi(bufferIndex, AL10.AL_SIZE);

		playedPos += bufferLength;

		if (musicLength > 0 && playedPos > musicLength)
			playedPos -= musicLength;

		if (stream(bufferIndex)) {
			AL10.alSourceQueueBuffers(source, unqueued);
		} else {
			remainingBufferCount--;
			if (remainingBufferCount == 0) {
				done = true;
			}
		}
		processed--;
	}
	
	int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
	
	if (state != AL10.AL_PLAYING) {
		AL10.alSourcePlay(source);
	}
}
 
Example #21
Source File: Wave.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final static int getFormat(int channels, int sample_size_in_bits) {
	if (channels == 1 && sample_size_in_bits == 8)
		return AL10.AL_FORMAT_MONO8;
	else if (channels == 1 && sample_size_in_bits == 16)
		return AL10.AL_FORMAT_MONO16;
	else if (channels == 2 && sample_size_in_bits == 8)
		return AL10.AL_FORMAT_STEREO8;
	else if (channels == 2 && sample_size_in_bits == 16)
		return AL10.AL_FORMAT_STEREO16;
	else
		throw new RuntimeException("Unsupported wave format");
}
 
Example #22
Source File: Mini2DxOpenALAudio.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public void setSoundPan(long soundId, float pan, float volume) {
	if (!soundIdToSource.containsKey(soundId))
		return;
	int sourceId = soundIdToSource.get(soundId);

	AL10.alSource3f(sourceId, AL10.AL_POSITION, MathUtils.cos((pan - 1) * MathUtils.PI / 2), 0,
			MathUtils.sin((pan + 1) * MathUtils.PI / 2));
	AL10.alSourcef(sourceId, AL10.AL_GAIN, volume);
}
 
Example #23
Source File: AbstractAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public void stop() {
	if (playing) {
		AL10.alSourceStop(source.getSource());
		AL10.alSourcei(source.getSource(), AL10.AL_BUFFER, AL10.AL_NONE);
		AL10.alSourceRewind(source.getSource());
		playing = false;
	}
}
 
Example #24
Source File: OpenALStreamPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Start this stream playing
 * 
 * @param loop True if the stream should loop 
 * @throws IOException Indicates a failure to read from the stream
 */
public void play(boolean loop) throws IOException {
	this.loop = loop;
	initStreams();
	
	done = false;

	AL10.alSourceStop(source);
	removeBuffers();
	
	startPlayback();
}
 
Example #25
Source File: QueuedAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
QueuedAudioPlayer(AudioSource source, AudioParameters params) {
	super(source, params);
	this.url = Utils.makeURL((String)params.sound);
	this.buffer_stream = new ByteBufferOutputStream(true);
	if ((!params.music && !Settings.getSettings().play_sfx) || this.source == null) {
		this.ogg_stream = null;
		this.channels = 0;
		this.audio = null;
		return;
	}

	if (params.relative)
		AL10.alSourcei(source.getSource(), AL10.AL_SOURCE_RELATIVE, AL10.AL_TRUE);
	else
		AL10.alSourcei(source.getSource(), AL10.AL_SOURCE_RELATIVE, AL10.AL_FALSE);
	
	setGain(params.gain);
	setPos(params.x, params.y, params.z);

	audio = new Audio(NUM_BUFFERS);
	IntBuffer al_buffers = audio.getBuffers();
	this.ogg_stream = new OGGStream(url);
	this.channels = ogg_stream.getChannels();
	for (int i = 0; i < al_buffers.capacity(); i++) {
		fillBuffer(al_buffers.get(i));
	}

	AL10.alSourcei(source.getSource(), AL10.AL_LOOPING, AL10.AL_FALSE);
	AL10.alSourcef(source.getSource(), AL10.AL_ROLLOFF_FACTOR, ROLLOFF_FACTOR);
	AL10.alSourcef(source.getSource(), AL10.AL_REFERENCE_DISTANCE, params.radius);
	AL10.alSourcef(source.getSource(), AL10.AL_MIN_GAIN, 0f);
	AL10.alSourcef(source.getSource(), AL10.AL_MAX_GAIN, 1f);
	AL10.alSourcef(source.getSource(), AL10.AL_PITCH, params.pitch);
	AL10.alSourceQueueBuffers(source.getSource(), al_buffers);
	if (params.music || AudioManager.getManager().startPlaying())
		AL10.alSourcePlay(source.getSource());

	AudioManager.getManager().registerQueuedPlayer(this);
}
 
Example #26
Source File: QueuedAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final void fillBufferFromStream(int al_buffer) {
		buffer_stream.buffer().flip();
/*		buffer_stream.buffer().limit(256);
		buffer_stream.buffer().position(0);
		for (int i = 0; i < buffer_stream.buffer().remaining(); i++)
			buffer_stream.buffer().put(i, (byte)0);*/
//System.out.println("al_buffer = " + al_buffer);
//		assert buffer_stream.buffer().remaining()%512 == 0;
		AL10.alBufferData(al_buffer, Wave.getFormat(channels, 16), buffer_stream.buffer(), ogg_stream.getRate());
	}
 
Example #27
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * Play a mod or xm track streamed from the specified location
    * 
    * @param module The moudle to play back
    * @param source The OpenAL source to play the music on
    * @param start True if the music should be started
    * @param loop True if the track should be looped
    */
public void play(Module module, int source, boolean loop, boolean start) {
	this.source = source;
	this.loop = loop;
	this.module = module;
	done = false;
	
	ibxm = new IBXM(48000);
	ibxm.set_module(module);
	songDuration = ibxm.calculate_song_duration();

	if (bufferNames != null) {
		AL10.alSourceStop(source);
		bufferNames.flip();
		AL10.alDeleteBuffers(bufferNames);
	}
	
	bufferNames = BufferUtils.createIntBuffer(2);
	AL10.alGenBuffers(bufferNames);
	remainingBufferCount = 2;
	
	for (int i=0;i<2;i++) {
        stream(bufferNames.get(i));
	}
       AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcef(source, AL10.AL_PITCH, 1.0f);
	AL10.alSourcef(source, AL10.AL_GAIN, 1.0f); 
	
	if (start) {
		AL10.alSourcePlay(source);
	}
}
 
Example #28
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 #29
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Start this stream playing
 * 
 * @param loop True if the stream should loop 
 * @throws IOException Indicates a failure to read from the stream
 */
public synchronized void play(boolean loop) throws IOException {
	this.loop = loop;
	initStreams();
	
	done = false;

	AL10.alSourceStop(source);
	
	startPlayback();
	syncStartTime = getTime();
}
 
Example #30
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Restart the music loop that is currently paused
 */
public void restartLoop() {
	if ((music) && (soundWorks) && (currentMusic != -1)){
		paused = false;
		AL10.alSourcePlay(currentMusic);
		if (stream != null)
			stream.resuming();
	}
}