You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
973 B
52 lines
973 B
package net.tortuga.sounds;
|
|
|
|
|
|
import com.porcupine.mutable.MFloat;
|
|
|
|
|
|
public class EffectPlayer {
|
|
|
|
/** the track */
|
|
private AudioX track;
|
|
|
|
/** base gain for sfx */
|
|
private double baseGain = 1;
|
|
|
|
/** base pitch for sfx */
|
|
private double basePitch = 1;
|
|
|
|
/** dedicated volume control */
|
|
private MFloat gainMultiplier = null;
|
|
|
|
private float lastUpdateComputedGain = 0;
|
|
|
|
|
|
public EffectPlayer(AudioX track, double basePitch, double baseGain, MFloat gainMultiplier) {
|
|
this.track = track;
|
|
|
|
this.baseGain = baseGain;
|
|
this.basePitch = basePitch;
|
|
|
|
this.gainMultiplier = gainMultiplier;
|
|
}
|
|
|
|
|
|
public int play(double pitch, double gain)
|
|
{
|
|
if (track == null) return -1;
|
|
|
|
double computedGain = gainMultiplier.get() * gain * baseGain;
|
|
double computedPitch = pitch * basePitch;
|
|
|
|
return track.playEffect((float) computedPitch, (float) computedGain, false);
|
|
|
|
}
|
|
|
|
|
|
public int play(double gain)
|
|
{
|
|
if (track == null) return -1;
|
|
return play(1, (float) gain);
|
|
}
|
|
|
|
}
|
|
|