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