Package limn.sound

Class AudioClip

java.lang.Object
limn.sound.AudioClip

public final class AudioClip extends Object
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:

  • Field Details

  • Method Details

    • of

      public static AudioClip of(short[] interleavedSamples, int channels, int sampleRate)
      Wraps raw interleaved 16-bit PCM. The array is taken by reference (not copied) and must not be mutated afterwards, mirroring Image's zero-copy contract.
      Parameters:
      interleavedSamples - interleaved signed 16-bit samples (frameCount * channels long)
      channels - 1 (mono) or 2 (stereo)
      sampleRate - frames per second (e.g. 44100)
    • tone

      public static AudioClip tone(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) at DEFAULT_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