merge ws/perf-audio (Ogg page CRC via core Crc32.msb from ws/perf-core)
This commit is contained in:
commit
6ddc5b6017
113 files changed
+4582
-2280
No files matched your search
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/aac: raw AAC in ADTS framing (ISO/IEC 13818-7 / 14496-3 1.A.3). Supports: AAC-LC via codecs/audio/Aac (1-8
|
||||
-- channels, every rate), CRC-protected headers, a leading ID3v2 tag, resync, seeking by frame; HE-AAC plays its
|
||||
-- AAC-LC core. Not supported: writing, ADIF, LATM.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/ac3: raw AC-3 (Dolby Digital, ATSC A/52) via codecs/audio/Ac3. Supports: every channel layout (WAVE order, no
|
||||
-- downmix), 32 / 44.1 / 48 kHz, every bit rate, the CRC check, resync, exact seeking; drc 0 .. 1, off by default.
|
||||
-- Not supported: writing, E-AC-3 (UNSUPPORTED), bsid 9 / 10 reduced-rate streams.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/adpcm: headerless ADPCM (.adpcm / .ima / .vox) via codecs/audio/Adpcm; sniff is 0, the layout comes from opts.
|
||||
-- "ima": DVI nibbles, high first; "ima_wav": MS IMA blocks; "ms": MS ADPCM, 7 standard coefficient pairs; "ima_qt":
|
||||
-- Apple ima4 (34-byte packets, 64 frames); "psx": PS-ADPCM (16-byte frames, 28 samples). Encode: ima, ima_wav, ms.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/adx: CRI ADX via codecs/audio/Adpcm; header and decoder follow vgmstream r2117 (ISC,
|
||||
-- licenses/vgmstream-LICENSE.txt), bit-exact with it. Supports: encoding type 3, versions 3-5, 1-8 channels, loop
|
||||
-- points; encode as version 4. Not supported: encrypted ADX (0x0408 / 0x0409), encoding types 2 and 4, AHX.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/aiff: AIFF / AIFF-C (Apple AIFF 1.3, AIFF-C draft 1991). Supports: PCM 1-32 bits; AIFF-C NONE / twos /
|
||||
-- sowt / raw / in24 / in32 / fl32 / fl64 / ulaw / alaw / ima4; text chunks as tags; truncated SSND; encode 8-32 bit,
|
||||
-- sowt, fl32, fl64, ulaw, alaw. Not supported: other compressed AIFF-C codecs, MARK / INST, the ID3 chunk.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/ape: Monkey's Audio (.ape) via codecs/audio/Ape and ApeTag, from the Monkey's Audio SDK 13.28 (BSD 3-clause,
|
||||
-- licenses/monkeys-audio-LICENSE.txt). Supports: versions 3.95+, every level, 8-32-bit integer and 32-bit float, 1-32
|
||||
-- channels, an ID3v2 prefix, seeking by the seek table. Not supported: files before 3.95, encoding.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/au: Sun / NeXT audio (.au / .snd), big endian. Supports: encodings 1 (mu-law), 2-5 (8-32-bit linear), 6 / 7
|
||||
-- (float), 27 (A-law), data size 0xFFFFFFFF (to the end), the annotation as tags.comment; encode to any of them.
|
||||
-- Not supported: G.721 / G.722 / G.723 ADPCM and the other NeXT encodings.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/brstm: Nintendo BRSTM (Wii, "RSTM", BE), BCSTM (3DS, "CSTM", LE), BFSTM (Wii U BE / Switch LE, "FSTM"); layouts
|
||||
-- follow vgmstream r2117 (ISC, licenses/vgmstream-LICENSE.txt), bit-exact. Supports: DSP ADPCM, PCM16 / PCM8, 1-255
|
||||
-- channels, loop points. Read only. Not supported: BCSTM IMA ADPCM, BRSTM 0.1, BFSTM regions, the track table.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/caf: Apple Core Audio Format (CAF 1.0 spec). Supports: linear PCM (8-32-bit integer, 32 / 64-bit float, either
|
||||
-- endian), ALAC, AAC-LC (kuki esds), mu-law, A-law, IMA4; pakt trimming, data size -1, info tags, seeking; encode PCM
|
||||
-- (16 / 24-bit BE, 32-bit float) and ALAC (16 / 20 / 24-bit). Not supported: other compressed formats.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/flac: FLAC (RFC 9639), native and Ogg FLAC; absorbed from flac-luau 7083d0d (same author). Supports: every
|
||||
-- subframe type, Rice / Rice2, 4-32 bits, 1-8 channels, CRC-16 resync, seeking, an ID3v2 prefix, the main metadata
|
||||
-- blocks; encode levels 0-8 (libFLAC presets), 4-24 bits. Not supported: MD5 check on decode, chained Ogg, Ogg output.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/m4a: MPEG-4 audio (M4A / M4B / MP4 / MOV audio tracks) via containers/IsoBmff. Supports: AAC-LC (HE-AAC plays
|
||||
-- its core), ALAC, edit-list gapless trimming, seeking, iTunes tags and cover art; encode ALAC (16 / 20 / 24-bit, 1-8
|
||||
-- channels). Not supported: writing AAC, other codecs in MP4 (UNSUPPORTED), encrypted files.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/mp3: MPEG audio layers I-III (ISO/IEC 11172-3, 13818-3, MPEG-2.5); absorbed from mp3-luau c755bbf, a port of
|
||||
-- minimp3 by lieff (CC0: licenses/minimp3-CC0.txt). Supports: every mode, CBR / VBR / free format, Xing / LAME gapless,
|
||||
-- exact seeking, ID3v2 / ID3v1 tags; encode layers III / II (CBR). Not supported: MPEG-2 multichannel, CRC, VBR output.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/mpc: Musepack (.mpc / .mp+ / .mpp) SV7 and SV8 via codecs/audio/Musepack (a libmpcdec port). Supports: mono /
|
||||
-- stereo, 32-48 kHz, gapless length, seeking (SV8 exact; SV7 with 32 frames of pre-roll, as libmpcdec), APEv2 tags,
|
||||
-- an ID3v2 prefix, ReplayGain in meta. Not supported: writing, SV4-SV6 (UNSUPPORTED), chapters.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/opus/Encode: Ogg Opus writing (RFC 7845), CELT only (TOC config 31: full band, 20 ms, code 0), family 0.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/opus: Ogg Opus (RFC 6716, RFC 7845); absorbed from opus-luau dd2b4e5, a port of the libopus 1.6 decoder (BSD:
|
||||
-- licenses/libopus-BSD.txt). Supports: every mode / bandwidth / frame size, mapping families 0 / 1 / 255, seeking, PLC;
|
||||
-- encode CELT only (20 ms, full band, CBR). Not supported: SILK / hybrid encoding, mapping family 3, chained streams.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/qoa: QOA "Quite OK Audio" via codecs/audio/Qoa (a port of qoa.h, phoboslab, MIT). Supports: static and
|
||||
-- streaming files, 1-255 channels, rates up to 16777215 Hz, frame-accurate seeking; encode byte-for-byte as qoa_encode,
|
||||
-- 1-8 channels. Not supported: channel count or rate changes mid-stream.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/tta: True Audio (.tta, TTA1) via codecs/audio/Tta, from the TTA1 format description. Supports: 8 / 16 / 24
|
||||
-- bits, any channel count, seeking by the seek table, APEv2 tags, an ID3v2 prefix. Not supported: password-protected
|
||||
-- files, TTA2, ID3v2 contents, encoding.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/vag: Sony VAG (PS-ADPCM: VAGp mono, VAGi stereo) and KVAG (IMA); layouts follow vgmstream r2117 (ISC,
|
||||
-- licenses/vgmstream-LICENSE.txt), bit-exact, Sony's leading blank frame included. Supports: loop points; encode VAGp /
|
||||
-- VAGi. Not supported: HEVAG (0x00020001 / 0x00030000), game-specific variants (pGAV, VAG1 / VAG2, Jak, ...).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/voc: Creative Voice File (.voc), from Creative's format description. Supports: block types 1, 2, 3, 5, 8, 9
|
||||
-- (8 / 16-bit, A-law, mu-law); markers and repeats played once, as ffmpeg; truncated files; encode version 1.20 type 9
|
||||
-- blocks. Not supported: Creative ADPCM, channel count changes mid-file (the first block's rate is used).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/vorbis: Ogg Vorbis (Vorbis I spec; RFC 5215); the decoder is a port of stb_vorbis 1.22 (public domain / MIT,
|
||||
-- licenses/stb_vorbis-LICENSE.txt) with libvorbis' sample-exact trimming and seeking. Supports: 1-255 channels,
|
||||
-- floor 1, residues 0-2, packetDecoder for Matroska / MP4; an encoder. Not supported: floor 0, chained streams.
|
||||
|
||||
@@ -7,54 +7,60 @@ local readu8, readi8, readu16, readi16, readu32, readi32 =
|
||||
local readf32, readf64, writef32, writeu32 = buffer.readf32, buffer.readf64, buffer.writef32, buffer.writeu32
|
||||
local band, rshift, byteswap = bit32.band, bit32.rshift, bit32.byteswap
|
||||
local writeu8, writeu16, writei16, writei32 = buffer.writeu8, buffer.writeu16, buffer.writei16, buffer.writei32
|
||||
local floor = math.floor
|
||||
|
||||
local Codecs = {}
|
||||
|
||||
-- integer PCM: 1 byte = unsigned, 2 / 3 / 4 bytes = signed
|
||||
function Codecs.int(src: buffer, off: number, dst: buffer, d: number, count: number, bytes: number, be: boolean)
|
||||
local o = d * 4
|
||||
local e = off + (count - 1) * bytes -- the last sample's offset
|
||||
if bytes == 1 then
|
||||
for i = 0, count - 1 do
|
||||
writef32(dst, o + i * 4, (readu8(src, off + i) - 128) / 128)
|
||||
for s = off, e do
|
||||
writef32(dst, o, (readu8(src, s) - 128) / 128)
|
||||
o += 4
|
||||
end
|
||||
elseif bytes == 2 then
|
||||
if be then
|
||||
for i = 0, count - 1 do
|
||||
local s = off + i * 2
|
||||
for s = off, e, 2 do
|
||||
local v = readi8(src, s) * 256 + readu8(src, s + 1)
|
||||
writef32(dst, o + i * 4, v / 32768)
|
||||
writef32(dst, o, v / 32768)
|
||||
o += 4
|
||||
end
|
||||
else
|
||||
for i = 0, count - 1 do
|
||||
writef32(dst, o + i * 4, readi16(src, off + i * 2) / 32768)
|
||||
for s = off, e, 2 do
|
||||
writef32(dst, o, readi16(src, s) / 32768)
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
elseif bytes == 3 then
|
||||
if be then
|
||||
for i = 0, count - 1 do
|
||||
local s = off + i * 3
|
||||
for s = off, e, 3 do
|
||||
local v = readi8(src, s) * 65536 + readu8(src, s + 1) * 256 + readu8(src, s + 2)
|
||||
writef32(dst, o + i * 4, v / 8388608)
|
||||
writef32(dst, o, v / 8388608)
|
||||
o += 4
|
||||
end
|
||||
else
|
||||
for i = 0, count - 1 do
|
||||
local s = off + i * 3
|
||||
for s = off, e, 3 do
|
||||
local v = readi8(src, s + 2) * 65536 + readu16(src, s)
|
||||
writef32(dst, o + i * 4, v / 8388608)
|
||||
writef32(dst, o, v / 8388608)
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
else
|
||||
if be then
|
||||
for i = 0, count - 1 do
|
||||
local v = byteswap(readu32(src, off + i * 4))
|
||||
for s = off, e, 4 do
|
||||
local v = byteswap(readu32(src, s))
|
||||
if v >= 0x80000000 then
|
||||
v -= 0x100000000
|
||||
end
|
||||
writef32(dst, o + i * 4, v / 2147483648)
|
||||
writef32(dst, o, v / 2147483648)
|
||||
o += 4
|
||||
end
|
||||
else
|
||||
for i = 0, count - 1 do
|
||||
writef32(dst, o + i * 4, readi32(src, off + i * 4) / 2147483648)
|
||||
for s = off, e, 4 do
|
||||
writef32(dst, o, readi32(src, s) / 2147483648)
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -63,28 +69,29 @@ end
|
||||
function Codecs.float(src: buffer, off: number, dst: buffer, d: number, count: number, bytes: number, be: boolean,
|
||||
tmp: buffer)
|
||||
local o = d * 4
|
||||
local e = off + (count - 1) * bytes
|
||||
if bytes == 4 then
|
||||
if be then
|
||||
for i = 0, count - 1 do
|
||||
writeu32(tmp, 0, byteswap(readu32(src, off + i * 4)))
|
||||
writef32(dst, o + i * 4, readf32(tmp, 0))
|
||||
for s = off, e, 4 do
|
||||
writeu32(tmp, 0, byteswap(readu32(src, s)))
|
||||
writef32(dst, o, readf32(tmp, 0))
|
||||
o += 4
|
||||
end
|
||||
else
|
||||
for i = 0, count - 1 do
|
||||
writef32(dst, o + i * 4, readf32(src, off + i * 4))
|
||||
end
|
||||
buffer.copy(dst, o, src, off, count * 4)
|
||||
end
|
||||
else
|
||||
if be then
|
||||
for i = 0, count - 1 do
|
||||
local s = off + i * 8
|
||||
for s = off, e, 8 do
|
||||
writeu32(tmp, 0, byteswap(readu32(src, s + 4)))
|
||||
writeu32(tmp, 4, byteswap(readu32(src, s)))
|
||||
writef32(dst, o + i * 4, readf64(tmp, 0))
|
||||
writef32(dst, o, readf64(tmp, 0))
|
||||
o += 4
|
||||
end
|
||||
else
|
||||
for i = 0, count - 1 do
|
||||
writef32(dst, o + i * 4, readf64(src, off + i * 8))
|
||||
for s = off, e, 8 do
|
||||
writef32(dst, o, readf64(src, s))
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -92,8 +99,9 @@ end
|
||||
|
||||
function Codecs.law(src: buffer, off: number, dst: buffer, d: number, count: number, tbl: buffer)
|
||||
local o = d * 4
|
||||
for i = 0, count - 1 do
|
||||
writef32(dst, o + i * 4, readf32(tbl, readu8(src, off + i) * 4))
|
||||
for s = off, off + count - 1 do
|
||||
writef32(dst, o, readf32(tbl, readu8(src, s) * 4))
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,11 +111,13 @@ end
|
||||
|
||||
function Codecs.quantize(src: buffer, s: number, dst: buffer, off: number, count: number, kind: string)
|
||||
local so = s * 4
|
||||
local se = so + count * 4 - 4
|
||||
local o = off
|
||||
if kind == "f32" then
|
||||
buffer.copy(dst, off, src, so, count * 4)
|
||||
elseif kind == "s16" then
|
||||
for i = 0, count - 1 do
|
||||
local v = math.floor(readf32(src, so + i * 4) * 32768 + 0.5)
|
||||
for i = so, se, 4 do
|
||||
local v = floor(readf32(src, i) * 32768 + 0.5)
|
||||
if v > 32767 then
|
||||
v = 32767
|
||||
elseif v < -32768 then
|
||||
@@ -115,11 +125,12 @@ function Codecs.quantize(src: buffer, s: number, dst: buffer, off: number, count
|
||||
elseif v ~= v then
|
||||
v = 0
|
||||
end
|
||||
writei16(dst, off + i * 2, v)
|
||||
writei16(dst, o, v)
|
||||
o += 2
|
||||
end
|
||||
elseif kind == "s24" then
|
||||
for i = 0, count - 1 do
|
||||
local v = math.floor(readf32(src, so + i * 4) * 8388608 + 0.5)
|
||||
for i = so, se, 4 do
|
||||
local v = floor(readf32(src, i) * 8388608 + 0.5)
|
||||
if v > 8388607 then
|
||||
v = 8388607
|
||||
elseif v < -8388608 then
|
||||
@@ -130,13 +141,13 @@ function Codecs.quantize(src: buffer, s: number, dst: buffer, off: number, count
|
||||
if v < 0 then
|
||||
v += 16777216
|
||||
end
|
||||
local o = off + i * 3
|
||||
writeu16(dst, o, v % 65536)
|
||||
writeu8(dst, o + 2, v // 65536)
|
||||
o += 3
|
||||
end
|
||||
elseif kind == "s32" then
|
||||
for i = 0, count - 1 do
|
||||
local v = math.floor(readf32(src, so + i * 4) * 2147483648 + 0.5)
|
||||
for i = so, se, 4 do
|
||||
local v = floor(readf32(src, i) * 2147483648 + 0.5)
|
||||
if v > 2147483647 then
|
||||
v = 2147483647
|
||||
elseif v < -2147483648 then
|
||||
@@ -144,11 +155,12 @@ function Codecs.quantize(src: buffer, s: number, dst: buffer, off: number, count
|
||||
elseif v ~= v then
|
||||
v = 0
|
||||
end
|
||||
writei32(dst, off + i * 4, v)
|
||||
writei32(dst, o, v)
|
||||
o += 4
|
||||
end
|
||||
else -- u8
|
||||
for i = 0, count - 1 do
|
||||
local v = math.floor(readf32(src, so + i * 4) * 128 + 0.5)
|
||||
for i = so, se, 4 do
|
||||
local v = floor(readf32(src, i) * 128 + 0.5)
|
||||
if v > 127 then
|
||||
v = 127
|
||||
elseif v < -128 then
|
||||
@@ -156,7 +168,8 @@ function Codecs.quantize(src: buffer, s: number, dst: buffer, off: number, count
|
||||
elseif v ~= v then
|
||||
v = 0
|
||||
end
|
||||
writeu8(dst, off + i, v + 128)
|
||||
writeu8(dst, o, v + 128)
|
||||
o += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- audio/wavpack: WavPack (.wv) via codecs/audio/WavPack, from the WavPack 5 file format document and WavPack 5.9.0's
|
||||
-- open_utils.c (BSD 3-clause, licenses/wavpack-LICENSE.txt). Supports: lossless and hybrid (lossy without the .wvc, as
|
||||
-- wvunpack), 8-32-bit integer and float, 1-4096 channels, seeking, APEv2. Not supported: DSD, WavPack 1-3, encoding.
|
||||
|
||||
@@ -94,6 +94,20 @@ local DIM = { 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2 }
|
||||
local UNSIGNED = { false, false, true, true, false, false, true, true, true, true, true }
|
||||
local MOD = { 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17 }
|
||||
local OFF = { 1, 1, 0, 0, 4, 4, 0, 0, 0, 0, 0 }
|
||||
-- UNPACK[cb][4 sym + k]: a codeword's dim values (k = 1 .. dim), first value most significant
|
||||
local UNPACK: { { number } } = {}
|
||||
for cb = 1, 11 do
|
||||
local dim, mod, off = DIM[cb], MOD[cb], OFF[cb]
|
||||
local t = table.create(mod ^ dim * 4, 0)
|
||||
for sym = 0, mod ^ dim - 1 do
|
||||
local v = sym
|
||||
for k = dim, 1, -1 do
|
||||
t[sym * 4 + k] = v % mod - off
|
||||
v = v // mod
|
||||
end
|
||||
end
|
||||
UNPACK[cb] = t
|
||||
end
|
||||
|
||||
-- |q|^(4/3)
|
||||
local POW43 = table.create(8192, 0)
|
||||
@@ -421,7 +435,7 @@ local function spectralData(st: State, c: Channel, pulses: { number }?): string?
|
||||
continue
|
||||
end
|
||||
local bk = SPEC_BOOK[cb]
|
||||
local dim, uns, mod, off = DIM[cb], UNSIGNED[cb], MOD[cb], OFF[cb]
|
||||
local dim, uns, unpack = DIM[cb], UNSIGNED[cb], UNPACK[cb]
|
||||
local gain = 2 ^ (0.25 * (sf[idx] - 100))
|
||||
for w = 0, glen - 1 do
|
||||
local base = (win + w) * 128 + lo
|
||||
@@ -432,19 +446,8 @@ local function spectralData(st: State, c: Channel, pulses: { number }?): string?
|
||||
return "bad spectral code"
|
||||
end
|
||||
-- unpack the symbol into dim values (first value most significant)
|
||||
local vals1: number, vals2: number, vals3: number, vals4: number
|
||||
if dim == 4 then
|
||||
vals4 = sym % mod - off
|
||||
sym = (sym - (sym % mod)) / mod
|
||||
vals3 = sym % mod - off
|
||||
sym = (sym - (sym % mod)) / mod
|
||||
vals2 = sym % mod - off
|
||||
sym = (sym - (sym % mod)) / mod
|
||||
vals1 = sym % mod - off
|
||||
else
|
||||
vals2 = sym % mod - off
|
||||
vals1 = (sym - (sym % mod)) / mod - off
|
||||
end
|
||||
local u = sym * 4
|
||||
local vals1, vals2, vals3, vals4 = unpack[u + 1], unpack[u + 2], unpack[u + 3], unpack[u + 4]
|
||||
if uns then
|
||||
if vals1 ~= 0 and getBits(1) == 1 then
|
||||
vals1 = -vals1
|
||||
@@ -670,6 +673,19 @@ local function filterbank(st: State, c: Channel, out: { number }, stride: number
|
||||
else
|
||||
local t = st.time
|
||||
Mdct.inverse(PLAN_LONG, spec, 1, 1, t, 1, 2 / 2048)
|
||||
if seq ~= LONG_STOP and seq ~= LONG_START then
|
||||
-- ONLY_LONG: window, overlap-add and output in one pass
|
||||
local rise = if prev == 1 then KBD_LONG else SINE_LONG
|
||||
local fall = if shape == 1 then KBD_LONG else SINE_LONG
|
||||
local p = offset
|
||||
for n = 1, 1024 do
|
||||
out[p] = (t[n] * rise[n] + overlap[n]) * scale
|
||||
overlap[n] = t[1024 + n] * fall[1024 + n]
|
||||
p += stride
|
||||
end
|
||||
c.prevShape = shape
|
||||
return
|
||||
end
|
||||
if seq == LONG_STOP then
|
||||
local rise = if prev == 1 then KBD_SHORT else SINE_SHORT
|
||||
for n = 1, 448 do
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/Tables: the AAC-LC tables of ISO/IEC 14496-3 (subpart 4, Annex 4.A): Huffman codebooks, scalefactor
|
||||
-- band offsets, TNS band limits. Transcribed from FFmpeg libavcodec/aactab.c (tables of the standard, no code; see
|
||||
-- licenses/NOTICE.md). Generated; do not edit.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac: AAC-LC decoder (ISO/IEC 14496-3 subpart 4, ISO/IEC 13818-7): AudioSpecificConfig, ADTS, raw_data_block.
|
||||
-- Written from the standard; no third-party code. HE-AAC decodes its AAC-LC core at the core rate. Not supported: Main
|
||||
-- prediction, LTP, SSR, coupling channels, 960-sample frames, ER / USAC (UNSUPPORTED).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Ac3/Tables: transcribed from ATSC A/52:2018 section 7.2.3 (bit allocation tables) and section 5.4 (frame
|
||||
-- sizes); masktab is derived from bndtab / bndsz. No third-party code.
|
||||
local T = {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Ac3: AC-3 (Dolby Digital, ATSC A/52) syncframes: syncinfo / BSI, CRC check and decoder.
|
||||
-- Written from ATSC A/52:2018; no third-party code. E-AC-3 (bsid 11 .. 16) and bsid 9 / 10 are UNSUPPORTED.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Adpcm/Decoder: the streaming Types.Decoder over packetised ADPCM (ADX, VAG, BRSTM, raw IMA) with exact seeking.
|
||||
-- New in rosetta.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
|
||||
@@ -78,7 +78,7 @@ local function rice(b: buffer, pos: number, limit: number, out: { number }, n: n
|
||||
if pos > limit then
|
||||
return -1 -- each value reads at most 41 bits past here: inside the 16 padding bytes
|
||||
end
|
||||
local k = 31 - countlz(floor(history / 512) + 3)
|
||||
local k = 31 - countlz(history // 512 + 3)
|
||||
if k > kb then
|
||||
k = kb
|
||||
end
|
||||
@@ -90,14 +90,14 @@ local function rice(b: buffer, pos: number, limit: number, out: { number }, n: n
|
||||
if x > 0xFFFF then
|
||||
history = 0xFFFF
|
||||
else
|
||||
history += x * mult - floor(history * mult / 512)
|
||||
history += x * mult - (history * mult) // 512
|
||||
end
|
||||
if history < 128 and i < n then
|
||||
if pos > limit then
|
||||
return -1
|
||||
end
|
||||
local lg = if history > 0 then 31 - countlz(history) else 0
|
||||
k = 7 - lg + floor((history + 16) / 64)
|
||||
k = 7 - lg + (history + 16) // 64
|
||||
if k > kb then
|
||||
k = kb
|
||||
end
|
||||
@@ -155,7 +155,7 @@ local function predict(err: { number }, out: { number }, n: number, bps: number,
|
||||
for j = 1, order do
|
||||
val += (out[i - j] - d) * coefs[j]
|
||||
end
|
||||
val = floor((val + half) / qd)
|
||||
val = (val + half) // qd -- qd is 2^quant: exact
|
||||
local e = err[i]
|
||||
out[i] = signExtend(val + d + e, bps)
|
||||
if e ~= 0 then
|
||||
@@ -168,7 +168,7 @@ local function predict(err: { number }, out: { number }, n: number, bps: number,
|
||||
local v = d - out[i - j]
|
||||
local sgn = if v > 0 then es elseif v < 0 then -es else 0
|
||||
coefs[j] -= sgn
|
||||
e -= floor(v * sgn / qd) * (order - j + 1)
|
||||
e -= ((v * sgn) // qd) * (order - j + 1)
|
||||
end
|
||||
end
|
||||
i += 1
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Alac: Apple Lossless (ALAC) decoder and encoder.
|
||||
-- Written from the ALAC format as Apple published it; no third-party code. ALAC stores C L R ... for 3+ channels; the
|
||||
-- API uses WAV order.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Ape: the Monkey's Audio codec (.ape), file versions 3.95 and later.
|
||||
-- Ported from the Monkey's Audio SDK 13.28 (Matthew T. Ashland, BSD 3-clause since v10, licenses/monkeys-audio-LICENSE.txt):
|
||||
-- APEHeader.cpp, APEInfo / APEDecompress.cpp. Not supported: pre-3.95 (UNSUPPORTED), the pre-8.50 "interim" 24-bit re-decode.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/ApeTag: APEv1 / APEv2 tags -> Types.Tags.
|
||||
-- From the APEv2 specification (wiki.hydrogenaud.io); no third-party code. Items + a 32-byte "APETAGEX" footer, optional
|
||||
-- 32-byte header (APEv2), before an optional ID3v1 tag.
|
||||
|
||||
@@ -28,10 +28,33 @@ for i = 0, 255 do
|
||||
CRC16[i + 1] = d
|
||||
end
|
||||
|
||||
-- slice-by-4: C1 = CRC16; Ck[i] = the CRC16 state after i (high byte) and k - 1 zero bytes
|
||||
local C1, C2, C3, C4 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0)
|
||||
for i = 0, 255 do
|
||||
C1[i + 1] = CRC16[i + 1]
|
||||
end
|
||||
for i = 0, 255 do
|
||||
local c = C1[i + 1]
|
||||
c = bxor(band(lshift(c, 8), 0xFFFF), C1[rshift(c, 8) + 1])
|
||||
C2[i + 1] = c
|
||||
c = bxor(band(lshift(c, 8), 0xFFFF), C1[rshift(c, 8) + 1])
|
||||
C3[i + 1] = c
|
||||
c = bxor(band(lshift(c, 8), 0xFFFF), C1[rshift(c, 8) + 1])
|
||||
C4[i + 1] = c
|
||||
end
|
||||
|
||||
local function crc16(b: buffer, from: number, to: number): number
|
||||
local c = 0
|
||||
for i = from, to - 1 do
|
||||
c = bxor(band(lshift(c, 8), 0xFFFF), CRC16[bxor(rshift(c, 8), readu8(b, i)) + 1])
|
||||
local i = from
|
||||
-- four bytes w (big-endian) at a time: the state is linear, so the new state is the xor of each byte of
|
||||
-- (c << 16) ~ w pushed through 4, 3, 2 and 1 table steps
|
||||
while i + 4 <= to do
|
||||
local x = bxor(lshift(c, 16), byteswap(readu32(b, i)))
|
||||
c = bxor(bxor(C4[rshift(x, 24) + 1], C3[band(rshift(x, 16), 255) + 1]), bxor(C2[band(rshift(x, 8), 255) + 1], C1[band(x, 255) + 1]))
|
||||
i += 4
|
||||
end
|
||||
for j = i, to - 1 do
|
||||
c = bxor(band(lshift(c, 8), 0xFFFF), CRC16[bxor(rshift(c, 8), readu8(b, j)) + 1])
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Flac: FLAC frames without the container (frame header, subframes, CRC-8 / CRC-16) and the frame encoder.
|
||||
-- Absorbed from flac-luau 7083d0d; the encoder is new.
|
||||
local Flac = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Hively/Load: AHX ("THX\0".."THX\2") and HivelyTracker ("HVL\0", "HVL\1") module files -> Tune.
|
||||
-- Ported from hvl2wav replay.c 1.9 (hvl_load_ahx / hvl_reset; BSD-3-Clause, (c) 2006-2018 Pete Gordon;
|
||||
-- licenses/hivelytracker-LICENSE.txt), with bounds checks the C code does not have.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Hively/Player: the AHX / HivelyTracker replayer and integer mixer, as hvl2wav's replay.c 1.9 computes them.
|
||||
-- Ported from HivelyTracker (BSD-3-Clause, (c) 2006-2018 Pete Gordon; licenses/hivelytracker-LICENSE.txt). Where the C
|
||||
-- code reads outside its arrays on bad data this port clamps instead.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Hively/Tables: the AHX / HivelyTracker replayer's waveform, panning, vibrato and period tables.
|
||||
-- Ported from hvl2wav replay.c 1.9 (BSD-3-Clause, (c) 2006-2018 Pete Gordon; licenses/hivelytracker-LICENSE.txt) as
|
||||
-- built on 64-bit Linux (`long` is 64-bit: the noise generator's shifts do not wrap at 32 bits).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Hively: the AHX / HivelyTracker engine (loader, replayer, waveform tables, render glue).
|
||||
-- A port of hvl2wav replay.c 1.9 (BSD-3-Clause, (c) 2006-2018 Pete Gordon; licenses/hivelytracker-LICENSE.txt); at
|
||||
-- hvl2wav's settings the output equals its 16-bit samples / 32768. hvl2wav pads a 44.1 kHz speed-multiplier-4 frame to
|
||||
|
||||
@@ -82,77 +82,122 @@ end
|
||||
-- one pass of radix p: cc (i, v, k) = src[1 + i + ido * (v + p * k)] -> ch (i, k, u) = dst[1 + i + ido * (k + l1 * u)]
|
||||
local function pass(p: number, ido: number, l1: number, ar: { number }, ai: { number }, br: { number }, bi: { number }, tr: { number }, ti: { number }, cr: { number }, ci: { number })
|
||||
local lp = ido * l1
|
||||
if p == 4 then
|
||||
if ido == 1 and p == 4 then -- the last pass: no twiddles, s = 4k + 1, d = k + 1
|
||||
local lp2, lp3 = 2 * lp, 3 * lp
|
||||
local s = 1
|
||||
for d = 1, l1 do
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + 1], ai[s + 1]
|
||||
local a2r, a2i = ar[s + 2], ai[s + 2]
|
||||
local a3r, a3i = ar[s + 3], ai[s + 3]
|
||||
local t0r, t0i = a0r + a2r, a0i + a2i
|
||||
local t1r, t1i = a0r - a2r, a0i - a2i
|
||||
local t2r, t2i = a1r + a3r, a1i + a3i
|
||||
local t3r, t3i = a1r - a3r, a1i - a3i
|
||||
br[d], bi[d] = t0r + t2r, t0i + t2i
|
||||
br[d + lp], bi[d + lp] = t1r + t3i, t1i - t3r
|
||||
br[d + lp2], bi[d + lp2] = t0r - t2r, t0i - t2i
|
||||
br[d + lp3], bi[d + lp3] = t1r - t3i, t1i + t3r
|
||||
s += 4
|
||||
end
|
||||
elseif ido == 1 and p == 2 then
|
||||
local s = 1
|
||||
for d = 1, l1 do
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + 1], ai[s + 1]
|
||||
br[d], bi[d] = a0r + a1r, a0i + a1i
|
||||
br[d + lp], bi[d + lp] = a0r - a1r, a0i - a1i
|
||||
s += 2
|
||||
end
|
||||
elseif p == 4 then
|
||||
local ido2, ido3, lp2, lp3 = 2 * ido, 3 * ido, 2 * lp, 3 * lp
|
||||
for k = 0, l1 - 1 do
|
||||
for i = 0, ido - 1 do
|
||||
local s = 1 + i + ido * 4 * k
|
||||
local s = 1 + ido * 4 * k
|
||||
local d = 1 + ido * k
|
||||
do -- i = 0: no twiddle
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + ido], ai[s + ido]
|
||||
local a2r, a2i = ar[s + 2 * ido], ai[s + 2 * ido]
|
||||
local a3r, a3i = ar[s + 3 * ido], ai[s + 3 * ido]
|
||||
local a2r, a2i = ar[s + ido2], ai[s + ido2]
|
||||
local a3r, a3i = ar[s + ido3], ai[s + ido3]
|
||||
local t0r, t0i = a0r + a2r, a0i + a2i
|
||||
local t1r, t1i = a0r - a2r, a0i - a2i
|
||||
local t2r, t2i = a1r + a3r, a1i + a3i
|
||||
local t3r, t3i = a1r - a3r, a1i - a3i
|
||||
br[d], bi[d] = t0r + t2r, t0i + t2i
|
||||
br[d + lp], bi[d + lp] = t1r + t3i, t1i - t3r
|
||||
br[d + lp2], bi[d + lp2] = t0r - t2r, t0i - t2i
|
||||
br[d + lp3], bi[d + lp3] = t1r - t3i, t1i + t3r
|
||||
end
|
||||
for i1 = 2, ido do -- i = i1 - 1
|
||||
s += 1
|
||||
d += 1
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + ido], ai[s + ido]
|
||||
local a2r, a2i = ar[s + ido2], ai[s + ido2]
|
||||
local a3r, a3i = ar[s + ido3], ai[s + ido3]
|
||||
local t0r, t0i = a0r + a2r, a0i + a2i
|
||||
local t1r, t1i = a0r - a2r, a0i - a2i
|
||||
local t2r, t2i = a1r + a3r, a1i + a3i
|
||||
local t3r, t3i = a1r - a3r, a1i - a3i
|
||||
local d = 1 + i + ido * k
|
||||
br[d], bi[d] = t0r + t2r, t0i + t2i
|
||||
local y1r, y1i = t1r + t3i, t1i - t3r
|
||||
local y2r, y2i = t0r - t2r, t0i - t2i
|
||||
local y3r, y3i = t1r - t3i, t1i + t3r
|
||||
if i == 0 then
|
||||
br[d + lp], bi[d + lp] = y1r, y1i
|
||||
br[d + 2 * lp], bi[d + 2 * lp] = y2r, y2i
|
||||
br[d + 3 * lp], bi[d + 3 * lp] = y3r, y3i
|
||||
else
|
||||
local w1r, w1i = tr[i + 1], ti[i + 1]
|
||||
local w2r, w2i = tr[ido + i + 1], ti[ido + i + 1]
|
||||
local w3r, w3i = tr[2 * ido + i + 1], ti[2 * ido + i + 1]
|
||||
br[d + lp], bi[d + lp] = y1r * w1r - y1i * w1i, y1r * w1i + y1i * w1r
|
||||
br[d + 2 * lp], bi[d + 2 * lp] = y2r * w2r - y2i * w2i, y2r * w2i + y2i * w2r
|
||||
br[d + 3 * lp], bi[d + 3 * lp] = y3r * w3r - y3i * w3i, y3r * w3i + y3i * w3r
|
||||
end
|
||||
local w1r, w1i = tr[i1], ti[i1]
|
||||
local w2r, w2i = tr[ido + i1], ti[ido + i1]
|
||||
local w3r, w3i = tr[ido2 + i1], ti[ido2 + i1]
|
||||
br[d + lp], bi[d + lp] = y1r * w1r - y1i * w1i, y1r * w1i + y1i * w1r
|
||||
br[d + lp2], bi[d + lp2] = y2r * w2r - y2i * w2i, y2r * w2i + y2i * w2r
|
||||
br[d + lp3], bi[d + lp3] = y3r * w3r - y3i * w3i, y3r * w3i + y3i * w3r
|
||||
end
|
||||
end
|
||||
elseif p == 2 then
|
||||
for k = 0, l1 - 1 do
|
||||
for i = 0, ido - 1 do
|
||||
local s = 1 + i + ido * 2 * k
|
||||
local s = 1 + ido * 2 * k
|
||||
local d = 1 + ido * k
|
||||
do
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + ido], ai[s + ido]
|
||||
br[d], bi[d] = a0r + a1r, a0i + a1i
|
||||
br[d + lp], bi[d + lp] = a0r - a1r, a0i - a1i
|
||||
end
|
||||
for i1 = 2, ido do
|
||||
s += 1
|
||||
d += 1
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + ido], ai[s + ido]
|
||||
local d = 1 + i + ido * k
|
||||
br[d], bi[d] = a0r + a1r, a0i + a1i
|
||||
local yr, yi = a0r - a1r, a0i - a1i
|
||||
if i == 0 then
|
||||
br[d + lp], bi[d + lp] = yr, yi
|
||||
else
|
||||
local wr, wi = tr[i + 1], ti[i + 1]
|
||||
br[d + lp], bi[d + lp] = yr * wr - yi * wi, yr * wi + yi * wr
|
||||
end
|
||||
local wr, wi = tr[i1], ti[i1]
|
||||
br[d + lp], bi[d + lp] = yr * wr - yi * wi, yr * wi + yi * wr
|
||||
end
|
||||
end
|
||||
elseif p == 3 then
|
||||
local c = 0.86602540378443864676 -- sin(pi / 3)
|
||||
local ido2, lp2 = 2 * ido, 2 * lp
|
||||
for k = 0, l1 - 1 do
|
||||
for i = 0, ido - 1 do
|
||||
local s = 1 + i + ido * 3 * k
|
||||
local s = ido * 3 * k
|
||||
local d = ido * k
|
||||
for i1 = 1, ido do
|
||||
s += 1
|
||||
d += 1
|
||||
local a0r, a0i = ar[s], ai[s]
|
||||
local a1r, a1i = ar[s + ido], ai[s + ido]
|
||||
local a2r, a2i = ar[s + 2 * ido], ai[s + 2 * ido]
|
||||
local a2r, a2i = ar[s + ido2], ai[s + ido2]
|
||||
local tr_, ti_ = a1r + a2r, a1i + a2i
|
||||
local sr, si = a1r - a2r, a1i - a2i
|
||||
local d = 1 + i + ido * k
|
||||
br[d], bi[d] = a0r + tr_, a0i + ti_
|
||||
local mr, mi = a0r - 0.5 * tr_, a0i - 0.5 * ti_
|
||||
local y1r, y1i = mr + c * si, mi - c * sr
|
||||
local y2r, y2i = mr - c * si, mi + c * sr
|
||||
if i == 0 then
|
||||
if i1 == 1 then
|
||||
br[d + lp], bi[d + lp] = y1r, y1i
|
||||
br[d + 2 * lp], bi[d + 2 * lp] = y2r, y2i
|
||||
br[d + lp2], bi[d + lp2] = y2r, y2i
|
||||
else
|
||||
local w1r, w1i = tr[i + 1], ti[i + 1]
|
||||
local w2r, w2i = tr[ido + i + 1], ti[ido + i + 1]
|
||||
local w1r, w1i = tr[i1], ti[i1]
|
||||
local w2r, w2i = tr[ido + i1], ti[ido + i1]
|
||||
br[d + lp], bi[d + lp] = y1r * w1r - y1i * w1i, y1r * w1i + y1i * w1r
|
||||
br[d + 2 * lp], bi[d + 2 * lp] = y2r * w2r - y2i * w2i, y2r * w2i + y2i * w2r
|
||||
br[d + lp2], bi[d + lp2] = y2r * w2r - y2i * w2i, y2r * w2i + y2i * w2r
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -108,16 +108,52 @@ function Mdct.forward(plan: Plan, x: { number }, xi: number, out: { number }, oi
|
||||
end
|
||||
|
||||
function Mdct.inverse(plan: Plan, inp: { number }, ii: number, is: number?, y: { number }, yi: number, scale: number?)
|
||||
local m = plan.m
|
||||
local q, m = plan.n // 4, plan.m
|
||||
local h = m // 2
|
||||
local c = plan.c
|
||||
Mdct.dct4(plan, inp, ii, is or 1, c, 1, 1, scale)
|
||||
-- unfold: y = (C2, -C2 reversed, -C1 reversed, -C1)
|
||||
for j = 0, h - 1 do
|
||||
y[yi + j] = c[h + j + 1]
|
||||
y[yi + h + j] = -c[m - j]
|
||||
y[yi + m + j] = -c[h - j]
|
||||
y[yi + 3 * h + j] = -c[j + 1]
|
||||
local re, im, twc, tws = plan.re, plan.im, plan.twc, plan.tws
|
||||
local us = is or 1
|
||||
local sc = scale or 1
|
||||
local ia, ib, step = ii, ii + (m - 1) * us, 2 * us -- inp[ii + 2p us], inp[ii + (m - 1 - 2p) us]
|
||||
for p = 1, q do
|
||||
local a, b = inp[ia], inp[ib]
|
||||
local c, s = twc[p], tws[p]
|
||||
re[p] = a * c + b * s
|
||||
im[p] = b * c - a * s
|
||||
ia += step
|
||||
ib -= step
|
||||
end
|
||||
Fft.forward(plan.fft, re, im)
|
||||
-- the DCT-IV output C[j] (j = 2k and M - 1 - 2k) unfolded into y = (C2, -C2 reversed, -C1 reversed, -C1):
|
||||
-- y[3h - 1 - j] = -C[j]; y[3h + j] = -C[j] (j < h), y[j - h] = C[j] (j >= h)
|
||||
local b3 = yi + 3 * h
|
||||
-- 2k < h exactly when M - 1 - 2k >= h (h = q)
|
||||
local half = (q + 1) // 2
|
||||
local yh = yi - h
|
||||
for k = 0, half - 1 do
|
||||
local k1 = k + 1
|
||||
local c, s = twc[k1], tws[k1]
|
||||
local tr, ti = re[k1], im[k1]
|
||||
local e = (tr * c + ti * s) * sc -- C[2k]
|
||||
local o = -(ti * c - tr * s) * sc -- C[M - 1 - 2k]
|
||||
local j = 2 * k
|
||||
y[b3 - 1 - j] = -e
|
||||
y[b3 + j] = -e
|
||||
j = m - 1 - j
|
||||
y[j + yh] = o
|
||||
y[b3 - 1 - j] = -o
|
||||
end
|
||||
for k = half, q - 1 do
|
||||
local k1 = k + 1
|
||||
local c, s = twc[k1], tws[k1]
|
||||
local tr, ti = re[k1], im[k1]
|
||||
local e = (tr * c + ti * s) * sc
|
||||
local o = -(ti * c - tr * s) * sc
|
||||
local j = 2 * k
|
||||
y[j + yh] = e
|
||||
y[b3 - 1 - j] = -e
|
||||
j = m - 1 - j
|
||||
y[b3 - 1 - j] = -o
|
||||
y[b3 + j] = -o
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/MidiRender: the MIDI tempo map, event timeline and the Decoder that plays a Midi through SoundFont.
|
||||
-- Lengths as python mido computes them. Format 0 / 1: one tempo map from every track, tracks merged (ties keep track
|
||||
-- order); format 2: each track is its own song, played one after another.
|
||||
|
||||
@@ -156,6 +156,7 @@ end
|
||||
-- layer III side info (L3_read_side_info): fills GR_*, returns main_data_begin or -1
|
||||
|
||||
local function readSideInfo(h1: number, h2: number, h3: number): number
|
||||
local GR_NLONG, GR_NSHORT, GR_RC, GR_SBG, GR_SFB, GR_TS = GR_NLONG, GR_NSHORT, GR_RC, GR_SBG, GR_SFB, GR_TS
|
||||
local mono = band(h3, 0xC0) == 0xC0
|
||||
local mpeg1 = band(h1, 8) ~= 0
|
||||
local srIdx = band(rshift(h2, 2), 3) + (band(rshift(h1, 3), 1) + band(rshift(h1, 4), 1)) * 3
|
||||
@@ -254,6 +255,7 @@ end
|
||||
|
||||
-- L3_read_scalefactors + L3_decode_scalefactors -> SCF[0 .. nLong + nShort)
|
||||
local function decodeScalefactors(h1: number, h3: number, istOff: number, gr: number, ch: number)
|
||||
local GR_SBG, ISCF, IST, SCFSIZE = GR_SBG, ISCF, IST, SCFSIZE
|
||||
local mpeg1 = band(h1, 8) ~= 0
|
||||
local nLong, nShort = GR_NLONG[gr], GR_NSHORT[gr]
|
||||
local part = ((if nShort ~= 0 then 1 else 0) + (if nLong == 0 then 1 else 0)) * 28
|
||||
@@ -335,6 +337,7 @@ end
|
||||
-- layer III Huffman decoding (L3_huffman) into GRBUF[dst ..], reads MAIN through a 32-bit cache
|
||||
|
||||
local function huffman(dst: number, gr: number, limit: number)
|
||||
local GRBUF, SCF, SFB = GRBUF, SCF, SFB
|
||||
local b = bsBuf
|
||||
local one = 0.0
|
||||
local ireg = 0
|
||||
@@ -482,6 +485,7 @@ end
|
||||
|
||||
-- L3_midside_stereo on GRBUF[left .. left + n) and its right channel at + 576
|
||||
local function midside(left: number, n: number)
|
||||
local GRBUF = GRBUF
|
||||
for i = left * 4, (left + n - 1) * 4, 4 do
|
||||
local a, c = rf(GRBUF, i), rf(GRBUF, i + 2304)
|
||||
wf(GRBUF, i, a + c)
|
||||
@@ -490,6 +494,7 @@ local function midside(left: number, n: number)
|
||||
end
|
||||
|
||||
local function intensityStereo(h1: number, h3: number, gr: number)
|
||||
local GRBUF, IST, MAXB = GRBUF, IST, MAXB
|
||||
local mpeg1 = band(h1, 8) ~= 0
|
||||
local ms = band(h3, 0x20) ~= 0
|
||||
local nLong, nShort = GR_NLONG[gr], GR_NSHORT[gr]
|
||||
@@ -559,6 +564,7 @@ local function intensityStereo(h1: number, h3: number, gr: number)
|
||||
end
|
||||
|
||||
local function reorder(g: number, sfb: number)
|
||||
local GRBUF, SYN = GRBUF, SYN
|
||||
local src, dst = g, 0
|
||||
while true do
|
||||
local len = ru8(SFB, sfb)
|
||||
@@ -586,14 +592,50 @@ for i = 0, 7 do
|
||||
end
|
||||
|
||||
local function antialias(g: number, nbands: number)
|
||||
local GRBUF = GRBUF
|
||||
local a0, a1, a2, a3, a4, a5, a6, a7 = AA0[1], AA0[2], AA0[3], AA0[4], AA0[5], AA0[6], AA0[7], AA0[8]
|
||||
local b0, b1, b2, b3, b4, b5, b6, b7 = AA1[1], AA1[2], AA1[3], AA1[4], AA1[5], AA1[6], AA1[7], AA1[8]
|
||||
local o = g * 4
|
||||
for _ = 1, nbands do
|
||||
for i = 0, 7 do
|
||||
local ui, di = o + (18 + i) * 4, o + (17 - i) * 4
|
||||
local u, d = rf(GRBUF, ui), rf(GRBUF, di)
|
||||
local c0, c1 = AA0[i + 1], AA1[i + 1]
|
||||
wf(GRBUF, ui, u * c0 - d * c1)
|
||||
wf(GRBUF, di, u * c1 + d * c0)
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 72), rf(GRBUF, o + 68)
|
||||
wf(GRBUF, o + 72, u * a0 - d * b0)
|
||||
wf(GRBUF, o + 68, u * b0 + d * a0)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 76), rf(GRBUF, o + 64)
|
||||
wf(GRBUF, o + 76, u * a1 - d * b1)
|
||||
wf(GRBUF, o + 64, u * b1 + d * a1)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 80), rf(GRBUF, o + 60)
|
||||
wf(GRBUF, o + 80, u * a2 - d * b2)
|
||||
wf(GRBUF, o + 60, u * b2 + d * a2)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 84), rf(GRBUF, o + 56)
|
||||
wf(GRBUF, o + 84, u * a3 - d * b3)
|
||||
wf(GRBUF, o + 56, u * b3 + d * a3)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 88), rf(GRBUF, o + 52)
|
||||
wf(GRBUF, o + 88, u * a4 - d * b4)
|
||||
wf(GRBUF, o + 52, u * b4 + d * a4)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 92), rf(GRBUF, o + 48)
|
||||
wf(GRBUF, o + 92, u * a5 - d * b5)
|
||||
wf(GRBUF, o + 48, u * b5 + d * a5)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 96), rf(GRBUF, o + 44)
|
||||
wf(GRBUF, o + 96, u * a6 - d * b6)
|
||||
wf(GRBUF, o + 44, u * b6 + d * a6)
|
||||
end
|
||||
do
|
||||
local u, d = rf(GRBUF, o + 100), rf(GRBUF, o + 40)
|
||||
wf(GRBUF, o + 100, u * a7 - d * b7)
|
||||
wf(GRBUF, o + 40, u * b7 + d * a7)
|
||||
end
|
||||
o += 72
|
||||
end
|
||||
@@ -627,6 +669,7 @@ end
|
||||
|
||||
-- L3_imdct36: GRBUF[g ..], OVL[ov ..] (float indices), window W (1-based, 18 values)
|
||||
local function imdct36(g: number, ov: number, W: { number }, nbands: number)
|
||||
local GRBUF = GRBUF
|
||||
local w0 = W[1]
|
||||
local w1 = W[2]
|
||||
local w2 = W[3]
|
||||
@@ -739,6 +782,7 @@ end
|
||||
|
||||
-- mp3d_DCT_II (scalar path) over the n time slots of a channel at GRBUF[g ..]: t[4][8] in locals
|
||||
local function dctII(g: number, n: number)
|
||||
local GRBUF = GRBUF
|
||||
for k = 0, n - 1 do
|
||||
local y = (g + k) * 4
|
||||
local t0_0, t1_0, t2_0, t3_0
|
||||
@@ -989,6 +1033,7 @@ end
|
||||
|
||||
-- L3_imdct12: x = TMP f32 index (stride 3), dst buffer + float index, ov = OVL float index
|
||||
local function imdct12(x: number, dst: buffer, d: number, ov: number)
|
||||
local TMP = TMP
|
||||
local xb = x * 4
|
||||
local x0, x3, x6, x9, x12, x15 =
|
||||
rf(TMP, xb), rf(TMP, xb + 12), rf(TMP, xb + 24), rf(TMP, xb + 36), rf(TMP, xb + 48), rf(TMP, xb + 60)
|
||||
@@ -1017,6 +1062,7 @@ local function imdct12(x: number, dst: buffer, d: number, ov: number)
|
||||
end
|
||||
|
||||
local function imdctShort(g: number, ov: number, nbands: number)
|
||||
local GRBUF = GRBUF
|
||||
for _ = 1, nbands do
|
||||
bcopy(TMP, 0, GRBUF, g * 4, 72)
|
||||
bcopy(GRBUF, g * 4, OVL, ov * 4, 24)
|
||||
@@ -1085,6 +1131,7 @@ end
|
||||
|
||||
-- mp3d_synth_pair: z = SYN float index, dst = PCM float index
|
||||
local function synthPair(dst: number, nch: number, z: number)
|
||||
local SYN = SYN
|
||||
local zb = z * 4
|
||||
local a = (rf(SYN, zb + 14 * 256) - rf(SYN, zb)) * 29
|
||||
a += (rf(SYN, zb + 1 * 256) + rf(SYN, zb + 13 * 256)) * 213
|
||||
@@ -1109,6 +1156,7 @@ end
|
||||
|
||||
-- mp3d_synth: two time slots of 32 subbands -> 64 samples per channel
|
||||
local function synth(xl: number, dstl: number, nch: number, lins: number)
|
||||
local GRBUF, SYN, WINT = GRBUF, SYN, WINT
|
||||
local xr = xl + 576 * (nch - 1)
|
||||
local dstr = dstl + (nch - 1)
|
||||
local zlin = lins + 15 * 64
|
||||
@@ -1216,6 +1264,7 @@ local function synth(xl: number, dstl: number, nch: number, lins: number)
|
||||
end
|
||||
|
||||
local function synthGranule(nbands: number, nch: number, pcm: number)
|
||||
local SYN = SYN
|
||||
for ch = 0, nch - 1 do
|
||||
dctII(576 * ch, nbands)
|
||||
end
|
||||
@@ -1241,6 +1290,7 @@ local ALLOC_L2M1_LOW = { 44, 4, 2, 44, 3, 10 }
|
||||
local totalBands, stereoBands = 0, 0
|
||||
|
||||
local function l12ReadScaleInfo(h1: number, h2: number, h3: number, kbpsHdr: number)
|
||||
local BA = BA
|
||||
local mode = rshift(h3, 6)
|
||||
local sb = if mode == 3 then 0 elseif mode == 1 then band(rshift(h3, 4), 3) * 4 + 4 else 32
|
||||
local layer1 = band(h1, 6) == 6
|
||||
@@ -1331,6 +1381,7 @@ local function l12Dequantize(g: number, groupSize: number): number
|
||||
end
|
||||
|
||||
local function l12ApplyScf(scfOff: number)
|
||||
local GRBUF = GRBUF
|
||||
local sb, tb = stereoBands, totalBands
|
||||
bcopy(GRBUF, (576 + sb * 18) * 4, GRBUF, sb * 18 * 4, (tb - sb) * 18 * 4)
|
||||
for i = 0, tb - 1 do
|
||||
@@ -1389,6 +1440,7 @@ function Core.upmix(pcm: buffer, n: number)
|
||||
end
|
||||
|
||||
function Core.decodeFrame(st: State, b: buffer, off: number, size: number, pcm: buffer): number
|
||||
local FRAME, GRBUF, MAIN = FRAME, GRBUF, MAIN
|
||||
if size < 4 or size > MAX_FRAME or off < 0 or off + size > buffer.len(b) then
|
||||
st.needReset = true
|
||||
return 0
|
||||
@@ -1476,6 +1528,7 @@ function Core.decodeFrame(st: State, b: buffer, off: number, size: number, pcm:
|
||||
end
|
||||
|
||||
function Core.probeL3(b: buffer, off: number, size: number): (number, number, number)
|
||||
local FRAME = FRAME
|
||||
local n = min(size, 64)
|
||||
if size < 4 or off + n > buffer.len(b) then
|
||||
return -1, 0, 0
|
||||
@@ -1500,6 +1553,7 @@ end
|
||||
|
||||
-- Layer I / II: minimp3 drops a frame that needs more bits than it has
|
||||
function Core.probeL12(b: buffer, off: number, size: number): boolean
|
||||
local FRAME = FRAME
|
||||
if size < 4 or size > MAX_FRAME or off + size > buffer.len(b) then
|
||||
return false
|
||||
end
|
||||
@@ -1533,6 +1587,7 @@ end
|
||||
-- mp3dec_check_vbrtag on the frame b[off, off + size): 0 = no tag, -1 = a Xing / Info tag without a frame
|
||||
-- count, 1 = tag; then frames, encoder delay + 529, padding - 529 (both 0 without a LAME extension)
|
||||
function Core.vbrTag(b: buffer, off: number, size: number): (number, number, number, number)
|
||||
local FRAME = FRAME
|
||||
if size < 12 or size > MAX_FRAME or off + size > buffer.len(b) then
|
||||
return 0, 0, 0, 0
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Mpa/EncTables: the synthesis window D and the layer III Huffman trees of ISO/IEC 11172-3, from PDMP3
|
||||
-- (public domain / unlicense, Krister Lagerstrom and contributors: licenses/PDMP3-UNLICENSE.txt). Tree entries with a
|
||||
-- high byte are nodes (high byte: left offset, low byte: right offset), else leaves (x << 4 | y; count1: v w x y bits).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Mpa/Tables: constant tables of minimp3 (https://github.com/lieff/minimp3, CC0), generated by tools/gen_tables.py.
|
||||
-- Every list is flattened row-major and 0-based (t[0] is the first element), like the C arrays.
|
||||
local T = {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Mpa: MPEG audio layers I / II / III (ISO/IEC 11172-3, 13818-3, MPEG-2.5) without the file around it.
|
||||
-- Core is a port of minimp3 by lieff (CC0, licenses/minimp3-CC0.txt), absorbed from mp3-luau c755bbf; the layer II / III
|
||||
-- encoders are new.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Musepack/Tables: the Musepack SV7 / SV8 Huffman tables, synthesis window and requantisation constants.
|
||||
-- Ported from libmpcdec (musepack_src_r475: huffman.c, synth_filter.c, requant.c, mpc_bits_reader.c; BSD-3-Clause,
|
||||
-- (c) The Musepack Development Team, licenses/libmpcdec-BSD.txt). Huffman tables: flat { code, length, value, ... }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Musepack: Musepack (MPC) stream versions 7 and 8.
|
||||
-- A port of libmpcdec (musepack_src_r475: mpc_demux.c, streaminfo.c, mpc_decoder.c; BSD-3-Clause, (c) The Musepack
|
||||
-- Development Team, licenses/libmpcdec-BSD.txt), gapless like libmpcdec. SV4 - SV6 are UNSUPPORTED.
|
||||
|
||||
@@ -193,6 +193,7 @@ local function laplaceDecode(dec: RD.Dec, fs: number, decay: number): number
|
||||
end
|
||||
|
||||
local function unquantCoarseEnergy(st: any, start: number, endb: number, intra: boolean, dec: RD.Dec, C: number, LM: number)
|
||||
local E_PROB = E_PROB
|
||||
local oldE = st.oldBandE
|
||||
local probBase = LM * 84 + (if intra then 42 else 0) -- e_prob_model[LM][intra], 0-based
|
||||
local coef, beta
|
||||
@@ -276,6 +277,7 @@ end
|
||||
-- bit allocation (rate.c)
|
||||
|
||||
local function bits2pulses(bandI: number, LM: number, bits: number): number
|
||||
local CACHE_BITS = CACHE_BITS
|
||||
local base = CACHE_INDEX[(LM + 1) * NB_EBANDS + bandI + 1]
|
||||
local lo, hi = 0, CACHE_BITS[base + 1]
|
||||
bits -= 1
|
||||
@@ -312,6 +314,7 @@ end
|
||||
-- clt_compute_allocation + interp_bits2pulses (decoder side)
|
||||
local function computeAllocation(start: number, endb: number, offsets: { number }, cap: { number }, allocTrim: number,
|
||||
total: number, pulses: { number }, ebits: { number }, finePriority: { number }, C: number, LM: number, ec: RD.Dec)
|
||||
local ALLOC, EB, LOG2_FRAC_TABLE = ALLOC, EB, LOG2_FRAC_TABLE
|
||||
total = imax(total, 0)
|
||||
local len = NB_EBANDS
|
||||
local skipStart = start
|
||||
@@ -541,6 +544,7 @@ end
|
||||
-- PVQ (cwrs.c, vq.c)
|
||||
|
||||
local function cwrsi(n: number, k: number, i: number, iy: { number }): number
|
||||
local U = U
|
||||
local yy = 0
|
||||
local idx = 1
|
||||
local p, k0, val
|
||||
@@ -618,6 +622,7 @@ local function cwrsi(n: number, k: number, i: number, iy: { number }): number
|
||||
end
|
||||
|
||||
local function expRotation1(X: number, len: number, stride: number, c: number, s: number)
|
||||
local W = W
|
||||
local ms = -s
|
||||
local p = X + 1
|
||||
for _ = 0, len - stride - 1 do
|
||||
@@ -672,6 +677,7 @@ local function expRotation(X: number, len: number, dir: number, stride: number,
|
||||
end
|
||||
|
||||
local function renormaliseVector(X: number, N: number, gain: number)
|
||||
local W = W
|
||||
local E = 1e-15
|
||||
for i = X + 1, X + N do
|
||||
local v = W[i]
|
||||
@@ -684,6 +690,7 @@ local function renormaliseVector(X: number, N: number, gain: number)
|
||||
end
|
||||
|
||||
local function algUnquant(X: number, N: number, K: number, spread: number, B: number, dec: RD.Dec, gain: number): number
|
||||
local U = U
|
||||
local iy = IY
|
||||
local ft = U[N * UK + K + 1] + U[N * UK + K + 2]
|
||||
local Ryy = cwrsi(N, K, decUint(dec, ft), iy)
|
||||
@@ -734,6 +741,7 @@ local ctx: Ctx = {
|
||||
}
|
||||
|
||||
local function haar1(X: number, N0: number, stride: number)
|
||||
local W = W
|
||||
N0 = rshift(N0, 1)
|
||||
local s = 0.70710678
|
||||
for i = 0, stride - 1 do
|
||||
@@ -749,6 +757,7 @@ local function haar1(X: number, N0: number, stride: number)
|
||||
end
|
||||
|
||||
local function deinterleaveHadamard(X: number, N0: number, stride: number, hadamard: boolean)
|
||||
local W = W
|
||||
local N = N0 * stride
|
||||
local tmp = TMP
|
||||
if hadamard then
|
||||
@@ -772,6 +781,7 @@ local function deinterleaveHadamard(X: number, N0: number, stride: number, hadam
|
||||
end
|
||||
|
||||
local function interleaveHadamard(X: number, N0: number, stride: number, hadamard: boolean)
|
||||
local W = W
|
||||
local N = N0 * stride
|
||||
local tmp = TMP
|
||||
if hadamard then
|
||||
@@ -810,6 +820,7 @@ local function computeQn(N: number, b: number, offset: number, pulseCap: number,
|
||||
end
|
||||
|
||||
local function computeTheta(N: number, b: number, B: number, B0: number, LM: number, stereo: boolean, fill: number)
|
||||
local ctx = ctx
|
||||
local i = ctx.i
|
||||
local ec = ctx.ec
|
||||
local pulseCap = LOGN[i + 1] + LM * 8
|
||||
@@ -889,6 +900,7 @@ local function computeTheta(N: number, b: number, B: number, B0: number, LM: num
|
||||
end
|
||||
|
||||
local function quantBandN1(X: number, Y: number, lowbandOut: number): number
|
||||
local W, ctx = W, ctx
|
||||
local x = X
|
||||
local ec = ctx.ec
|
||||
for _ = 0, (if Y >= 0 then 1 else 0) do
|
||||
@@ -907,6 +919,7 @@ local function quantBandN1(X: number, Y: number, lowbandOut: number): number
|
||||
end
|
||||
|
||||
local function quantPartition(X: number, N: number, b: number, B: number, lowband: number, LM: number, gain: number, fill: number): number
|
||||
local CACHE_BITS, W, ctx = CACHE_BITS, W, ctx
|
||||
local i = ctx.i
|
||||
local B0 = B
|
||||
local cm = 0
|
||||
@@ -999,6 +1012,7 @@ end
|
||||
|
||||
local function quantBand(X: number, N: number, b: number, B: number, lowband: number, LM: number, lowbandOut: number,
|
||||
gain: number, lowbandScratch: number, fill: number): number
|
||||
local BIT_INTERLEAVE, W = BIT_INTERLEAVE, W
|
||||
local N0 = N
|
||||
local NB = N
|
||||
local B0 = B
|
||||
@@ -1069,6 +1083,7 @@ local function quantBand(X: number, N: number, b: number, B: number, lowband: nu
|
||||
end
|
||||
|
||||
local function stereoMerge(X: number, Y: number, mid: number, N: number)
|
||||
local W = W
|
||||
local xp, side = 0, 0
|
||||
for j = 1, N do
|
||||
local y = W[Y + j]
|
||||
@@ -1097,6 +1112,7 @@ end
|
||||
|
||||
local function quantBandStereo(X: number, Y: number, N: number, b: number, B: number, lowband: number, LM: number,
|
||||
lowbandOut: number, lowbandScratch: number, fill: number): number
|
||||
local W, ctx = W, ctx
|
||||
if N == 1 then
|
||||
return quantBandN1(X, Y, lowbandOut)
|
||||
end
|
||||
@@ -1169,6 +1185,7 @@ local function quantAllBands(start: number, endb: number, hasY: boolean, N: numb
|
||||
pulses: { number }, shortBlocks: boolean, spread: number, dualStereo: boolean, intensity: number,
|
||||
tfRes: { number }, totalBits: number, balance: number, ec: RD.Dec, LM: number, codedBands: number,
|
||||
seed: number, disableInv: boolean): number
|
||||
local EB, W, ctx = EB, W, ctx
|
||||
local M = lshift(1, LM)
|
||||
local B = if shortBlocks then M else 1
|
||||
local normOffset = M * EB[start + 1]
|
||||
@@ -1278,6 +1295,7 @@ end
|
||||
|
||||
local function antiCollapse(st: any, C: number, size: number, LM: number, start: number, endb: number,
|
||||
collapse: { number }, pulses: { number }, seed: number)
|
||||
local EB = EB
|
||||
local logE, prev1logE, prev2logE = st.oldBandE, st.oldLogE, st.oldLogE2
|
||||
for i = start, endb - 1 do
|
||||
local N0 = EB[i + 2] - EB[i + 1]
|
||||
@@ -1318,6 +1336,7 @@ local function antiCollapse(st: any, C: number, size: number, LM: number, start:
|
||||
end
|
||||
|
||||
local function denormaliseBands(X: number, freq: { number }, logE: { number }, eoff: number, start: number, endb: number, M: number, silence: boolean)
|
||||
local EB = EB
|
||||
local N = M * SHORT_MDCT
|
||||
local bound = M * EB[endb + 1]
|
||||
if silence then
|
||||
@@ -1349,6 +1368,7 @@ local function denormaliseBands(X: number, freq: { number }, logE: { number }, e
|
||||
end
|
||||
|
||||
local function celtSynthesis(st: any, C: number, CC: number, start: number, effEnd: number, isTransient: boolean, LM: number, silence: boolean, N: number)
|
||||
local FREQ2, WINDOW = FREQ2, WINDOW
|
||||
local M = lshift(1, LM)
|
||||
local B, NB, shift
|
||||
if isTransient then
|
||||
@@ -1396,6 +1416,7 @@ end
|
||||
-- comb_filter, in place on mem (1-based base index of sample 0)
|
||||
local function combFilter(mem: { number }, base: number, T0: number, T1: number, N: number, g0: number, g1: number,
|
||||
tapset0: number, tapset1: number, overlap: number)
|
||||
local COMB_GAINS = COMB_GAINS
|
||||
if g0 == 0 and g1 == 0 then
|
||||
return
|
||||
end
|
||||
@@ -1412,14 +1433,16 @@ local function combFilter(mem: { number }, base: number, T0: number, T1: number,
|
||||
overlap = 0
|
||||
end
|
||||
local i = 0
|
||||
local d1 = 2 - T1
|
||||
while i < overlap do
|
||||
local p = base + i
|
||||
local x0 = mem[p - T1 + 2]
|
||||
local x0 = mem[p + d1]
|
||||
local w = WINDOW[i + 1]
|
||||
local f = w * w
|
||||
local of = 1 - f
|
||||
mem[p] = mem[p] + (of * g00) * mem[p - T0] + (of * g01) * (mem[p - T0 + 1] + mem[p - T0 - 1])
|
||||
+ (of * g02) * (mem[p - T0 + 2] + mem[p - T0 - 2]) + (f * g10) * x2 + (f * g11) * (x1 + x3)
|
||||
local t = p - T0
|
||||
mem[p] = mem[p] + (of * g00) * mem[t] + (of * g01) * (mem[t + 1] + mem[t - 1])
|
||||
+ (of * g02) * (mem[t + 2] + mem[t - 2]) + (f * g10) * x2 + (f * g11) * (x1 + x3)
|
||||
+ (f * g12) * (x0 + x4)
|
||||
x4 = x3
|
||||
x3 = x2
|
||||
@@ -1437,7 +1460,7 @@ local function combFilter(mem: { number }, base: number, T0: number, T1: number,
|
||||
x2 = mem[p - T1]
|
||||
x1 = mem[p - T1 + 1]
|
||||
for q = p, base + N - 1 do
|
||||
local x0 = mem[q - T1 + 2]
|
||||
local x0 = mem[q + d1]
|
||||
mem[q] = mem[q] + g10 * x2 + g11 * (x1 + x3) + g12 * (x0 + x4)
|
||||
x4 = x3
|
||||
x3 = x2
|
||||
@@ -1527,6 +1550,7 @@ Celt.reset = resetState
|
||||
|
||||
-- noise-based concealment (celt_decode_lost, FRAME_PLC_NOISE)
|
||||
local function decodeLost(st: any, N: number, LM: number)
|
||||
local EB = EB
|
||||
local C = st.channels
|
||||
local start = st.start
|
||||
local endb = st["end"]
|
||||
@@ -1582,6 +1606,7 @@ end
|
||||
-- celt_decode_with_ec (buf nil or len <= 1 conceals)
|
||||
function Celt.decode(st: any, buf: buffer?, off: number, len: number, pcm: { number }, pbase: number, frameSize: number,
|
||||
dec: RD.Dec?, accum: boolean): number
|
||||
local EB = EB
|
||||
local CC = st.channels
|
||||
local C = st.stream_channels
|
||||
local start = st.start
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Opus/CeltTables: from libopus celt/static_modes_float.h and celt/quant_bands.c (BSD, licenses/).
|
||||
return {
|
||||
logN400 = {
|
||||
|
||||
@@ -403,7 +403,11 @@ function Decoder.decodeMultistream(ms: MS, buf: buffer?, off: number, len: numbe
|
||||
return if ret < 0 then ret else -3
|
||||
end
|
||||
frameSize = ret
|
||||
if s < ms.coupled then
|
||||
local nch = ms.channels
|
||||
if ms.streams == 1 and nch <= 2 and ms.coupled == nch - 1 and ms.mapping[1] == 0 and (nch == 1 or ms.mapping[2] == 1) then
|
||||
-- one stream in its own channel order: the copy is a block move
|
||||
table.move(tmp, 1, frameSize * nch, pbase, pcm)
|
||||
elseif s < ms.coupled then
|
||||
copyOut(ms, s * 2, tmp, 0, 2, pcm, pbase, frameSize)
|
||||
copyOut(ms, s * 2 + 1, tmp, 1, 2, pcm, pbase, frameSize)
|
||||
else
|
||||
|
||||
@@ -50,6 +50,9 @@ for shift = 0, 3 do
|
||||
local factors = FACTORS[shift]
|
||||
local bitrev = table.create(n, 0)
|
||||
bitrevTable(bitrev, 0, 0, 1, factors, 1)
|
||||
for i = 1, n do
|
||||
bitrev[i] += 1 -- 1-based targets
|
||||
end
|
||||
local twr, twi = table.create(n, 0), table.create(n, 0)
|
||||
for k = 0, n - 1 do
|
||||
local ph = -2 * pi * k / n
|
||||
@@ -132,6 +135,7 @@ local function bfly4(fr: { number }, fi: { number }, fstride: number, twr: { num
|
||||
end
|
||||
else
|
||||
local m2, m3 = 2 * m, 3 * m
|
||||
local fs2, fs3 = fstride * 2, fstride * 3
|
||||
for i = 0, N - 1 do
|
||||
local p = i * mm + 1
|
||||
local t1, t2, t3 = 1, 1, 1
|
||||
@@ -154,8 +158,8 @@ local function bfly4(fr: { number }, fi: { number }, fstride: number, twr: { num
|
||||
fr[p + m2] = f0r - s3r
|
||||
fi[p + m2] = f0i - s3i
|
||||
t1 += fstride
|
||||
t2 += fstride * 2
|
||||
t3 += fstride * 3
|
||||
t2 += fs2
|
||||
t3 += fs3
|
||||
fr[p] = f0r + s3r
|
||||
fi[p] = f0i + s3i
|
||||
fr[p + m] = s5r + s4i
|
||||
@@ -170,6 +174,7 @@ end
|
||||
|
||||
local function bfly3(fr: { number }, fi: { number }, fstride: number, twr: { number }, twi: { number }, m: number, N: number, mm: number)
|
||||
local m2 = 2 * m
|
||||
local fs2 = fstride * 2
|
||||
local epi3i = twi[fstride * m + 1]
|
||||
for i = 0, N - 1 do
|
||||
local p = i * mm + 1
|
||||
@@ -184,7 +189,7 @@ local function bfly3(fr: { number }, fi: { number }, fstride: number, twr: { num
|
||||
local s3r, s3i = s1r + s2r, s1i + s2i
|
||||
local s0r, s0i = s1r - s2r, s1i - s2i
|
||||
t1 += fstride
|
||||
t2 += fstride * 2
|
||||
t2 += fs2
|
||||
local f0r, f0i = fr[p], fi[p]
|
||||
local fmr, fmi = f0r - s3r * 0.5, f0i - s3i * 0.5
|
||||
s0r *= epi3i
|
||||
@@ -203,23 +208,28 @@ end
|
||||
local function bfly5(fr: { number }, fi: { number }, fstride: number, twr: { number }, twi: { number }, m: number, N: number, mm: number)
|
||||
local yar, yai = twr[fstride * m + 1], twi[fstride * m + 1]
|
||||
local ybr, ybi = twr[fstride * 2 * m + 1], twi[fstride * 2 * m + 1]
|
||||
local fs1, fs2, fs3, fs4 = fstride, 2 * fstride, 3 * fstride, 4 * fstride
|
||||
for i = 0, N - 1 do
|
||||
local p0 = i * mm + 1
|
||||
local p1, p2, p3, p4 = p0 + m, p0 + 2 * m, p0 + 3 * m, p0 + 4 * m
|
||||
for u = 0, m - 1 do
|
||||
local k1, k2, k3, k4 = 1, 1, 1, 1 -- u * fstride * (1 .. 4) + 1
|
||||
for _ = 0, m - 1 do
|
||||
local s0r, s0i = fr[p0], fi[p0]
|
||||
local k = u * fstride
|
||||
local ar, ai = fr[p1], fi[p1]
|
||||
local wr, wi = twr[k + 1], twi[k + 1]
|
||||
local wr, wi = twr[k1], twi[k1]
|
||||
local s1r, s1i = ar * wr - ai * wi, ar * wi + ai * wr
|
||||
ar, ai = fr[p2], fi[p2]
|
||||
wr, wi = twr[2 * k + 1], twi[2 * k + 1]
|
||||
wr, wi = twr[k2], twi[k2]
|
||||
local s2r, s2i = ar * wr - ai * wi, ar * wi + ai * wr
|
||||
ar, ai = fr[p3], fi[p3]
|
||||
wr, wi = twr[3 * k + 1], twi[3 * k + 1]
|
||||
wr, wi = twr[k3], twi[k3]
|
||||
local s3r, s3i = ar * wr - ai * wi, ar * wi + ai * wr
|
||||
ar, ai = fr[p4], fi[p4]
|
||||
wr, wi = twr[4 * k + 1], twi[4 * k + 1]
|
||||
wr, wi = twr[k4], twi[k4]
|
||||
k1 += fs1
|
||||
k2 += fs2
|
||||
k3 += fs3
|
||||
k4 += fs4
|
||||
local s4r, s4i = ar * wr - ai * wi, ar * wi + ai * wr
|
||||
|
||||
local s7r, s7i = s1r + s4r, s1i + s4i
|
||||
@@ -298,24 +308,28 @@ function Mdct.backward(inp: { number }, inBase: number, out: { number }, outBase
|
||||
-- pre-rotate, storing in bit-reversed order (real and imaginary swapped: an FFT is used instead of an IFFT)
|
||||
local xp1 = inBase
|
||||
local xp2 = inBase + stride * (N2 - 1)
|
||||
for i = 0, N4 - 1 do
|
||||
local st2 = 2 * stride
|
||||
for i = 1, N4 do
|
||||
local x1 = inp[xp1]
|
||||
local x2 = inp[xp2]
|
||||
local t0, t1 = trig[2 * i + 1], trig[2 * i + 2]
|
||||
local rev = bitrev[i + 1] + 1
|
||||
local t0, t1 = trig[2 * i - 1], trig[2 * i]
|
||||
local rev = bitrev[i]
|
||||
fi[rev] = x2 * t1 + x1 * t0
|
||||
fr[rev] = x1 * t1 - x2 * t0
|
||||
xp1 += 2 * stride
|
||||
xp2 -= 2 * stride
|
||||
xp1 += st2
|
||||
xp2 -= st2
|
||||
end
|
||||
fftImpl(pl)
|
||||
local h = outBase + (overlap // 2)
|
||||
for k = 0, N4 - 1 do
|
||||
local re = fi[k + 1]
|
||||
local im = fr[k + 1]
|
||||
local t0, t1 = trig[2 * k + 1], trig[2 * k + 2]
|
||||
out[h + 2 * k] = re * t1 + im * t0
|
||||
out[h + N2 - 1 - 2 * k] = re * t0 - im * t1
|
||||
local hb = h + N2 - 1
|
||||
for k = 1, N4 do
|
||||
local re = fi[k]
|
||||
local im = fr[k]
|
||||
local t0, t1 = trig[2 * k - 1], trig[2 * k]
|
||||
out[h] = re * t1 + im * t0
|
||||
out[hb] = re * t0 - im * t1
|
||||
h += 2
|
||||
hb -= 2
|
||||
end
|
||||
-- mirror on both sides for TDAC
|
||||
local xp = outBase + overlap - 1
|
||||
|
||||
@@ -714,21 +714,27 @@ local function up2HQ(S: { number }, out: { number }, oo: number, inp: { number }
|
||||
S[1], S[2], S[3], S[4], S[5], S[6] = s0, s1, s2, s3, s4, s5
|
||||
end
|
||||
|
||||
-- FIR12 per phase ti, in tap order: FIR12[4 ti + 1 .. 4 ti + 4], FIR12[4 (11 - ti) + 4 .. 4 (11 - ti) + 1]
|
||||
local FIR12_ROWS: { { number } } = table.create(12) :: any
|
||||
for ti = 0, 11 do
|
||||
local f0, f1 = ti * 4, (11 - ti) * 4
|
||||
FIR12_ROWS[ti + 1] = { FIR12[f0 + 1], FIR12[f0 + 2], FIR12[f0 + 3], FIR12[f0 + 4], FIR12[f1 + 4], FIR12[f1 + 3], FIR12[f1 + 2], FIR12[f1 + 1] }
|
||||
end
|
||||
|
||||
local function iirFirInterpol(out: { number }, oo: number, buf: { number }, max_index_Q16: number, incr: number): number
|
||||
local rows: { { number } } = FIR12_ROWS
|
||||
local index_Q16 = 0
|
||||
while index_Q16 < max_index_Q16 do
|
||||
local ti = ((index_Q16 % 65536) * 12) // 65536
|
||||
local r = rows[((index_Q16 % 65536) * 12) // 65536 + 1]
|
||||
local b = index_Q16 // 65536 + 1 -- buf is 1-based
|
||||
local f0 = ti * 4
|
||||
local f1 = (11 - ti) * 4
|
||||
local res_Q15 = buf[b] * FIR12[f0 + 1]
|
||||
+ buf[b + 1] * FIR12[f0 + 2]
|
||||
+ buf[b + 2] * FIR12[f0 + 3]
|
||||
+ buf[b + 3] * FIR12[f0 + 4]
|
||||
+ buf[b + 4] * FIR12[f1 + 4]
|
||||
+ buf[b + 5] * FIR12[f1 + 3]
|
||||
+ buf[b + 6] * FIR12[f1 + 2]
|
||||
+ buf[b + 7] * FIR12[f1 + 1]
|
||||
local res_Q15 = buf[b] * r[1]
|
||||
+ buf[b + 1] * r[2]
|
||||
+ buf[b + 2] * r[3]
|
||||
+ buf[b + 3] * r[4]
|
||||
+ buf[b + 4] * r[5]
|
||||
+ buf[b + 5] * r[6]
|
||||
+ buf[b + 6] * r[7]
|
||||
+ buf[b + 7] * r[8]
|
||||
out[oo] = sat16((res_Q15 + 16384) // 32768)
|
||||
oo += 1
|
||||
index_Q16 += incr
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Opus: the Opus codec (RFC 6716) without its container.
|
||||
-- A port of the libopus 1.6 decoder (BSD, licenses/libopus-BSD.txt), absorbed from opus-luau dd2b4e5; the CELT encoder is new.
|
||||
local Opus = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Pcm: PCM plumbing shared by audio formats: raw sample formats, streaming Decoders, encoder input sources.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
@@ -105,7 +105,7 @@ type State = {
|
||||
f: Filter,
|
||||
step: number, -- M = from / g: the input advance per output frame, in units of 1 / L
|
||||
L: number, -- to / g
|
||||
hist: { number },
|
||||
hist: { { number } }, -- per channel: input frame base + i - 1 at [i]
|
||||
histFrames: number,
|
||||
base: number,
|
||||
inFrames: number,
|
||||
@@ -115,6 +115,16 @@ type State = {
|
||||
flush: any,
|
||||
}
|
||||
|
||||
-- dot(x, xi, h, hi, n): sum of x[xi + k] * h[hi + k] for k = 0 .. n - 1, in that order
|
||||
local function dot(x: { number }, xi: number, h: { number }, hi: number, n: number): number
|
||||
local acc = 0
|
||||
local d = xi - hi
|
||||
for k = hi, hi + n - 1 do
|
||||
acc += x[k + d] * h[k]
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
local function run(st: State, limitOut: number, out: buffer?): (buffer, number)
|
||||
local f = st.f
|
||||
local taps, half, h = f.taps, f.half, f.h
|
||||
@@ -140,61 +150,78 @@ local function run(st: State, limitOut: number, out: buffer?): (buffer, number)
|
||||
local b = if out and buffer.len(out) >= bytes then out else buffer.create(bytes)
|
||||
local exact = f.exact
|
||||
local phases = f.phases
|
||||
local x0, x1 = hist[1], hist[2]
|
||||
local o = 0
|
||||
for j = j0, jmax - 1 do
|
||||
local num = j * M
|
||||
local ip = num // L -- floor(t)
|
||||
local first = ip - half + 1
|
||||
local rel = first - base
|
||||
local num = j0 * M
|
||||
local ip = num // L -- floor(t)
|
||||
local ph = num - ip * L -- num mod L
|
||||
for _ = j0, jmax - 1 do
|
||||
local rel = ip - half + 1 - base
|
||||
local kLo = if rel < 0 then -rel else 0
|
||||
local kHi = taps - 1
|
||||
if rel + kHi >= histFrames then
|
||||
kHi = histFrames - 1 - rel
|
||||
end
|
||||
local cnt = kHi - kLo + 1
|
||||
local xi = rel + kLo + 1
|
||||
if exact then
|
||||
local hb = (num - ip * L) * taps + 1 -- phase * taps + 1
|
||||
for c = 0, ch - 1 do
|
||||
local acc = 0
|
||||
local hi = (rel + kLo) * ch + c + 1
|
||||
for k = kLo, kHi do
|
||||
acc += hist[hi] * h[hb + k]
|
||||
hi += ch
|
||||
local hb = ph * taps + kLo + 1
|
||||
if ch == 2 then
|
||||
local a0, a1 = 0, 0
|
||||
local d = xi - hb
|
||||
for k = hb, hb + cnt - 1 do
|
||||
local hk = h[k]
|
||||
a0 += x0[k + d] * hk
|
||||
a1 += x1[k + d] * hk
|
||||
end
|
||||
writef32(b, o, acc)
|
||||
writef32(b, o, a0)
|
||||
writef32(b, o + 4, a1)
|
||||
o += 8
|
||||
elseif ch == 1 then
|
||||
writef32(b, o, dot(x0, xi, h, hb, cnt))
|
||||
o += 4
|
||||
else
|
||||
for c = 1, ch do
|
||||
writef32(b, o, dot(hist[c], xi, h, hb, cnt))
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
else
|
||||
local fp = (num - ip * L) / L * phases
|
||||
local fp = ph / L * phases
|
||||
local p = floor(fp)
|
||||
local a = fp - p
|
||||
local hb = p * taps + 1
|
||||
local hb = p * taps + kLo + 1
|
||||
local hb2 = hb + taps
|
||||
for c = 0, ch - 1 do
|
||||
local acc, acc2 = 0, 0
|
||||
local hi = (rel + kLo) * ch + c + 1
|
||||
for k = kLo, kHi do
|
||||
local x = hist[hi]
|
||||
acc += x * h[hb + k]
|
||||
acc2 += x * h[hb2 + k]
|
||||
hi += ch
|
||||
end
|
||||
for c = 1, ch do
|
||||
local acc = dot(hist[c], xi, h, hb, cnt)
|
||||
local acc2 = dot(hist[c], xi, h, hb2, cnt)
|
||||
writef32(b, o, acc + (acc2 - acc) * a)
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
ph += M
|
||||
if ph >= L then
|
||||
local q = ph // L
|
||||
ip += q
|
||||
ph -= q * L
|
||||
end
|
||||
end
|
||||
st.outPos = jmax
|
||||
local keepFrom = (jmax * M) // L - half + 1
|
||||
local drop = keepFrom - base
|
||||
if drop > 0 then
|
||||
if drop >= histFrames then
|
||||
st.hist = {}
|
||||
for c = 1, ch do
|
||||
hist[c] = {}
|
||||
end
|
||||
st.histFrames = 0
|
||||
st.base = base + histFrames
|
||||
else
|
||||
local nh: { number } = table.create((histFrames - drop) * ch) :: any
|
||||
table.move(hist, drop * ch + 1, histFrames * ch, 1, nh)
|
||||
st.hist = nh
|
||||
for c = 1, ch do
|
||||
local nh: { number } = table.create(histFrames - drop) :: any
|
||||
table.move(hist[c], drop + 1, histFrames, 1, nh)
|
||||
hist[c] = nh
|
||||
end
|
||||
st.histFrames = histFrames - drop
|
||||
st.base = base + drop
|
||||
end
|
||||
@@ -208,10 +235,15 @@ local function process(self: State, src: buffer, frames: number, out: buffer?):
|
||||
end
|
||||
local ch = self.channels
|
||||
frames = min(floor(frames), buffer.len(src) // (ch * 4))
|
||||
local hist = self.hist
|
||||
local p = self.histFrames * ch
|
||||
for i = 0, frames * ch - 1 do
|
||||
hist[p + i + 1] = readf32(src, i * 4)
|
||||
local p = self.histFrames
|
||||
for c = 1, ch do
|
||||
local x = self.hist[c]
|
||||
local o = (c - 1) * 4
|
||||
local step = ch * 4
|
||||
for i = p + 1, p + frames do
|
||||
x[i] = readf32(src, o)
|
||||
o += step
|
||||
end
|
||||
end
|
||||
self.histFrames += frames
|
||||
self.inFrames += frames
|
||||
@@ -250,6 +282,10 @@ function Resample.new(from: number, to: number, channels: number, opts: Options?
|
||||
local L: number, M: number = ti // g, fi // g
|
||||
local exact = L <= MAX_EXACT
|
||||
local phases = if exact then L else INTERP_PHASES
|
||||
local hist: { { number } } = table.create(channels) :: any
|
||||
for c = 1, channels do
|
||||
hist[c] = {}
|
||||
end
|
||||
local st: State = {
|
||||
from = from,
|
||||
to = to,
|
||||
@@ -258,7 +294,7 @@ function Resample.new(from: number, to: number, channels: number, opts: Options?
|
||||
f = if L == 1 and M == 1 then { taps = 2, half = 1, phases = 1, exact = true, h = { 1, 0 } } else makeFilter(to / from, phases, exact, q[1], q[2], cut),
|
||||
step = M,
|
||||
L = L,
|
||||
hist = {},
|
||||
hist = hist,
|
||||
histFrames = 0,
|
||||
base = 0,
|
||||
inFrames = 0,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/SoundFont/Fallback: the built-in General MIDI set (generated waveforms per GM family, drum kit on bank 128).
|
||||
-- No third-party code.
|
||||
local Parse = require("@rosetta/codecs/audio/SoundFont/Parse")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/SoundFont/Parse: SoundFont 2.0x (sfbk RIFF) reader, zones merged into regions as TinySoundFont does.
|
||||
-- After tsf.h v0.9 (MIT, (c) Bernhard Schelling; licenses/TinySoundFont-LICENSE.txt) tsf_load_presets /
|
||||
-- tsf_region_operator / tsf_region_envtosecs. Unlike tsf.h, initialAttenuation is cB * 0.04 dB (FluidSynth's
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/SoundFont/Synth: a SoundFont 2 sample synthesizer with MIDI channels.
|
||||
-- A port of TinySoundFont (tsf.h v0.9, MIT, (c) 2017-2025 Bernhard Schelling, based on SFZero (c) 2012 Steve Folta;
|
||||
-- licenses/TinySoundFont-LICENSE.txt). Unlike tsf.h, the envelope gain is ramped across each 64-sample block.
|
||||
@@ -675,6 +676,8 @@ local function voiceRender(s: State, v: Voice, out: buffer, frame: number, numSa
|
||||
local endD = region.stop
|
||||
local loopEndD = loopEnd + 1
|
||||
local loopLen = loopEnd - loopStart + 1
|
||||
local wrapAt = if isLooping then loopEnd else math.huge -- ip >= loopEnd and isLooping
|
||||
local wrapEnd = if isLooping then loopEndD else math.huge
|
||||
local pos = v.pos
|
||||
local lpActive, a0, a1, b1, b2, z1, z2 = v.lpActive, v.a0, v.a1, v.b1, v.b2, v.z1, v.z2
|
||||
local dynamicLowpass = modLfoToFilterFc ~= 0 or modEnvToFilterFc ~= 0
|
||||
@@ -719,26 +722,41 @@ local function voiceRender(s: State, v: Voice, out: buffer, frame: number, numSa
|
||||
local panL, panR = v.panL, v.panR
|
||||
local g = gainMono
|
||||
local k = block
|
||||
while k > 0 and pos < endD do
|
||||
k -= 1
|
||||
local ip = floor(pos)
|
||||
local np = if ip >= loopEnd and isLooping then loopStart else ip + 1
|
||||
local s0 = readf32(input, ip * 4)
|
||||
local val = s0 + (readf32(input, np * 4) - s0) * (pos - ip)
|
||||
if lpActive then
|
||||
if lpActive then
|
||||
while k > 0 and pos < endD do
|
||||
k -= 1
|
||||
local ip = floor(pos)
|
||||
local np = if ip >= wrapAt then loopStart else ip + 1
|
||||
local s0 = readf32(input, ip * 4)
|
||||
local val = s0 + (readf32(input, np * 4) - s0) * (pos - ip)
|
||||
local y = val * a0 + z1
|
||||
z1 = val * a1 + z2 - b1 * y
|
||||
z2 = val * a0 - b2 * y
|
||||
val = y
|
||||
val = y * g
|
||||
g += step
|
||||
writef32(out, o, readf32(out, o) + val * panL)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + val * panR)
|
||||
o += 8
|
||||
pos += pitchRatio
|
||||
if pos >= wrapEnd then
|
||||
pos -= loopLen
|
||||
end
|
||||
end
|
||||
val *= g
|
||||
g += step
|
||||
writef32(out, o, readf32(out, o) + val * panL)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + val * panR)
|
||||
o += 8
|
||||
pos += pitchRatio
|
||||
if pos >= loopEndD and isLooping then
|
||||
pos -= loopLen
|
||||
else
|
||||
while k > 0 and pos < endD do
|
||||
k -= 1
|
||||
local ip = floor(pos)
|
||||
local np = if ip >= wrapAt then loopStart else ip + 1
|
||||
local s0 = readf32(input, ip * 4)
|
||||
local val = (s0 + (readf32(input, np * 4) - s0) * (pos - ip)) * g
|
||||
g += step
|
||||
writef32(out, o, readf32(out, o) + val * panL)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + val * panR)
|
||||
o += 8
|
||||
pos += pitchRatio
|
||||
if pos >= wrapEnd then
|
||||
pos -= loopLen
|
||||
end
|
||||
end
|
||||
end
|
||||
o += k * 8
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/SoundFont: SoundFont 2 banks and the sample synth that plays MIDI through them.
|
||||
-- The synth is a port of TinySoundFont (tsf.h v0.9, MIT, (c) 2017-2025 Bernhard Schelling; licenses/TinySoundFont-LICENSE.txt).
|
||||
local Err = require("@rosetta/core/Err")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Stream: the streaming Types.Decoder over a packetised codec (gapless trim, seeking with pre-roll).
|
||||
-- New in rosetta.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tracker/Load: helpers mapping other tracker formats' effects onto the engine's S3M / IT or MOD / XM families.
|
||||
-- Ported from OpenMPT's ModCommand helpers (ConvertModCommand, ConvertToVolCommand, FillInTwoCommands, GetEffectWeight,
|
||||
-- CPattern::WriteEffect; BSD licence, licenses/openmpt-LICENSE.txt).
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tracker/Mixer: tracker voice mixing (loops, IT sustain loops, IT two-pole resonant filter, click ramps).
|
||||
-- No third-party code.
|
||||
local floor, ceil, min = math.floor, math.ceil, math.min
|
||||
local floor, ceil, min, max = math.floor, math.ceil, math.min, math.max
|
||||
local readf32, writef32 = buffer.readf32, buffer.writef32
|
||||
|
||||
local Mixer = {}
|
||||
@@ -87,7 +88,10 @@ local function mixVoice(v: any, out: buffer?, off: number, n: number, linear: bo
|
||||
local fa, fb0, fb1 = v.fa, v.fb0, v.fb1
|
||||
local y1l, y2l, y1r, y2r = v.y1l, v.y2l, v.y1r, v.y2r
|
||||
local o = (off + i) * 8
|
||||
for _ = 1, m do
|
||||
-- the common voice (mono, interpolated) runs the general loop only while its volume ramps
|
||||
local fast = nch == 1 and linear
|
||||
local mg = if fast then (if rl > 0 then min(rl, m) else 0) else m
|
||||
for _ = 1, mg do
|
||||
local idx = floor(p)
|
||||
if idx > hi then
|
||||
idx = hi
|
||||
@@ -148,6 +152,80 @@ local function mixVoice(v: any, out: buffer?, off: number, n: number, linear: bo
|
||||
o += 8
|
||||
p += step
|
||||
end
|
||||
-- while p < e - 1 (forward), idx = floor(p) is in range and idx + 1 < e needs no wrap: those steps skip the
|
||||
-- checks; two steps of margin for the rounding of the running p
|
||||
local k0 = mg + 1
|
||||
local safe = mg
|
||||
if mg < m and step >= 0.001 and p >= 0 and s >= 0 and e <= len then
|
||||
safe = min(m, mg + floor((e - 1 - p) / step) - 2)
|
||||
end
|
||||
if mg < m and fOn then -- the general loop, specialised to a filtered mono voice after its ramp
|
||||
for _ = k0, safe do
|
||||
local idx = floor(p)
|
||||
local a = readf32(data, idx * 4)
|
||||
local x = a + (readf32(data, idx * 4 + 4) - a) * (p - idx)
|
||||
local y = x * fa + y1l * fb0 + y2l * fb1
|
||||
y2l, y1l = y1l, y
|
||||
writef32(out, o, readf32(out, o) + y * gl)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + y * gr)
|
||||
o += 8
|
||||
p += step
|
||||
end
|
||||
for _ = max(k0, safe + 1), m do
|
||||
local idx = floor(p)
|
||||
if idx > hi then
|
||||
idx = hi
|
||||
elseif idx < 0 then
|
||||
idx = 0
|
||||
end
|
||||
local j = idx + 1
|
||||
if j >= e then
|
||||
j = wrapJ
|
||||
end
|
||||
if j > hi then
|
||||
j = hi
|
||||
end
|
||||
local a = readf32(data, idx * 4)
|
||||
local x = a + (readf32(data, j * 4) - a) * (p - idx)
|
||||
local y = x * fa + y1l * fb0 + y2l * fb1
|
||||
y2l, y1l = y1l, y
|
||||
writef32(out, o, readf32(out, o) + y * gl)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + y * gr)
|
||||
o += 8
|
||||
p += step
|
||||
end
|
||||
elseif mg < m then -- the same, unfiltered
|
||||
for _ = k0, safe do
|
||||
local idx = floor(p)
|
||||
local a = readf32(data, idx * 4)
|
||||
local x = a + (readf32(data, idx * 4 + 4) - a) * (p - idx)
|
||||
writef32(out, o, readf32(out, o) + x * gl)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + x * gr)
|
||||
o += 8
|
||||
p += step
|
||||
end
|
||||
for _ = max(k0, safe + 1), m do
|
||||
local idx = floor(p)
|
||||
if idx > hi then
|
||||
idx = hi
|
||||
elseif idx < 0 then
|
||||
idx = 0
|
||||
end
|
||||
local j = idx + 1
|
||||
if j >= e then
|
||||
j = wrapJ
|
||||
end
|
||||
if j > hi then
|
||||
j = hi
|
||||
end
|
||||
local a = readf32(data, idx * 4)
|
||||
local x = a + (readf32(data, j * 4) - a) * (p - idx)
|
||||
writef32(out, o, readf32(out, o) + x * gl)
|
||||
writef32(out, o + 4, readf32(out, o + 4) + x * gr)
|
||||
o += 8
|
||||
p += step
|
||||
end
|
||||
end
|
||||
v.p = p
|
||||
v.gl, v.gr, v.rampN = gl, gr, rl
|
||||
v.y1l, v.y2l, v.y1r, v.y2r = y1l, y2l, y1r, y2r
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tracker/Pcm: raw 8 / 16-bit tracker sample data (signed / unsigned, XM / IT 2.15 delta coding,
|
||||
-- interleaved or planar stereo) <-> f32.
|
||||
local readu8, readi8, readu16, readi16 = buffer.readu8, buffer.readi8, buffer.readu16, buffer.readi16
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tracker/Player: the tracker sequencer for the MOD, S3M, XM and IT effect families.
|
||||
-- Written from the format documents (ProTracker 2.3 docs, the XM spec and FT2 behaviour notes, ST3 TECH.DOC, ITTECH.TXT);
|
||||
-- no third-party code.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tracker/Tables: tracker lookup tables, from the public format documents (ProTracker 2.3 effect docs,
|
||||
-- FT2 / XM spec, ST3 TECH.DOC, ITTECH.TXT).
|
||||
local Tables = {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tracker: the shared tracker engine behind music/mod, s3m, xm and it, and the formats mapped onto them.
|
||||
-- Written from the format documents (ProTracker 2.3, the XM spec + FT2 behaviour, ST3 TECH.DOC, ITTECH.TXT); libxmp /
|
||||
-- OpenMPT were used only as reference players for tests.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Tta: the TTA1 (True Audio) lossless codec.
|
||||
-- From the TTA1 format description (22-byte header and seek table with CRC-32s, frames of 256 / 245 seconds); no libtta /
|
||||
-- ffmpeg code (LGPL). Format 2 (password) is UNSUPPORTED.
|
||||
|
||||
@@ -278,12 +278,12 @@ local function partition(br: Codebook.Br, book: Codebook.Book, target: { number
|
||||
return false
|
||||
end
|
||||
local base = e * dims
|
||||
local len = math.min(dims, psize - k)
|
||||
local at = offset + k
|
||||
for i = 0, len - 1 do
|
||||
if at + i < limit then
|
||||
target[at + i + 1] += vq[base + i + 1]
|
||||
end
|
||||
-- the values at + i < limit of the first min(dims, psize - k)
|
||||
local len = math.min(dims, psize - k, limit - at)
|
||||
local d = base - at
|
||||
for t = at + 1, at + len do
|
||||
target[t] += vq[t + d]
|
||||
end
|
||||
k += dims
|
||||
end
|
||||
@@ -517,13 +517,13 @@ function Packet.decode(st: State, b: buffer, off: number, size: number): number
|
||||
for j = 1, leftStart do
|
||||
fr[j] = 0
|
||||
end
|
||||
local L = leftEnd - leftStart
|
||||
for j = 0, L - 1 do
|
||||
fr[leftStart + j + 1] *= lslope[j + 1]
|
||||
for j = 1, leftEnd - leftStart do
|
||||
fr[leftStart + j] *= lslope[j]
|
||||
end
|
||||
local R = rightEnd - rightStart
|
||||
for j = 0, R - 1 do
|
||||
fr[rightStart + j + 1] *= rslope[R - j]
|
||||
local rb = rightStart + R + 1 -- fr[rightStart + j + 1] *= rslope[R - j]
|
||||
for j = 1, R do
|
||||
fr[rb - j] *= rslope[j]
|
||||
end
|
||||
for j = rightEnd + 1, n do
|
||||
fr[j] = 0
|
||||
@@ -539,13 +539,20 @@ function Packet.decode(st: State, b: buffer, off: number, size: number): number
|
||||
local tl = st.tailLen
|
||||
for c = 1, ch do
|
||||
local out, tail, fr = st.out[c], st.tail[c], st.frame[c]
|
||||
for j = 0, count - 1 do
|
||||
local v = if j < tl then tail[j + 1] else 0
|
||||
local fi = j - o
|
||||
if fi >= 0 then
|
||||
v += fr[fi + 1]
|
||||
end
|
||||
out[j + 1] = v
|
||||
-- out[j] = (tail[j] if j <= tl else 0) + (fr[j - o] if j > o), j = 1 .. count
|
||||
local a = math.min(math.max(o, 0), count) -- j <= a: no frame sample
|
||||
local b = math.min(tl, count) -- j <= b: a tail sample
|
||||
for j = 1, math.min(a, b) do
|
||||
out[j] = tail[j]
|
||||
end
|
||||
for j = b + 1, a do
|
||||
out[j] = 0
|
||||
end
|
||||
for j = a + 1, b do
|
||||
out[j] = tail[j] + fr[j - o]
|
||||
end
|
||||
for j = math.max(a, b) + 1, count do
|
||||
out[j] = 0 + fr[j - o]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Vorbis/Setup: the three Vorbis header packets (Vorbis I spec section 4.2).
|
||||
-- Ported from stb_vorbis 1.22 start_decoder (public domain / MIT, licenses/stb_vorbis-LICENSE.txt). Floor 0 is
|
||||
-- rejected as unsupported, as stb_vorbis does.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Vorbis/Tables: the floor 1 inverse dB table (Vorbis I specification section 10.1, as in stb_vorbis 1.22,
|
||||
-- public domain / MIT, licenses/stb_vorbis-LICENSE.txt).
|
||||
return table.freeze({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Vorbis: the Vorbis I decoder without its container.
|
||||
-- A Luau port of stb_vorbis 1.22 (public domain / MIT, licenses/stb_vorbis-LICENSE.txt).
|
||||
local Vorbis = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/VorbisComment: Vorbis comment fields ("KEY=value"; Vorbis, Opus, FLAC) <-> Types.Tags.
|
||||
local VorbisComment = {}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/WavPack: the WavPack 4 / 5 audio codec (the blocks of .wv files, and of WavPack in Matroska).
|
||||
-- Ported from WavPack 5.9.0 (David Bryant, BSD 3-clause, licenses/wavpack-LICENSE.txt). Not supported: DSD, pre-4.0
|
||||
-- streams (version < 0x402).
|
||||
|
||||
@@ -86,12 +86,13 @@ function RangeDecoder.new(buf: buffer, base: number, storage: number): Dec
|
||||
return d
|
||||
end
|
||||
|
||||
function RangeDecoder.decode(d: Dec, ft: number): number
|
||||
local function decode(d: Dec, ft: number): number
|
||||
local ext = d.rng // ft
|
||||
d.ext = ext
|
||||
local s = d.val // ext
|
||||
return ft - math.min(s + 1, ft)
|
||||
end
|
||||
RangeDecoder.decode = decode
|
||||
|
||||
function RangeDecoder.decodeBin(d: Dec, bits: number): number
|
||||
local ext = rshift(d.rng, bits)
|
||||
@@ -101,16 +102,16 @@ function RangeDecoder.decodeBin(d: Dec, bits: number): number
|
||||
return ft - math.min(s + 1, ft)
|
||||
end
|
||||
|
||||
function RangeDecoder.update(d: Dec, fl: number, fh: number, ft: number)
|
||||
local function update(d: Dec, fl: number, fh: number, ft: number)
|
||||
local s = d.ext * (ft - fh)
|
||||
d.val = band(d.val - s, 0xFFFFFFFF) -- uint32 wrap (corrupt streams only)
|
||||
if fl > 0 then
|
||||
d.rng = d.ext * (fh - fl)
|
||||
else
|
||||
d.rng -= s
|
||||
local rng = if fl > 0 then d.ext * (fh - fl) else d.rng - s
|
||||
d.rng = rng
|
||||
if rng <= CODE_BOT then
|
||||
normalize(d)
|
||||
end
|
||||
normalize(d)
|
||||
end
|
||||
RangeDecoder.update = update
|
||||
|
||||
function RangeDecoder.bitLogp(d: Dec, logp: number): boolean
|
||||
local r = d.rng
|
||||
@@ -118,12 +119,15 @@ function RangeDecoder.bitLogp(d: Dec, logp: number): boolean
|
||||
local s = rshift(r, logp)
|
||||
local ret = v < s
|
||||
if ret then
|
||||
d.rng = s
|
||||
r = s
|
||||
else
|
||||
d.val = v - s
|
||||
d.rng = r - s
|
||||
r -= s
|
||||
end
|
||||
d.rng = r
|
||||
if r <= CODE_BOT then
|
||||
normalize(d)
|
||||
end
|
||||
normalize(d)
|
||||
return ret
|
||||
end
|
||||
|
||||
@@ -140,11 +144,13 @@ function RangeDecoder.icdf(d: Dec, icdf: { number }, off: number, ftb: number):
|
||||
until v >= s
|
||||
d.val = v - s
|
||||
d.rng = t - s
|
||||
normalize(d)
|
||||
if t - s <= CODE_BOT then
|
||||
normalize(d)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function RangeDecoder.bits(d: Dec, bits: number): number
|
||||
local function bits(d: Dec, bits: number): number
|
||||
local window = d.end_window
|
||||
local available = d.nend_bits
|
||||
if available < bits then
|
||||
@@ -171,6 +177,7 @@ function RangeDecoder.bits(d: Dec, bits: number): number
|
||||
d.nbits_total += bits
|
||||
return ret
|
||||
end
|
||||
RangeDecoder.bits = bits
|
||||
|
||||
function RangeDecoder.uint(d: Dec, ft0: number): number
|
||||
local ft = ft0 - 1
|
||||
@@ -178,17 +185,17 @@ function RangeDecoder.uint(d: Dec, ft0: number): number
|
||||
if ftb > UINT_BITS then
|
||||
ftb -= UINT_BITS
|
||||
local ft1 = rshift(ft, ftb) + 1
|
||||
local s = RangeDecoder.decode(d, ft1)
|
||||
RangeDecoder.update(d, s, s + 1, ft1)
|
||||
local t = bor(lshift(s, ftb), RangeDecoder.bits(d, ftb))
|
||||
local s = decode(d, ft1)
|
||||
update(d, s, s + 1, ft1)
|
||||
local t = bor(lshift(s, ftb), bits(d, ftb))
|
||||
if t <= ft then
|
||||
return t
|
||||
end
|
||||
d.error = 1
|
||||
return ft
|
||||
else
|
||||
local s = RangeDecoder.decode(d, ft0)
|
||||
RangeDecoder.update(d, s, s + 1, ft0)
|
||||
local s = decode(d, ft0)
|
||||
update(d, s, s + 1, ft0)
|
||||
return s
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- containers/IsoBmff/Box: the box tree of an ISO BMFF / QuickTime file (ISO/IEC 14496-12 4.2): 32-bit, 64-bit
|
||||
-- (size 1) and to-the-end (size 0) sizes, uuid boxes, full-box version / flags, and the recursion into the container
|
||||
-- boxes (moov / trak / mdia / minf / stbl / udta / meta / ilst items / moof / traf / iprp / ipco / iref / dinf / ...).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- containers/IsoBmff/Demux: tracks and sample tables of an ISO BMFF / QuickTime file (ISO/IEC 14496-12 8.3 - 8.8),
|
||||
-- edit lists and fragments (mvex / trex, moof / traf / tfhd / tfdt / trun). The per-sample tables are columnar arrays,
|
||||
-- offsets absolute in the reader's buffer. Never throws.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- containers/IsoBmff/Meta: the metadata boxes. HEIF / AVIF items (ISO/IEC 23008-12: pitm, iinf / infe, iloc
|
||||
-- versions 0 - 2, iref, iprp / ipco / ipma, idat; the common properties ispe / pixi / colr / irot / imir / clap / auxC
|
||||
-- decoded, codec configurations av1C / hvcC / avcC kept raw) and the iTunes tags (udta / meta / ilst: text, trkn /
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- containers/IsoBmff/Mux: writes a progressive ISO BMFF / MP4 / M4A file (ISO/IEC 14496-12): ftyp, moov first ("fast
|
||||
-- start"), the samples interleaved in chunks in one mdat, udta / meta / ilst tags; co64 past 4 GB. Audio and video
|
||||
-- sample entries with their configuration box, plus raw child boxes. Never throws: bad specs return nil, Err.ARG.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- containers/IsoBmff/QtPalette: the depth and colour table of a QuickTime video sample description (Apple QuickTime
|
||||
-- File Format, "Video sample description": depth at byte 82, color table ID at 84, then the table when the ID is 0).
|
||||
-- Used by the MOV demuxer and by Matroska's V_QUICKTIME tracks (whose CodecPrivate is the same description). Depths 1,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- containers/IsoBmff: ISO base media file format (ISO/IEC 14496-12) and its relatives: MP4 / M4A / M4V / MOV (QuickTime)
|
||||
-- / 3GP, fragmented MP4 (moof), HEIF / AVIF items (ISO/IEC 23008-12), iTunes tags. A container (layer 2): m4a, mp4,
|
||||
-- mov, heif, avif build on it. Written from the specifications; no third-party code.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/669: Composer 669 / UNIS 669 modules ("if" / "JN"), ported from OpenMPT's Load_669.cpp (BSD,
|
||||
-- licenses/openmpt-LICENSE.txt). Supports: 8 channels, 64-row patterns, played as the "s3m" family with 669's quirks
|
||||
-- (periods in Hz, auto portamentos, effects D..H, a fixed 78 BPM). Not supported: UNIS 669's speed 0, writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/ahx: AHX (Abyss' Highest eXperience) 4-channel Amiga synth modules, "THX\0" .. "THX\2", rendered through
|
||||
-- codecs/audio/Hively (a port of HivelyTracker's hvl2wav, BSD-3-Clause; at 44.1 kHz, stereo 0, equal to hvl2wav).
|
||||
-- Supports: tracks, positions with transposes, PList instruments, subsongs. Not supported: writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/far: Farandole Composer modules (FAR, 16 channels), ported from OpenMPT's Load_far.cpp (BSD,
|
||||
-- licenses/openmpt-LICENSE.txt). Plays as the "s3m" family with FAR's quirks (periods in Hz, a slide step of
|
||||
-- 36318 / 1024 Hz, OpenMPT's fixed 80 BPM). Not supported: FAR's tempo effects (D / E), note offset (C), writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/hmp: HMI SOS music: HMP ("HMIMIDIP", "HMIMIDIP013195") and HMI ("HMI-MIDISONG061595"), from the layout
|
||||
-- notes (wildmidi only as a test reference). Decodes to a Types.Midi (format 1, a track per chunk; the tick rate at
|
||||
-- HMP 0x38 / HMI byte 212, as division 60). Not supported: writing, HMP branch tables.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/hvl: HivelyTracker modules, "HVL\0" / "HVL\1" (AHX extended: 4..16 channels, two effect columns, ring
|
||||
-- modulation, panning, stereo separation), rendered through codecs/audio/Hively (a port of hvl2wav, BSD-3-Clause; at
|
||||
-- 44.1 kHz equal to hvl2wav). Not supported: writing.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- music/it/Itsex: IT 2.14 / 2.15 (double-delta) sample decompression, from ITTECH.TXT: 0x8000-byte output blocks, each
|
||||
-- a u16 length then an LSB-first bit stream of deltas with three width-change methods.
|
||||
local readu8, readu16, writef32 = buffer.readu8, buffer.readu16, buffer.writef32
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/it: Impulse Tracker modules (IMPM, ITTECH.TXT), played through codecs/audio/Tracker. Supports: 64 channels,
|
||||
-- instrument / sample mode, old and new instrument headers, envelopes, NNAs, resonant filters (default Zxx macros),
|
||||
-- IT 2.14 / 2.15 compressed samples, the message. Not supported: embedded MIDI macros, OpenMPT extensions, writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/med: MED / OctaMED modules (MMD0..MMD3), ported from OpenMPT's Load_med.cpp (BSD,
|
||||
-- licenses/openmpt-LICENSE.txt); the first song plays as the "xm" family with Amiga periods. Supports: 1..64 tracks,
|
||||
-- play sequences, hold / decay, IFF multi-octave samples. Not supported: synth / MIDI instruments, echo, writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/midi/Smf: SMF 1.0 MThd / MTrk <-> Types.Midi (running status also across meta / sysex, RIFF RMID unwrapped).
|
||||
-- Writes what python mido writes: running status reset after meta / sysex, one end-of-track, track names at tick 0.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/midi: Standard MIDI Files (SMF 1.0 formats 0 / 1 / 2, PPQ and SMPTE; RIFF RMID read), from the spec. Supports:
|
||||
-- decode to a Types.Midi, .kar lyrics, encode (byte-identical to python mido by default), the tempo map, rendering
|
||||
-- through codecs/audio/SoundFont. Not supported: RMID write, XMF / DLS banks, system common bytes in tracks.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/mod: ProTracker / NoiseTracker / StarTrekker MODs (M.K., M!K!, FLT4, xCHN, xxCH, xxCN, CD81, OKTA, TDZx;
|
||||
-- 15-sample Soundtracker by name or extension), from the ProTracker 2.3 docs. Writes 31-sample MODs from "mod" modules
|
||||
-- and XM ones that fit. Not supported: FLT8's split patterns (read as 8 channels), the E0x filter, PowerPacker files.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/mtm: MultiTracker modules (MTM, 1..32 channels, patterns of shared tracks), ported from OpenMPT's Load_mtm.cpp
|
||||
-- (BSD, licenses/openmpt-LICENSE.txt); played as the "xm" family with Amiga periods, as OpenMPT does. Not supported:
|
||||
-- MultiTracker's E9x / EDx retrigger timing and vibrato start phase (played as in XM), writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/mus: DMX MUS ("MUS\x1a"; Doom, Heretic, Hexen, Strife), from Vladimir Arnost's "MUS File Format" (wildmidi
|
||||
-- only as a test reference). Decodes to a Types.Midi as the usual converters map it (MUS channel 15 -> 9; 140 ticks/s
|
||||
-- as division 70 at 500000 us per quarter). Not supported: writing (encode as .mid with the midi format).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/okt: Oktalyzer modules (OKTASONG, 4..8 channels: each Amiga channel may be a mixed pair), ported from OpenMPT's
|
||||
-- Load_okt.cpp (BSD, licenses/openmpt-LICENSE.txt); played as the "it" family with Amiga periods, loops as sustain
|
||||
-- loops (released by R), the three arpeggios and note slides. Not supported: the LED filter (F), writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/ptm: PolyTracker modules (PTMF, up to 32 channels), ported from OpenMPT's Load_ptm.cpp (BSD,
|
||||
-- licenses/openmpt-LICENSE.txt); played as the "it" family with Amiga periods, as OpenMPT converts PTM. Not supported:
|
||||
-- reverse sample offset (K), sample offsets scaled for 16-bit samples, writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/s3m: Scream Tracker 3 modules (SCRM, ST3 TECH.DOC). Supports: 32 PCM channels, 8 / 16-bit mono / stereo
|
||||
-- samples, the panning table, ST3.00 fast slides, every ST3 effect; notes stored an octave up (S3M C-4 = note 61, as IT
|
||||
-- shows S3M files). Not supported: AdLib (OPL) instruments (silent), writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/sf2: SoundFont 2 banks (SoundFont 2.04 spec), read-only, over codecs/audio/SoundFont (a TinySoundFont port).
|
||||
-- Supports: INFO, 16 / 24-bit (sm24) samples, presets / instruments with global zones, generators merged into regions.
|
||||
-- Not supported: writing, SF3 (Vorbis samples), modulators (skipped).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/stm: Scream Tracker 2 modules (STM, "!Scream!" / BMOD2STM / WUZAMOD! / SWavePro), ported from OpenMPT's
|
||||
-- Load_stm.cpp (BSD, licenses/openmpt-LICENSE.txt); played as the "s3m" family with ST2's tempo, no effect memory and
|
||||
-- its deferred Bxx. Not supported: STX, ST2's noise for samples at volume 0 (silent), writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/ult: UltraTracker modules (MAS_UTrack_V001 .. V004, up to 32 channels), ported from OpenMPT's Load_ult.cpp
|
||||
-- (BSD, licenses/openmpt-LICENSE.txt); played as the "it" family with Amiga periods, as OpenMPT converts ULT. Not
|
||||
-- supported: reverse (5x2), "no loop" (5x1), E0x, offsets past 64 KiB, pre-1.4 log volumes, writing.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- music/umx: Unreal Engine 1 music packages (.umx, versions up to 128), ported from OpenMPT's UMXTools.cpp /
|
||||
-- ContainerUMX.cpp (BSD, licenses/openmpt-LICENSE.txt): the IT / S3M / XM / MOD module of a "music" export; decode
|
||||
-- needs opts.decodeModule (the api passes it). Not supported: Unreal Engine 2+ packages (.uax), writing.
|
||||
|
||||
Loaded 100 of 113 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user