lmaudio

lmaudio is a native lmcode host for offline audio: synthesis, physical models, filters, effects and analysis in one static executable scripted from LMScript. It renders deterministic WAV, CSV and numeric results and needs no sound card.

Install and run

npm install -g @lmctl-ai/lmctl
lmscript hello.lms
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmaudio/main/examples/drum_machine_pattern.lms

A block that declares cli="lmaudio" and install="github:lmctl-ai/lmaudio@latest" compiles against the schema embedded in the lmaudio binary. lmscript uses lmaudio from PATH, or downloads the release binary into its tool cache on first use. The latest release is v0.2.2.

Host protocol and flags

Command or variableEffect
lmaudio --versionPrints the release identity, for example lmaudio 0.2.2.
lmaudio --noticesPrints the third-party software notices with the upstream license texts.
lmaudio --lmcode-schemaPrints the embedded schema as readable JSON.
lmaudio --lmcode-schema --jsonPrints the exact schema bytes the compiler binds a program to (schema version 2, name lmaudio).
lmaudio --lmcode-signaturesPrints every canonical signature the host registry provides, one per line, standard catalog included.
lmaudio --lmcode FILE [FILE ...]Runs compiled lmcode program files. This is what run_lmcode calls; the compiler owns the program files.
lmaudio --dry-run --lmcode FILERuns a program without writing any file. The flag comes before --lmcode. The result envelope carries dry true.
LMAUDIO_MAX_MEMORY_MBEnvironment variable: total memory budget in MiB, default 4096. A value that is not a positive whole number is a usage error on every command.
Exit codeEnvelopeMeaning
0ok trueThe program ran and every audio.assert_close held.
2phase cli, code CLI_USAGEUnknown or misplaced arguments, or an invalid LMAUDIO_MAX_MEMORY_MB.
3phase load, for example code LOAD_BAD_BYTECODE or LOAD_UNBOUNDThe program file cannot be read, or it imports a function the host does not provide.
3phase run, code RUN_HOSTA host error with a source line and column: a failed audio.assert_close, a missing WAV file, an invalid argument, or the memory budget being exceeded.

Every --lmcode run ends with one JSON envelope on stdout between the lines LMCODE_RETURN_BEGIN and LMCODE_RETURN_END. run_lmcode decodes it and returns a map with ok and result on success, or ok false with phase, code, message, line and column on failure.

Schema quick reference

ItemValue
Schemadsl.schema 2, name lmaudio
Context objectaudio, of type Audio
Host typesAudio (28 methods), Buffer (58 methods), Spectrum (16 methods), Spectrogram (9 methods), Biquad (10 methods)
Host signatures171
Standard signatures206 of lmcode_std_v3 (the current catalog has 226)
Total from lmaudio --lmcode-signatures377
Unitsseconds, Hz, linear amplitude unless a name says db
Sample rate100 to 384000 Hz, 44100 when omitted
Buffersmono or stereo, 32-bit float, at most 200 million frames

Main objects and functions

ObjectWhat it doesMain members
audio (Audio)Makes sound and holds helperssilence, sine, cosine, saw, square, triangle, chirp, impulse, noise, expr, additive, fm, karplus, pluck, modal, bar, drum, sequence, load_wav, stereo, biquad_design, note_freq, midi_freq, cents, db, print, save_text, assert_close
Buffer: levels and envelopesReturns a new buffergain, gain_db, normalize, normalize_rms, normalize_lufs, fade, adsr, multiply, pan
Buffer: editingReturns a new bufferslice, pad, concat, mix, reverse, resample, channel, to_mono, pattern, granular
Buffer: filters and effectsReturns a new bufferbiquad, svf, ladder, lpf_sweep, convolve, reverb, zitarev, delay, chorus, flanger, phaser, compress, overdrive, wavefold, bitcrush, paulstretch
Buffer: measurementReturns numbersrms, peak, dc_offset, energy, zcr, duration, frames, sr, channels, get, pitch, lufs, rt60, peak_freq, centroid, thd, snr_db
Buffer: analysis objectsReturns Spectrum, Spectrogram or Bufferspectrum, spectrogram, schroeder_db
Buffer: outputWrites files and returns the buffersave_wav, save_csv, pitch_track_csv
SpectrumReads one FFTmag_at_freq, peak_freq_in, peak_freq, peak_mag, db_at, phase_at, ifft, parseval_energy, save_csv
SpectrogramReads an STFT gridframes, bins, time_at, freq_at, mag_at, db_at, ridge_freq, save_csv
BiquadExact filter responsegain_at, db_at, phase_deg_at, apply, save_response_csv, b0, b1, b2, a1, a2
Standard functionsValues back to LMScript and general helperslmcode_return_put, lmcode_return_set, str_split, float_list, json_parse, file_write

Minimal runnable example

Save as hello.lms in an empty directory and run lmscript hello.lms. It renders an arpeggio, normalizes it to -16 LUFS, checks the loudness, saves a WAV file and returns two numbers to LMScript.

# hello.lms: an A major arpeggio on a plucked string, checked and saved
mkdir("audio");
a = _lmcode_ cli="lmaudio" install="github:lmctl-ai/lmaudio@latest";
let arp = audio.sequence("A3:0.5 C#4:0.5 E4:0.5 A4:1.5", 120.0, "karplus", 22050);
let out = arp.reverb(0.8, 6500.0, 0.25).normalize_lufs(-16.0);
audio.assert_close(out.lufs(), -16.0, 0.01);
audio.print("pitch of the first note: " + str(arp.slice(0.0, 0.25).pitch()) + " Hz");
out.save_wav("audio/hello.wav", 16);
lmcode_return_put("lufs", out.lufs());
lmcode_return_put("seconds", out.duration());
end _lmcode_
r = run_lmcode(a);
println(json_stringify(r));
assert(r.ok);
lmscript hello.lms
pitch of the first note: 219.959988525778 Hz
lmaudio: warning: 1 sample(s) outside [-1, 1] were clipped while writing audio/hello.wav (16-bit PCM); normalize() first or save with bits=32
{"ok":true,"result":{"lufs":-16.00000004683295,"seconds":1.5000907029478459}}

More detail