README

mizchi/kagura_engine/audio does not have a README file

#
AudioContext

pub trait AudioContext {
fn create_player(Self, clip : AudioClip) -> PlayerId raise
fn play(Self, id : PlayerId) -> Unit raise
fn pause(Self, id : PlayerId) -> Unit raise
fn stop(Self, id : PlayerId) -> Unit raise
fn state(Self, id : PlayerId) -> PlayerState
fn set_volume(Self, id : PlayerId, volume : Double) -> Unit
fn current_position(Self, id : PlayerId) -> Double
fn seek(Self, id : PlayerId, position : Double) -> Unit raise
fn set_pan(Self, id : PlayerId, pan : Double) -> Unit
fn dispose(Self, id : PlayerId) -> Unit
}

#
AudioStream

pub trait AudioStream {
fn read(Self, buf : FixedArray[Byte], length : Int) -> Int
fn content_length(Self) -> Int
}

#
AudioClip

pub struct AudioClip {
format : AudioFormat
data : Bytes
loop_ : Bool
} derive(
Debug
)

impl Show for AudioClip

#
AudioClipStream

pub struct AudioClipStream {
clip : AudioClip
position : Int
}

Stream that reads sequentially from an AudioClip.

#
AudioClipStream::new

#
AudioClipStream::remaining

fn AudioClipStream::remaining(self : AudioClipStream) -> Int

#
AudioClipStream::reset

fn AudioClipStream::reset(self : AudioClipStream) -> Unit

#
AudioFormat

pub struct AudioFormat {
sample_rate : Int
channels : Int
bits_per_sample : Int
} derive(
Debug
)

impl Show for AudioFormat

#
AudioOutputHooks

pub struct AudioOutputHooks {
try_initialize : (AudioFormat) -> Bool
write_frames : (FixedArray[Float], Int) -> Int
suspend : () -> Unit
resume_playback : () -> Unit
close : () -> Unit
output_latency : () -> Double
}

Audio output hooks for backend integration (Web Audio API / native audio).

#
AudioOutputStats

pub struct AudioOutputStats {
initialized : Bool
frames_written : Int
suspended : Bool
} derive(
Debug
)

#
BufferedAudioStream

pub struct BufferedAudioStream {
chunks : Array[Bytes]
total_bytes : Int
read_chunk_idx : Int
read_byte_idx : Int
finalized : Bool
final_length : Int
}

Buffered stream that accumulates audio data chunks progressively. Useful for network streaming or progressive decoding.

#
BufferedAudioStream::buffered_bytes

fn BufferedAudioStream::buffered_bytes(self : BufferedAudioStream) -> Int

Get the number of bytes available for reading.

#
BufferedAudioStream::finalize

fn BufferedAudioStream::finalize(self : BufferedAudioStream) -> Unit

Mark the stream as complete with known total length.

#
BufferedAudioStream::has_data

fn BufferedAudioStream::has_data(self : BufferedAudioStream) -> Bool

Check if more data is available to read.

#
BufferedAudioStream::is_finalized

fn BufferedAudioStream::is_finalized(self : BufferedAudioStream) -> Bool

#
BufferedAudioStream::new

#
BufferedAudioStream::push_chunk

fn BufferedAudioStream::push_chunk(self : BufferedAudioStream, data : Bytes) -> Unit

Append a data chunk to the stream buffer.

#
BufferedAudioStream::reset

fn BufferedAudioStream::reset(self : BufferedAudioStream) -> Unit

#
MixerAudioContext

pub struct MixerAudioContext {
mixer :
Mixer

player_map : Array[(PlayerId,
VoiceId
)]
next_id : Int
bgm_player_id : PlayerId?
bgm_fade_target : Double
bgm_fade_speed : Double
bgm_current_volume : Double
bgm_outgoing_id : PlayerId?
bgm_outgoing_volume : Double
bgm_outgoing_fade_speed : Double
}

MixerAudioContext wraps mizchi/audio's Mixer to implement AudioContext.

#
MixerAudioContext::crossfade_bgm

fn MixerAudioContext::crossfade_bgm(self : MixerAudioContext, clip : AudioClip, duration_seconds : Double, volume? : Double) -> Unit

Crossfade from the current BGM to a new BGM clip. The old BGM fades out and the new BGM fades in over duration_seconds.

#
MixerAudioContext::dispose_outgoing_bgm

fn MixerAudioContext::dispose_outgoing_bgm(self : MixerAudioContext) -> Unit

Dispose the outgoing BGM player.

#
MixerAudioContext::fade_bgm

fn MixerAudioContext::fade_bgm(self : MixerAudioContext, target_volume : Double, duration_seconds : Double) -> Unit

Start a volume fade on the BGM.

#
MixerAudioContext::new

fn MixerAudioContext::new(sample_rate : Int) -> MixerAudioContext

#
MixerAudioContext::pause_bgm

fn MixerAudioContext::pause_bgm(self : MixerAudioContext) -> Unit

Pause the current BGM.

#
MixerAudioContext::play_bgm

fn MixerAudioContext::play_bgm(self : MixerAudioContext, clip : AudioClip, volume? : Double) -> Unit

Play a BGM clip with looping. Stops any currently playing BGM.

#
MixerAudioContext::render

fn MixerAudioContext::render(self : MixerAudioContext, frames : Int, output : FixedArray[Float]) -> Unit

Render audio frames into an output buffer.

#
MixerAudioContext::resume_bgm

fn MixerAudioContext::resume_bgm(self : MixerAudioContext) -> Unit

Resume the current BGM.

#
MixerAudioContext::set_bgm_volume

fn MixerAudioContext::set_bgm_volume(self : MixerAudioContext, volume : Double) -> Unit

