ws-audio2: api renderMusic uses a Module's own render method for non-tracker engines (AHX / HVL); docs/guide/music.md: AHX / HVL and MIDI variants section, Formats rows (docs inputs: tools/fixtures/docs_chip.py)
src/Formats/init.luau: renderMusic: a kind "music" value whose format is not mod/s3m/xm/it and that has a render method renders through it (a failed render's .err becomes the error). Backward compatible.
This commit is contained in:
1 parent
71bb89763e
commit
d3ea84bb57
4 files changed
+126
-1
No files matched your search
@@ -312,9 +312,65 @@ assert(F.music.load(assert(F.save(xm))).instruments[1].name == "lead")
|
||||
| s3m, it | yes | - | Module |
|
||||
| midi (.mid, .kar, RMID) | yes | yes (SMF) | Midi |
|
||||
| sf2 | yes | - | SoundFont |
|
||||
| ahx (AHX / THX), hvl (HivelyTracker) | yes | - | Module (own synth engine) |
|
||||
| mus (Doom), xmi (Miles XMIDI), hmp (HMP, HMI) | yes | - (save as midi) | Midi |
|
||||
|
||||
See [FORMATS.md](../FORMATS.md) for each format's capabilities.
|
||||
|
||||
### AHX / HVL and MIDI variants
|
||||
|
||||
AHX and HivelyTracker modules carry no samples: their instruments are small synth programs (waveforms, filter and
|
||||
pulse-width sweeps, a performance list). They load as a Module-shaped value (`format` `"ahx"` / `"hvl"`; `patterns` are
|
||||
the tracks, 6 bytes per row: note, instrument, effect, parameter, second effect, parameter; `positions` hold each
|
||||
channel's track and transpose; `subsongs`) and render through their own replayer, a port of HivelyTracker's, which gives
|
||||
hvl2wav's samples exactly. Render options: `sampleRate`, `subsong` (0 = the main song), `loop`, `maxDuration` (default
|
||||
600 s) and, for AHX, `stereo` 0..4 (0 mono as hvl2wav renders by default, 4 the Amiga's hard L R R L panning); HVL files
|
||||
store their own panning and gain.
|
||||
|
||||
```luau
|
||||
local song = assert(F.music.load(ahxBytes))
|
||||
assert(song.format == "ahx" and song.channels == 4 and song.title == "demo")
|
||||
local dec = song:render({ stereo = 4 }) -- a Decoder, stereo f32 at 44100 Hz
|
||||
assert(dec.channels == 2 and dec.duration > 1)
|
||||
local hvl = assert(F.music.load(hvlBytes))
|
||||
assert(hvl.format == "hvl" and hvl.channels == 6 and #hvl.subsongs == 1)
|
||||
local intro = hvl:render({ subsong = 1, sampleRate = 22050 })
|
||||
local wav = assert(F.save(intro, nil, { format = "wav" }))
|
||||
assert(F.detect(wav) == "wav" and F.detect(hvlBytes) == "hvl")
|
||||
```
|
||||
|
||||
Doom MUS, Miles XMIDI and HMI's HMP / HMI files load as a **Midi**, so they play through the SoundFont synth and save
|
||||
as a Standard MIDI File. MUS runs at 140 ticks per second (`rate` option), XMIDI at a fixed 120 (note durations become
|
||||
note-offs; `track` picks the song of a multi-song file, `meta.source.songs` counts them), HMP / HMI at the rate in
|
||||
their header.
|
||||
|
||||
```luau
|
||||
local doom = assert(F.music.load(musBytes))
|
||||
assert(doom.kind == "midi" and doom.meta.source.format == "mus")
|
||||
local audio = assert(F.ops.audio.toAudio(doom:render({ soundfont = sf2Bytes, tail = 0.2 })))
|
||||
assert(audio.channels == 2)
|
||||
local xmi = assert(F.music.load(xmiBytes, { track = 2 })) -- the second song
|
||||
assert(xmi.meta.source.songs == 2 and xmi.meta.source.song == 2)
|
||||
local smf = assert(F.save(xmi, nil, { format = "midi" })) -- as a .mid
|
||||
assert(F.detect(smf) == "midi")
|
||||
local hmp = assert(F.music.load(hmpBytes))
|
||||
assert(hmp.meta.source.format == "hmp" and #hmp.tracks == 3)
|
||||
```
|
||||
|
||||
Karaoke `.kar` files are MIDI files with the lyrics in text events: `meta.lyrics` lists them with their time
|
||||
(`{ time, tick, text }`; a leading `\` starts a new paragraph, `/` a new line), the `@` headers land in
|
||||
`meta.karaoke` (`T` = title lines, `L` language, `I` info, ...) and `meta.tags`.
|
||||
|
||||
```luau
|
||||
local kar = assert(F.music.load(karBytes))
|
||||
assert(kar.meta.tags.title == "Little Song" and kar.meta.tags.artist == "The Docs")
|
||||
local line = {}
|
||||
for _, l in kar.meta.lyrics do
|
||||
table.insert(line, l.text)
|
||||
end
|
||||
assert(table.concat(line) == "\\Hello /karaoke" and kar.meta.lyrics[2].time == 0.5)
|
||||
```
|
||||
|
||||
## Gotchas
|
||||
|
||||
- Saving music to an audio format renders it with the options in `opts`: `F.save(song, nil, { format = "wav",
|
||||
|
||||
Reference in new issue
Block a user