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
833 B
52 lines
833 B
10 years ago
|
package mightypork.gamecore.resources.sounds;
|
||
10 years ago
|
|
||
10 years ago
|
|
||
10 years ago
|
import mightypork.utils.math.Calc;
|
||
|
import mightypork.utils.objects.Mutable;
|
||
|
|
||
|
|
||
|
/**
|
||
10 years ago
|
* Volume combined of multiple volumes, combining them (multiplication).
|
||
10 years ago
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
10 years ago
|
public class JointVolume extends Mutable<Double> {
|
||
10 years ago
|
|
||
10 years ago
|
private final Mutable<Double>[] volumes;
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
/**
|
||
10 years ago
|
* Create joint volume with master gain of 1
|
||
10 years ago
|
*
|
||
10 years ago
|
* @param volumes individual volumes to join
|
||
10 years ago
|
*/
|
||
10 years ago
|
public JointVolume(Mutable<Double>... volumes) {
|
||
|
super(1D);
|
||
10 years ago
|
this.volumes = volumes;
|
||
|
}
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
/**
|
||
|
* Get combined gain (multiplied)
|
||
|
*/
|
||
|
@Override
|
||
10 years ago
|
public Double get()
|
||
10 years ago
|
{
|
||
10 years ago
|
double d = super.get();
|
||
10 years ago
|
for (final Mutable<Double> v : volumes)
|
||
10 years ago
|
d *= v.get();
|
||
10 years ago
|
|
||
10 years ago
|
return Calc.clampd(d, 0, 1);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
/**
|
||
|
* Set master gain
|
||
|
*/
|
||
|
@Override
|
||
10 years ago
|
public void set(Double o)
|
||
10 years ago
|
{
|
||
|
super.set(o);
|
||
|
}
|
||
|
}
|