public void setLooping (long soundId, boolean looping) {\r
soundPool.setLoop((int)soundId, looping?-1:0);\r
}\r
+\r
+ @Override\r
+ public void setPan (long soundId, float pan, float volume) {\r
+ float leftVolume = volume;\r
+ float rightVolume = volume;\r
+ \r
+ if(pan < 0) {\r
+ rightVolume *= (1 - Math.abs(pan));\r
+ } else\r
+ if(pan > 0) {\r
+ leftVolume *= (1 - Math.abs(pan));\r
+ }\r
+ \r
+ soundPool.setVolume((int)soundId, leftVolume, rightVolume); \r
+ }\r
}\r
import org.lwjgl.LWJGLException;\r
import org.lwjgl.openal.AL;\r
import org.lwjgl.openal.AL10;\r
+import org.lwjgl.openal.AL11;\r
\r
import com.badlogic.gdx.Audio;\r
import com.badlogic.gdx.audio.AudioDevice;\r
alSourcei(sourceId, AL_BUFFER, 0);\r
AL10.alSourcef(sourceId, AL10.AL_GAIN, 1);\r
AL10.alSourcef(sourceId, AL10.AL_PITCH, 1);\r
+ AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 0);\r
return sourceId;\r
}\r
}\r
AL10.alSourcef(sourceId, AL10.AL_PITCH, pitch);\r
}\r
\r
+ public void setSoundPan(long soundId, float pan, float volume) {\r
+ if(!soundIdToSource.containsKey(soundId)) return;\r
+ int sourceId = soundIdToSource.get(soundId);\r
+ \r
+ AL10.alSource3f(sourceId, AL10.AL_POSITION, -pan, 0, 0); \r
+ }\r
+ \r
public void dispose () {\r
for (int i = 0, n = allSources.size; i < n; i++) {\r
int sourceID = allSources.get(i);\r
public void setLooping (long soundId, boolean looping) {\r
audio.setSoundLooping(soundId, looping);\r
}\r
+\r
+ @Override\r
+ public void setPan (long soundId, float pan, float volume) {\r
+ audio.setSoundPan(soundId, pan, volume);\r
+ }\r
}\r
* @param volume the volume in the range 0 (silent) to 1 (max volume).\r
*/\r
public void setVolume(long soundId, float volume);\r
+ \r
+ /**\r
+ * Sets the panning and volume of the sound instance with the given id as returned by {@link #play()} or {@link #play(float)}. If the \r
+ * sound is no longer playing, this has no effect.\r
+ * @param soundId the sound id\r
+ * @param pan panning in the range -1 (full right) to 1 (full left). 0 is center position.\r
+ * @param volume the volume in the range [0,1].\r
+ */\r
+ public void setPan(long soundId, float pan, float volume);\r
}\r
volume.setValue(1);\r
final Label volumeValue = new Label("1.0", skin);\r
Table table = new Table("ui");\r
+ final Slider pan = new Slider(-1f, 1f, 0.1f, skin);\r
+ pan.setValue(0);\r
+ final Label panValue = new Label("0.0", skin);\r
table.width = Gdx.graphics.getWidth(); table.height = Gdx.graphics.getHeight();\r
\r
table.align(Align.CENTER | Align.TOP);\r
table.add(new Label("Volume", skin));\r
table.add(volume);\r
table.add(volumeValue);\r
+ table.row();\r
+ table.add(new Label("Pan", skin));\r
+ table.add(pan);\r
+ table.add(panValue);\r
ui.addActor(table);\r
\r
play.setClickListener(new ClickListener() {\r
@Override\r
public void click (Actor actor) {\r
- soundId = sound.play(volume.getValue());\r
+ soundId = sound.play();\r
sound.setPitch(soundId, pitch.getValue());\r
+ sound.setPan(soundId, pan.getValue(), volume.getValue());\r
}\r
});\r
\r
volumeValue.setText("" + value);\r
}\r
});\r
+ pan.setValueChangedListener(new ValueChangedListener() {\r
+ @Override\r
+ public void changed (Slider slider, float value) {\r
+ sound.setPan(soundId, value, volume.getValue());\r
+ }\r
+ });\r
Gdx.input.setInputProcessor(ui);\r
}\r
\r