|
|
|
@ -19,50 +19,50 @@ import mightypork.utils.math.constraints.vect.Vect; |
|
|
|
|
* @author Ondřej Hruška (MightyPork) |
|
|
|
|
*/ |
|
|
|
|
public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set listener position |
|
|
|
|
* |
|
|
|
|
* @param pos listener position |
|
|
|
|
*/ |
|
|
|
|
public abstract void setListenerPos(Vect pos); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get current listener position |
|
|
|
|
* |
|
|
|
|
* @return listener position |
|
|
|
|
*/ |
|
|
|
|
public abstract Vect getListenerPos(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -- instance --
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Volume masterVolume = new Volume(1D); |
|
|
|
|
private final Volume effectsVolume = new JointVolume(masterVolume); |
|
|
|
|
private final Volume loopsVolume = new JointVolume(masterVolume); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<LoopPlayer> loopPlayers = new ArrayList<>(); |
|
|
|
|
private final List<DeferredAudio> resources = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void destroy() |
|
|
|
|
{ |
|
|
|
|
for (final DeferredAudio r : resources) { |
|
|
|
|
r.destroy(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deinitSoundSystem(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Deinitialize the soud system, release resources etc.<br> |
|
|
|
|
* Audio resources are already destroyed. |
|
|
|
|
*/ |
|
|
|
|
protected abstract void deinitSoundSystem(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void update(double delta) |
|
|
|
|
{ |
|
|
|
@ -70,67 +70,64 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
lp.update(delta); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create effect resource |
|
|
|
|
* |
|
|
|
|
* @param resource resource path |
|
|
|
|
* @param pitch default pitch (1 = unchanged) |
|
|
|
|
* @param gain default gain (0-1) |
|
|
|
|
* @return player |
|
|
|
|
*/ |
|
|
|
|
public EffectPlayer createEffect(String resource, double pitch, double gain) |
|
|
|
|
public EffectPlayer createEffect(String resource) |
|
|
|
|
{ |
|
|
|
|
return new EffectPlayer(createAudio(resource), pitch, gain, effectsVolume); |
|
|
|
|
return new EffectPlayer(createAudioResource(resource), effectsVolume); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Register loop resource (music / effect loop) |
|
|
|
|
* |
|
|
|
|
* @param resource resource path |
|
|
|
|
* @param pitch default pitch (1 = unchanged) |
|
|
|
|
* @param gain default gain (0-1) |
|
|
|
|
* @param fadeIn default time for fadeIn |
|
|
|
|
* @param fadeOut default time for fadeOut |
|
|
|
|
* @return player |
|
|
|
|
*/ |
|
|
|
|
public LoopPlayer createLoop(String resource, double pitch, double gain, double fadeIn, double fadeOut) |
|
|
|
|
public LoopPlayer createLoop(String resource) |
|
|
|
|
{ |
|
|
|
|
final LoopPlayer p = new LoopPlayer(createAudio(resource), pitch, gain, loopsVolume); |
|
|
|
|
p.setFadeTimes(fadeIn, fadeOut); |
|
|
|
|
final LoopPlayer p = new LoopPlayer(createAudioResource(resource), loopsVolume); |
|
|
|
|
loopPlayers.add(p); |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create {@link DeferredAudio} for a resource, request deferred load and |
|
|
|
|
* add to the resources list. |
|
|
|
|
* add to the resources list.<br> |
|
|
|
|
* The method is accessed only from within this class, since the sound |
|
|
|
|
* registry holds players, not the resources themselves. |
|
|
|
|
* |
|
|
|
|
* @param res a resource name |
|
|
|
|
* @return the resource |
|
|
|
|
* @throws IllegalArgumentException if resource is already registered |
|
|
|
|
*/ |
|
|
|
|
protected DeferredAudio createAudio(String res) |
|
|
|
|
protected final DeferredAudio createAudioResource(String res) |
|
|
|
|
{ |
|
|
|
|
final DeferredAudio a = doCreateResource(res); |
|
|
|
|
App.bus().send(new ResourceLoadRequest(a)); |
|
|
|
|
resources.add(a); |
|
|
|
|
return a; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a backend-specific deferred audio resource |
|
|
|
|
* Create a backend-specific deferred audio resource.<br> |
|
|
|
|
* The actual resource instance should be created here. Registering, loading |
|
|
|
|
* etc. is handled higher. |
|
|
|
|
* |
|
|
|
|
* @param res resource path |
|
|
|
|
* @return Deferred Audio |
|
|
|
|
*/ |
|
|
|
|
protected abstract DeferredAudio doCreateResource(String res); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Fade out all loops (= fade out the currently playing loops) |
|
|
|
|
*/ |
|
|
|
@ -140,8 +137,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
p.fadeOut(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Pause all loops (leave volume unchanged) |
|
|
|
|
*/ |
|
|
|
@ -151,8 +148,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
p.pause(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set level of master volume (volume multiplier) |
|
|
|
|
* |
|
|
|
@ -162,8 +159,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
{ |
|
|
|
|
masterVolume.set(volume); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set level of effects volume (volume multiplier) |
|
|
|
|
* |
|
|
|
@ -173,8 +170,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
{ |
|
|
|
|
effectsVolume.set(volume); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set level of loops volume (volume multiplier) |
|
|
|
|
* |
|
|
|
@ -184,8 +181,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
{ |
|
|
|
|
loopsVolume.set(volume); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get level of master volume (volume multiplier) |
|
|
|
|
* |
|
|
|
@ -195,8 +192,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
{ |
|
|
|
|
return masterVolume.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get level of effects volume (volume multiplier) |
|
|
|
|
* |
|
|
|
@ -206,8 +203,8 @@ public abstract class AudioModule extends BackendModule implements Updateable { |
|
|
|
|
{ |
|
|
|
|
return effectsVolume.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get level of loops volume (volume multiplier) |
|
|
|
|
* |
|
|
|
|