17.7. Sample bank and audio file loading
Module strudel_samples
17.7.1. Structures
- Sample
- Fields:
data : array<float> - Interleaved PCM float samples (left, right, left, right, …).
channels : int = 1 - Channel count (1 = mono, 2 = stereo).
sample_rate : int = 48000 - Native sample rate of the decoded audio in Hz.
- SampleBank
- Fields:
sounds : table<string;array< Sample>> - Map from lowercase sound name to its indexed variations (bd:0, bd:1, …).
17.7.2. Loading
- load_audio_file(path: string): Sample
Decode a single audio file (WAV/MP3/FLAC/OGG) from disk into a Sample. Keeps the native channel count (mono or stereo); returns an empty Sample on failure.
- Arguments:
path : string
- load_audio_memory(data: array<uint8>): Sample
Decode audio bytes (WAV/MP3/FLAC/OGG) from memory into a Sample. Uses miniaudio’s memory decoder with explicit error checking; returns an empty Sample on failure.
- Arguments:
data : array<uint8>
- load_sound(path: string; name: string; bank: SampleBank)
Load a single named sound from a directory of audio files into the bank. Files are sorted alphabetically so index :0, :1, … matches strudel’s sample indexing.
- Arguments:
path : string
name : string
bank : SampleBank
- load_sound_memory(data: array<uint8>; name: string; bank: SampleBank)
Decode audio bytes and add the result as a single-variation sound in the bank.
- Arguments:
data : array<uint8>
name : string
bank : SampleBank
17.7.3. Rendering
- render_sample(bank: SampleBank; name: string; variation: int; speed: float; begin: float = 0f; end_pos: float = 1f): array<float>
Render a sample slice at the given playback speed as interleaved stereo. begin/end_pos are normalized [0.0..1.0] slice bounds used by striate/chop/loop_at; speed resamples via miniaudio and mono input is upmixed to stereo. No gain/pan applied.
- Arguments:
bank : SampleBank
name : string
variation : int
speed : float
begin : float
end_pos : float