Skip to content

Commit

Permalink
Add an API for the AL_EXT_SOURCE_RADIUS extension
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias <webmaster@pottgames.de>
  • Loading branch information
Hangman committed Jun 24, 2023
1 parent dd1eb0c commit 217fdca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws
this.checkRequiredExtension(ALExtension.ALC_SOFT_DEVICE_CLOCK);
this.checkRequiredExtension(ALExtension.AL_SOFT_SOURCE_SPATIALIZE);
this.checkRequiredExtension(ALExtension.ALC_SOFT_OUTPUT_MODE);
this.checkRequiredExtension(ALExtension.AL_EXT_SOURCE_RADIUS);

// LOG OUTPUT LIMITER STATE
if (config.isEnableOutputLimiter()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void reset(float attenuationFactor, float attenuationMinDistance, float attenuat
this.setAttenuationMinDistance(attenuationMinDistance);
this.detachAllEffects();
this.setResamplerByIndex(resamplerIndex);
this.setRadius(0f);
this.obtained = false;
}

Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/de/pottgames/tuningfork/SoundSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL11;
import org.lwjgl.openal.EXTEfx;
import org.lwjgl.openal.EXTSourceRadius;
import org.lwjgl.openal.SOFTDirectChannels;
import org.lwjgl.openal.SOFTSourceResampler;
import org.lwjgl.openal.SOFTSourceSpatialize;
Expand Down Expand Up @@ -173,6 +174,29 @@ public Vector3 getPosition(Vector3 saveTo) {
}


/**
* Changes the source to a "large" source with a radius. The source has a raised cosine shape. A radius of 0 is the default (point-source).<br>
* The OpenAL documentation about this is very thin. I don't know nor have the resources to test how this really works with attenuation and directionality.
* If you happen to know, please PR a fix for this javadoc.
*
* @param radius
*/
public void setRadius(float radius) {
radius = MathUtils.clamp(radius, 0f, Float.MAX_VALUE);
AL10.alSourcef(this.sourceId, EXTSourceRadius.AL_SOURCE_RADIUS, radius);
}


/**
* Returns the radius of the source.
*
* @return the radius
*/
public float getRadius() {
return AL10.alGetSourcef(this.sourceId, EXTSourceRadius.AL_SOURCE_RADIUS);
}


/**
* Sets the speed of this sound source. The speed is <b>not</b> automatically determined by changes to the position, you need to call setSpeed manually.<br>
* The speed is only used for calculating a Doppler effect. Note that you need to call set speed on the sound listener as well in order to get a proper
Expand Down

0 comments on commit 217fdca

Please sign in to comment.