Set BGM volume immediately.

#
MixerAudioContext::stop_bgm

fn MixerAudioContext::stop_bgm(self : MixerAudioContext) -> Unit

Stop and dispose the current BGM and any outgoing BGM.

#
MixerAudioContext::tick_bgm

fn MixerAudioContext::tick_bgm(self : MixerAudioContext, frames : Int) -> Unit

Advance BGM fade by the given number of audio frames. Call this once per audio tick from the engine loop.

#
PlayerId

pub(all) struct PlayerId {
value : Int
} derive(
Debug
)

impl Show for PlayerId

#
PlayerState

pub enum PlayerState {
Stopped
Playing
Paused
} derive(
Debug
)

impl Show for PlayerState

#
SimpleAudioContext

pub struct SimpleAudioContext {
players : Array[SimpleAudioPlayer]
next_id : Int
format : AudioFormat
}

#
SimpleAudioContext::new

#
SimpleAudioContext::player_count

fn SimpleAudioContext::player_count(self : SimpleAudioContext) -> Int

#
SimpleAudioContext::tick

fn SimpleAudioContext::tick(self : SimpleAudioContext, samples : Int) -> Unit

Advance all playing players by the given number of samples.

#
SimpleAudioPlayer

pub struct SimpleAudioPlayer {
id : PlayerId
clip : AudioClip
state : PlayerState
volume : Double
position_samples : Int
}

#
audio_buffer_to_clip

fn audio_buffer_to_clip(buffer :
AudioBuffer
, loop_ : Bool) -> AudioClip

Convert a mizchi/audio AudioBuffer to an AudioClip. Converts Float samples to 16-bit PCM Bytes.

#
audio_close

fn audio_close() -> Unit

#
audio_output_latency

fn audio_output_latency() -> Double

#
audio_render_and_write

fn audio_render_and_write(mixer : MixerAudioContext, frames : Int) -> Int

Render audio from a MixerAudioContext and write to output hooks. Returns the number of frames actually written.

#
audio_resume

fn audio_resume() -> Unit

#
audio_suspend

fn audio_suspend() -> Unit

#
audio_try_initialize

fn audio_try_initialize(format : AudioFormat) -> Bool

#
audio_write_frames

fn audio_write_frames(output : FixedArray[Float], frames : Int) -> Int

#
bytes_per_sample

fn bytes_per_sample(format : AudioFormat) -> Int

#
bytes_to_samples

fn bytes_to_samples(format : AudioFormat, byte_count : Int) -> Int

#
cd_quality_format

fn cd_quality_format() -> AudioFormat

#
clip_duration

fn clip_duration(clip : AudioClip) -> Double

#
clip_sample_count

fn clip_sample_count(clip : AudioClip) -> Int

#
clip_to_audio_buffer

fn clip_to_audio_buffer(clip : AudioClip) ->
AudioBuffer

Convert an AudioClip back to a mizchi/audio AudioBuffer. Assumes 16-bit PCM format.

#
decode_audio_clip_auto

fn decode_audio_clip_auto(data : Bytes, loop_ : Bool) -> AudioClip? raise
AudioError

Detect audio format from bytes and decode accordingly. Returns None if format is not recognized.

#
decode_ogg_clip

fn decode_ogg_clip(ogg_bytes : Bytes, loop_ : Bool) -> AudioClip raise
AudioError

Decode OGG/Vorbis bytes into an AudioClip.

#
decode_wav_clip

fn decode_wav_clip(wav_bytes : Bytes, loop_ : Bool) -> AudioClip raise
AudioError

Decode WAV bytes into an AudioClip.

#
default_audio_format

fn default_audio_format() -> AudioFormat

#
default_audio_output_stats

fn default_audio_output_stats() -> AudioOutputStats

Create default AudioOutputStats.

#
detect_audio_format

fn detect_audio_format(data : Bytes) -> String

Detect audio format from magic bytes. Returns "wav", "ogg", or empty string if unknown.

#
duration_to_samples

fn duration_to_samples(format : AudioFormat, seconds : Double) -> Int

#
mono_format

fn mono_format(sample_rate : Int) -> AudioFormat

#
new_audio_clip

fn new_audio_clip(format : AudioFormat, data : Bytes, loop_ : Bool) -> AudioClip

#
new_audio_output_hooks

fn new_audio_output_hooks(try_initialize : (AudioFormat) -> Bool, write_frames : (FixedArray[Float], Int) -> Int, suspend : () -> Unit, resume_playback : () -> Unit, close : () -> Unit) -> AudioOutputHooks

#
new_audio_output_hooks_full

fn new_audio_output_hooks_full(try_initialize : (AudioFormat) -> Bool, write_frames : (FixedArray[Float], Int) -> Int, suspend : () -> Unit, resume_playback : () -> Unit, close : () -> Unit, output_latency : () -> Double) -> AudioOutputHooks

#
new_tracked_audio_output_hooks

fn new_tracked_audio_output_hooks(inner : AudioOutputHooks, stats :
Ref
[AudioOutputStats]) -> AudioOutputHooks

Create a tracked AudioOutputHooks wrapper that updates stats.

#
pcm16_format

fn pcm16_format(sample_rate : Int, channels : Int) -> AudioFormat

#
reset_audio_output_hooks

fn reset_audio_output_hooks() -> Unit

#
samples_to_bytes

fn samples_to_bytes(format : AudioFormat, sample_count : Int) -> Int

#
samples_to_duration

fn samples_to_duration(format : AudioFormat, sample_count : Int) -> Double

#
set_audio_output_hooks

fn set_audio_output_hooks(hooks : AudioOutputHooks) -> Unit

Source Files