Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix playback volume of mono sounds in the lwjgl3 backend #7365

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Android: Add configuration option to render under the cutout if available on the device.
- Fix: Keep SelectBox popup from extending past right edge of stage.
- Added Framebuffer multisample support (see GL31FrameBufferMultisampleTest.java for basic usage)
- Fixed playback volume of mono sounds and improved panning quality

[1.12.1]
- LWJGL3 Improvement: Audio device is automatically switched if it was changed in the operating system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.audio.AudioRecorder;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.IntArray;
Expand Down Expand Up @@ -108,6 +107,9 @@ public OpenALLwjgl3Audio (int simultaneousSources, int deviceBufferCount, int de
for (int i = 0; i < simultaneousSources; i++) {
int sourceID = alGenSources();
if (alGetError() != AL_NO_ERROR) break;
alSourcef(sourceID, AL_ROLLOFF_FACTOR, 0f);
alSourcei(sourceID, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcei(sourceID, SOFTDirectChannels.AL_DIRECT_CHANNELS_SOFT, SOFTDirectChannelsRemix.AL_REMIX_UNMATCHED_SOFT);
allSources.add(sourceID);
}
idleSources = new IntArray(allSources);
Expand Down Expand Up @@ -248,8 +250,7 @@ int obtainSource (boolean isMusic) {
alSourcei(sourceId, AL_BUFFER, 0);
AL10.alSourcef(sourceId, AL10.AL_GAIN, 1);
AL10.alSourcef(sourceId, AL10.AL_PITCH, 1);
AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 1f);
AL10.alSourcei(sourceId, SOFTDirectChannels.AL_DIRECT_CHANNELS_SOFT, SOFTDirectChannelsRemix.AL_REMIX_UNMATCHED_SOFT);
AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 0);
return sourceId;
}
}
Expand Down Expand Up @@ -358,8 +359,7 @@ public void setSoundPitch (long soundId, float pitch) {
public void setSoundPan (long soundId, float pan, float volume) {
int sourceId = soundIdToSource.get(soundId, -1);
if (sourceId != -1) {
AL10.alSource3f(sourceId, AL10.AL_POSITION, MathUtils.cos((pan - 1) * MathUtils.HALF_PI), 0,
MathUtils.sin((pan + 1) * MathUtils.HALF_PI));
AL10.alSource3f(sourceId, AL10.AL_POSITION, pan, 0, (float)-Math.sqrt(1d - pan * pan));
AL10.alSourcef(sourceId, AL10.AL_GAIN, volume);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.GdxRuntimeException;

Expand Down Expand Up @@ -157,8 +156,7 @@ public void setPan (float pan, float volume) {
this.pan = pan;
if (audio.noDevice) return;
if (sourceID == -1) return;
alSource3f(sourceID, AL_POSITION, MathUtils.cos((pan - 1) * MathUtils.HALF_PI), 0,
MathUtils.sin((pan + 1) * MathUtils.HALF_PI));
alSource3f(sourceID, AL_POSITION, pan, 0, (float)-Math.sqrt(1d - pan * pan));
alSourcef(sourceID, AL_GAIN, volume);
}

Expand Down