Package limn.sound
Record Class PlayOptions
java.lang.Object
java.lang.Record
limn.sound.PlayOptions
- Record Components:
gain- volume in [0..1], multiplied by the bus and master gainspitch- playback-rate multiplier in [0.25..4], where 1 is natural; the standard de-repetition trick is a small random variationpan- stereo position in [-1..1] (left..right, 0 = center). Realized for MONO clips; stereo clips ignore itloop- repeat until stoppedbus- the mixer bus this playback belongs topriority- voice-steal class: when every voice is busy, lower-priority sounds are stolen first and a sound never steals a higher-priority voice; mark music/dialogPlayOptions.Priority.HIGHso an effects burst cannot silence itposition- world position for 3D attenuation/panning, ornullfor plain 2D playback. Mono clips only (OpenAL constraint); pair withSounds.setListener(limn.math.Vec3, limn.math.Vec3, limn.math.Vec3). Overridespan
public record PlayOptions(float gain, float pitch, float pan, boolean loop, AudioBus bus, PlayOptions.Priority priority, Vec3 position)
extends Record
How to play a sound: volume, pitch, stereo pan or 3D position, looping,
mixer
bus and voice-steal PlayOptions.Priority. Immutable;
start from DEFAULTS and derive with the with* methods
(Transform3D-style):
Sounds.play(step, PlayOptions.DEFAULTS.withPitch(0.9f + random * 0.2f));
Sounds.play(song, PlayOptions.DEFAULTS.withBus(AudioBus.MUSIC)
.withPriority(PlayOptions.Priority.HIGH).withLoop(true));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumVoice-steal class; seepriority. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PlayOptionsGain 1, pitch 1, centered, no loop,AudioBus.SFX, NORMAL priority, 2D. -
Constructor Summary
ConstructorsConstructorDescriptionPlayOptions(float gain, float pitch, float pan, boolean loop, AudioBus bus, PlayOptions.Priority priority, Vec3 position) Creates an instance of aPlayOptionsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionat(float x, float y, float z) Positional 3D playback at (x,y,z): mono clips only.bus()Returns the value of thebusrecord component.final booleanIndicates whether some other object is "equal to" this one.floatgain()Returns the value of thegainrecord component.final inthashCode()Returns a hash code value for this object.booleanloop()Returns the value of thelooprecord component.floatpan()Returns the value of thepanrecord component.floatpitch()Returns the value of thepitchrecord component.position()Returns the value of thepositionrecord component.priority()Returns the value of thepriorityrecord component.final StringtoString()Returns a string representation of this record class.A copy routed through a different mixer bus.withGain(float newGain) A copy at a different volume,[0..1].withLoop(boolean newLoop) A copy that repeats until stopped.withPan(float newPan) A copy at a different stereo position,[-1..1].withPitch(float newPitch) A copy at a different playback rate,[0.25..4], where 1 is natural.withPriority(PlayOptions.Priority newPriority) A copy in a different voice-steal class.
-
Field Details
-
DEFAULTS
Gain 1, pitch 1, centered, no loop,AudioBus.SFX, NORMAL priority, 2D.
-
-
Constructor Details
-
PlayOptions
public PlayOptions(float gain, float pitch, float pan, boolean loop, AudioBus bus, PlayOptions.Priority priority, Vec3 position) Creates an instance of aPlayOptionsrecord class.- Parameters:
gain- the value for thegainrecord componentpitch- the value for thepitchrecord componentpan- the value for thepanrecord componentloop- the value for thelooprecord componentbus- the value for thebusrecord componentpriority- the value for thepriorityrecord componentposition- the value for thepositionrecord component
-
-
Method Details
-
withGain
A copy at a different volume,[0..1]. -
withPitch
A copy at a different playback rate,[0.25..4], where 1 is natural. -
withPan
A copy at a different stereo position,[-1..1]. Ignored for stereo clips. -
withLoop
A copy that repeats until stopped. -
withBus
A copy routed through a different mixer bus. -
withPriority
A copy in a different voice-steal class. -
at
Positional 3D playback at (x,y,z): mono clips only. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
gain
public float gain()Returns the value of thegainrecord component.- Returns:
- the value of the
gainrecord component
-
pitch
public float pitch()Returns the value of thepitchrecord component.- Returns:
- the value of the
pitchrecord component
-
pan
public float pan()Returns the value of thepanrecord component.- Returns:
- the value of the
panrecord component
-
loop
public boolean loop()Returns the value of thelooprecord component.- Returns:
- the value of the
looprecord component
-
bus
Returns the value of thebusrecord component.- Returns:
- the value of the
busrecord component
-
priority
Returns the value of thepriorityrecord component.- Returns:
- the value of the
priorityrecord component
-
position
Returns the value of thepositionrecord component.- Returns:
- the value of the
positionrecord component
-