Package limn.sound
Class AudioClip
java.lang.Object
limn.sound.AudioClip
An immutable, backend-independent chunk of PCM audio: interleaved 16-bit
signed samples, 1 (mono) or 2 (stereo) channels, at a given sample rate.
Backend-neutral like
Image: decoded/synthesized
once on the CPU, then handed to the running AudioEngine (via
Sounds.play(limn.sound.AudioClip)) which uploads it to the device lazily and caches the
device buffer keyed by object identity, so replaying the same instance (a UI
beep, a shared sound effect) is cheap.
Two ways to get one:
tone(float, float, float): synthesize a sine tone (the shape the system beep is built from);Sounds.decode(byte[])/Sounds.load(java.nio.file.Path)/Sounds.fromResource(java.lang.String): decode an encoded file (WAV/OGG) through the backend decoder.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe sample rate used bytone(float, float, float)and the default for synthesis. -
Method Summary
Modifier and TypeMethodDescriptionintchannels()doubleintstatic AudioClipof(short[] interleavedSamples, int channels, int sampleRate) Wraps raw interleaved 16-bit PCM.intshort[]samples()static AudioCliptone(float frequencyHz, float durationSeconds, float amplitude) Synthesizes a mono sine tone with a raised-cosine fade in/out envelope (so it starts and ends silently, avoiding clicks) atDEFAULT_SAMPLE_RATE.
-
Field Details
-
DEFAULT_SAMPLE_RATE
public static final int DEFAULT_SAMPLE_RATEThe sample rate used bytone(float, float, float)and the default for synthesis.- See Also:
-
-
Method Details
-
of
Wraps raw interleaved 16-bit PCM. The array is taken by reference (not copied) and must not be mutated afterwards, mirroringImage's zero-copy contract.- Parameters:
interleavedSamples- interleaved signed 16-bit samples (frameCount * channelslong)channels- 1 (mono) or 2 (stereo)sampleRate- frames per second (e.g. 44100)
-
tone
Synthesizes a mono sine tone with a raised-cosine fade in/out envelope (so it starts and ends silently, avoiding clicks) atDEFAULT_SAMPLE_RATE. This is the primitive the system alert beep is made of; applications can use it for UI feedback without shipping an asset.- Parameters:
frequencyHz- pitch in hertz (e.g. 660)durationSeconds- length in seconds (e.g. 0.09)amplitude- peak amplitude in [0..1] (e.g. 0.5)
-
samples
public short[] samples()- Returns:
- the raw interleaved 16-bit samples (do not mutate)
-
channels
public int channels()- Returns:
- the channel count (1 mono, 2 stereo)
-
sampleRate
public int sampleRate()- Returns:
- frames per second
-
frameCount
public int frameCount()- Returns:
- the number of frames (samples per channel)
-
durationSeconds
public double durationSeconds()- Returns:
- the playback length in seconds
-