Compare commits
109
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dde6be117c | ||
|
|
e993458d36 | ||
|
|
10f70c3a8a | ||
|
|
028bee3f59 | ||
|
|
9a4cacc40b | ||
|
|
a081e7d437 | ||
|
|
95efdd7e3e | ||
|
|
c291312f8a | ||
|
|
778502c54d | ||
|
|
686a1fbf86 | ||
|
|
627ddded77 | ||
|
|
6ddc5b6017 | ||
|
|
de755ca036 | ||
|
|
7a6368242b | ||
|
|
c0766614bc | ||
|
|
8a706a993c | ||
|
|
d5276798c3 | ||
|
|
c93ef2fa6f | ||
|
|
3f788e9d22 | ||
|
|
8bd15840d8 | ||
|
|
f9c95a357b | ||
|
|
351f6620dd | ||
|
|
58df9e8a3a | ||
|
|
e6d78a3033 | ||
|
|
a5a03ecb8d | ||
|
|
d339f1e081 | ||
|
|
6fab0d3dca | ||
|
|
53290f0e0c | ||
|
|
688503fb2d | ||
|
|
dbca9d5670 | ||
|
|
11d0df9418 | ||
|
|
0e0b213a80 | ||
|
|
4eca395b00 | ||
|
|
e100366cb8 | ||
|
|
5b4ee7f937 | ||
|
|
a2cd103674 | ||
|
|
be397639ea | ||
|
|
738b881349 | ||
|
|
5e71837637 | ||
|
|
903e239a0e | ||
|
|
2dac8b2a14 | ||
|
|
cc4aa331eb | ||
|
|
74df2ed607 | ||
|
|
64b0c75a53 | ||
|
|
8d305bb942 | ||
|
|
3905426eff | ||
|
|
ddc5dd101f | ||
|
|
0d05130526 | ||
|
|
b1d9fad454 | ||
|
|
f6c7857525 | ||
|
|
08f3b1c5bd | ||
|
|
37aa29d03e | ||
|
|
b7e96cbf34 | ||
|
|
3e4170288b | ||
|
|
1e69799c21 | ||
|
|
8f26e32a71 | ||
|
|
c19a68dfae | ||
|
|
8b07f26666 | ||
|
|
9855a7edd6 | ||
|
|
4c3159d02d | ||
|
|
3c8d5e99d7 | ||
|
|
fe1ee676c6 | ||
|
|
4ea42f1375 | ||
|
|
3a4279dd1f | ||
|
|
7a69ba8455 | ||
|
|
097a4340b9 | ||
|
|
9ae847d2a3 | ||
|
|
175ca9e823 | ||
|
|
59c2438ca1 | ||
|
|
e4840b719b | ||
|
|
3320339507 | ||
|
|
11b7f89dab | ||
|
|
b4f4966c6f | ||
|
|
7947dd7f3b | ||
|
|
d4163678c3 | ||
|
|
0f0da6e8ea | ||
|
|
6baa698abe | ||
|
|
67e116a6c6 | ||
|
|
051aca5b74 | ||
|
|
0ec772ee30 | ||
|
|
9c02ebdee5 | ||
|
|
c30e8618fc | ||
|
|
9efeea304e | ||
|
|
4bd59a30c8 | ||
|
|
69ee08a600 | ||
|
|
2e82b7d0af | ||
|
|
52d2d7ebf9 | ||
|
|
2704653a3e | ||
|
|
e51fd3585e | ||
|
|
80fd9cf1e8 | ||
|
|
158fa3d3f0 | ||
|
|
1f74419ccf | ||
|
|
082ea2019e | ||
|
|
d8212c6839 | ||
|
|
4b97caa7cc | ||
|
|
04ddb91340 | ||
|
|
a146611a27 | ||
|
|
5ad934565d | ||
|
|
719abb97c0 | ||
|
|
aacc78fac2 | ||
|
|
524179ec67 | ||
|
|
5096eb4898 | ||
|
|
1c79609ecb | ||
|
|
0b6773db8b | ||
|
|
c7e0639913 | ||
|
|
75984be212 | ||
|
|
7d4e0381fe | ||
|
|
9e7d159af8 | ||
|
|
01c044805f |
No files matched your search
+3
-1
@@ -1,7 +1,9 @@
|
||||
# build outputs (tools/build.py): the single-file bundles and their linemaps are committed, the rest is internal
|
||||
# build outputs (tools/build.py): the bundles (Rosetta.luau, Rosetta.rbxm / .rbxmx, rosetta.lua) and their linemaps are committed, the rest is internal
|
||||
/build/*
|
||||
!/build/Rosetta.luau
|
||||
!/build/rosetta.lua
|
||||
!/build/Rosetta.rbxm
|
||||
!/build/Rosetta.rbxmx
|
||||
!/build/*.linemap.json
|
||||
# generated test fixtures (tools/fixtures.py)
|
||||
/tests/gen/
|
||||
|
||||
@@ -4,9 +4,11 @@ Read, write and convert file formats in pure Luau, on Roblox, LuaJIT / LÖVE and
|
||||
|
||||
## Install
|
||||
|
||||
- **Roblox:** put [`build/Rosetta.luau`](build/Rosetta.luau) in a ModuleScript (e.g. ReplicatedStorage.Rosetta),
|
||||
or mount it with Rojo (`"Rosetta": { "$path": "rosetta/build/Rosetta.luau" }`; this repo's `default.project.json`
|
||||
does). Then `local F = require(ReplicatedStorage.Rosetta)`.
|
||||
- **Roblox (native):** insert [`build/Rosetta.rbxm`](build/Rosetta.rbxm) (a `Rosetta` ModuleScript whose child chunks
|
||||
load on first use, each compiled natively), or mount it with Rojo (`"$path": "rosetta/build/Rosetta.rbxm"`; this
|
||||
repo's `default.project.json` does). Then `local F = require(ReplicatedStorage.Rosetta)`.
|
||||
- **Roblox (one file, no native code):** paste [`build/Rosetta.luau`](build/Rosetta.luau) into a ModuleScript, or mount
|
||||
it with Rojo (`"$path": "rosetta/build/Rosetta.luau"`). Same API; interpreted, so the codecs run slower.
|
||||
- **LÖVE / LuaJIT:** copy [`build/rosetta.lua`](build/rosetta.lua). `local F = require("rosetta")` with its folder on
|
||||
`package.path`, or `local F = dofile("rosetta.lua")`.
|
||||
- **Luau CLI:** alias the sources in `.luaurc` (`"rosetta": "rosetta/src/Rosetta"`), then
|
||||
@@ -44,12 +46,13 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list
|
||||
## Formats
|
||||
|
||||
<!-- formats:begin -->
|
||||
174 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md)
|
||||
199 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md)
|
||||
adds each format's capabilities.
|
||||
|
||||
| Category | Format | Extensions | Read | Write |
|
||||
|---|---|---|---|---|
|
||||
| Images | ani | .ani | yes | yes |
|
||||
| Images | art | .art | yes | yes |
|
||||
| Images | blp | .blp | yes | yes |
|
||||
| Images | bmp | .bmp .dib | yes | yes |
|
||||
| Images | dds | .dds | yes | yes |
|
||||
@@ -61,11 +64,13 @@ adds each format's capabilities.
|
||||
| Images | ilbm | .iff .ilbm .lbm .pbm | yes | yes |
|
||||
| Images | jpeg | .jpg .jpeg .jpe .jfif | yes | yes |
|
||||
| Images | ktx | .ktx2 .ktx | yes | yes |
|
||||
| Images | lmp | .lmp | yes | yes |
|
||||
| Images | pcx | .pcx .pcc .dcx | yes | yes |
|
||||
| Images | png | .png .apng | yes | yes |
|
||||
| Images | pnm | .pnm .pbm .pgm .ppm .pam .pfm | yes | yes |
|
||||
| Images | qoi | .qoi | yes | yes |
|
||||
| Images | sgi | .sgi .rgb .rgba .bw .int .inta | yes | yes |
|
||||
| Images | spr | .spr | yes | yes |
|
||||
| Images | sunras | .ras .sun .rs .im1 .im8 .im24 .im32 | yes | yes |
|
||||
| Images | tga | .tga .icb .vda .vst .tpic | yes | yes |
|
||||
| Images | tiff | .tif .tiff | yes | yes |
|
||||
@@ -108,14 +113,20 @@ adds each format's capabilities.
|
||||
| Video | y4m | .y4m | yes | yes |
|
||||
| 3D models | 3ds | .3ds | yes | yes |
|
||||
| 3D models | 3mf | .3mf | yes | yes |
|
||||
| 3D models | ase | .ase .ask | yes | yes |
|
||||
| 3D models | b3d | .b3d | yes | - |
|
||||
| 3D models | blend | .blend | yes | - |
|
||||
| 3D models | bsp | .bsp | yes | - |
|
||||
| 3D models | buildmap | .map | yes | yes |
|
||||
| 3D models | d3map | .map | yes | - |
|
||||
| 3D models | dae | .dae .zae | yes | yes |
|
||||
| 3D models | fbx | .fbx | yes | yes |
|
||||
| 3D models | gltf | .gltf .glb | yes | yes |
|
||||
| 3D models | godot | .tscn .escn | yes | yes |
|
||||
| 3D models | iqm | .iqm | yes | yes |
|
||||
| 3D models | ldraw | .ldr .mpd .dat | yes | - |
|
||||
| 3D models | lwo | .lwo .lxo | yes | - |
|
||||
| 3D models | map | .map | yes | yes |
|
||||
| 3D models | mca | .mca .mcr | yes | - |
|
||||
| 3D models | md2 | .md2 | yes | - |
|
||||
| 3D models | md3 | .md3 | yes | - |
|
||||
@@ -126,14 +137,20 @@ adds each format's capabilities.
|
||||
| 3D models | off | .off | yes | yes |
|
||||
| 3D models | ply | .ply | yes | yes |
|
||||
| 3D models | pmx | .pmx .pmd | yes | - |
|
||||
| 3D models | proc | .proc | yes | - |
|
||||
| 3D models | qb | .qb | yes | yes |
|
||||
| 3D models | rbxm | .rbxm .rbxl | yes | yes |
|
||||
| 3D models | rbxmx | .rbxmx .rbxlx | yes | yes |
|
||||
| 3D models | robloxmesh | .mesh | yes | yes |
|
||||
| 3D models | schematic | .schem .schematic .litematic | yes | yes |
|
||||
| 3D models | smd | .smd | yes | yes |
|
||||
| 3D models | sourcemdl | .mdl | yes | - |
|
||||
| 3D models | stl | .stl | yes | yes |
|
||||
| 3D models | t3d | .t3d | yes | - |
|
||||
| 3D models | udmf | .udmf .textmap | yes | - |
|
||||
| 3D models | usda | .usda .usd .usdz | yes | yes |
|
||||
| 3D models | vbsp | .bsp | yes | - |
|
||||
| 3D models | vmf | .vmf .vmx | yes | yes |
|
||||
| 3D models | vox | .vox | yes | yes |
|
||||
| 3D models | vrml | .wrl .wrz .vrml | yes | yes |
|
||||
| 3D models | x | .x | yes | - |
|
||||
@@ -172,9 +189,12 @@ adds each format's capabilities.
|
||||
| Archives | pak | .pak .sin | yes | yes |
|
||||
| Archives | rpm | .rpm | yes | - |
|
||||
| Archives | tar | .tar | yes | yes |
|
||||
| Archives | unitypackage | .unitypackage | yes | yes |
|
||||
| Archives | uu | .uu .uue .xxe .b64 | yes | yes |
|
||||
| Archives | vpk | .vpk | yes | yes |
|
||||
| Archives | vswap | .wl6 .wl1 .sod .sdm .vswap | yes | - |
|
||||
| Archives | wad | .wad | yes | yes |
|
||||
| Archives | wad2 | .wad | yes | yes |
|
||||
| Archives | xz | .xz .txz .lzma | yes | - |
|
||||
| Archives | yenc | .yenc .ync | yes | yes |
|
||||
| Archives | z | .z .taz .tz | yes | yes |
|
||||
@@ -188,10 +208,17 @@ adds each format's capabilities.
|
||||
| Data | msgpack | .msgpack .mpk | yes | yes |
|
||||
| Data | nbt | .nbt .dat .mcstructure .dat_old | yes | yes |
|
||||
| Data | plist | .plist | yes | yes |
|
||||
| Data | q3shader | .shader | yes | yes |
|
||||
| Data | q3skin | .skin | yes | yes |
|
||||
| Data | snbt | .snbt | yes | yes |
|
||||
| Data | toml | .toml | yes | yes |
|
||||
| Data | tres | .tres | yes | yes |
|
||||
| Data | vdf | .vdf .acf .res .kv | yes | yes |
|
||||
| Data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes |
|
||||
| Data | yaml | .yaml .yml | yes | yes |
|
||||
| Vector graphics and tile maps | gamemaps | .wl6 .wl1 .sod .sdm | yes | - |
|
||||
| Vector graphics and tile maps | ldtk | .ldtk | yes | yes |
|
||||
| Vector graphics and tile maps | ogmo | .ogmo | yes | yes |
|
||||
| Vector graphics and tile maps | svg | .svg | yes | yes |
|
||||
| Vector graphics and tile maps | tiled | .tmx .tmj .tsx .tsj | yes | yes |
|
||||
| Layered images | aseprite | .aseprite .ase | yes | yes |
|
||||
@@ -237,11 +264,11 @@ Shared by the formats, not loadable on their own (`src/Rosetta/codecs/<domain>/`
|
||||
| compress | Brotli, Bzip2, Deflate, Explode, Lz4, Lzh, Lzma, Lzw, Lzx, PackBits, Quantum, UnixCompress, Xxh32, Zstd |
|
||||
| entropy | Huffman, RangeCoder |
|
||||
| font | Bitmap, Cff, GlyphNames, TrueType |
|
||||
| image | Bcn, Blend, Dct, Etc, Half, Jpeg, Pixels, Quantize, Raster, Texel, Texture, Vp8, Vp8L, Yuv |
|
||||
| model | Draco, Mat4, MeshFlatten, Minecraft, Polygon, Rbx, Rig, Sampler, Vrml |
|
||||
| text | Json, Nbt, Text, Url, Xml |
|
||||
| image | Bcn, Blend, Dct, Etc, Half, Jpeg, Miptex, Pixels, Quantize, Raster, Texel, Texture, Vp8, Vp8L, Yuv |
|
||||
| model | Brush, Displacement, DoomMap, Draco, Mat4, MeshFlatten, Minecraft, Patch, Polygon, Rbx, Rig, Sampler, SourceAnim, Vrml |
|
||||
| text | GodotVariant, Json, KeyValues, Lexer, Nbt, Text, Url, Xml |
|
||||
| video | Dsp, H263, H264, Legacy, Mpeg1, Mpeg2, Theora, Video |
|
||||
| containers | Archive, AudioWrap, Avi, Chunks, Cpio, Demux, Ebml, Fat, Iso9660, IsoBmff, MacFile, MpegEs, MpegPs, MpegTs, Ogg, Riff, Tar, Zip |
|
||||
| containers | Archive, AudioWrap, Avi, Blend, Chunks, Cpio, Demux, Ebml, Fat, Iso9660, IsoBmff, MacFile, MpegEs, MpegPs, MpegTs, Ogg, Riff, Tar, Zip |
|
||||
<!-- codecs:end -->
|
||||
|
||||
## Licence
|
||||
|
||||
+32133
-3659
File diff suppressed because it is too large.
Load diff
+616
-537
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"Core_1": [[8, "src/Rosetta/init.luau"], [892, "src/Rosetta/Registry.luau"], [3301, "src/Rosetta/Types.luau"], [4414, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [5168, "src/Rosetta/codecs/image/Yuv.luau"], [5473, "src/Rosetta/codecs/model/Rbx/init.luau"], [5710, "src/Rosetta/codecs/video/Video/init.luau"], [6268, "src/Rosetta/containers/AudioWrap.luau"], [6778, "src/Rosetta/containers/Ogg/Mux.luau"], [6967, "src/Rosetta/core/Bytes.luau"], [7494, "src/Rosetta/core/Crc32.luau"], [7645, "src/Rosetta/core/Err.luau"], [7727, "src/Rosetta/core/Input.luau"], [7803, "src/Rosetta/host/init.luau"]],
|
||||
"Core_2": [[8, "src/Rosetta/ops/ImageOps/init.luau"], [656, "src/Rosetta/ops/ImageOps/Kernels.luau"]],
|
||||
"Mpeg2": [[8, "src/Rosetta/codecs/video/Dsp.luau"], [846, "src/Rosetta/codecs/video/Mpeg1/init.luau"], [859, "src/Rosetta/codecs/video/Mpeg2/init.luau"], [1227, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], [2754, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], [2894, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"]],
|
||||
"H263": [[8, "src/Rosetta/codecs/video/H263/init.luau"], [165, "src/Rosetta/codecs/video/H263/Decoder.luau"], [1023, "src/Rosetta/codecs/video/H263/Tables.luau"]],
|
||||
"H264": [[8, "src/Rosetta/codecs/video/H264/init.luau"], [382, "src/Rosetta/codecs/video/H264/Bitstream.luau"], [657, "src/Rosetta/codecs/video/H264/Cabac.luau"], [1788, "src/Rosetta/codecs/video/H264/Cavlc.luau"], [2556, "src/Rosetta/codecs/video/H264/Deblock.luau"], [2818, "src/Rosetta/codecs/video/H264/Decoder.luau"], [3828, "src/Rosetta/codecs/video/H264/Inter.luau"], [4154, "src/Rosetta/codecs/video/H264/Intra.luau"], [4561, "src/Rosetta/codecs/video/H264/Mb.luau"], [5500, "src/Rosetta/codecs/video/H264/Params.luau"], [5948, "src/Rosetta/codecs/video/H264/Slice.luau"], [6200, "src/Rosetta/codecs/video/H264/Tables.luau"], [6242, "src/Rosetta/codecs/video/H264/Transform.luau"]],
|
||||
"Theora": [[8, "src/Rosetta/codecs/video/Theora/init.luau"], [272, "src/Rosetta/codecs/video/Theora/Decoder.luau"], [1536, "src/Rosetta/codecs/video/Theora/Header.luau"]],
|
||||
"Legacy": [[8, "src/Rosetta/codecs/video/Legacy/init.luau"], [207, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], [504, "src/Rosetta/codecs/video/Legacy/Flic.luau"], [871, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], [989, "src/Rosetta/codecs/video/Legacy/Picture.luau"], [1097, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], [1370, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], [1765, "src/Rosetta/codecs/video/Legacy/Smc.luau"]],
|
||||
"MpegTs": [[8, "src/Rosetta/containers/MpegEs.luau"], [175, "src/Rosetta/containers/MpegPs/init.luau"], [396, "src/Rosetta/containers/MpegTs/init.luau"]],
|
||||
"Dct": [[8, "src/Rosetta/codecs/image/Dct/init.luau"]],
|
||||
"Jpeg": [[8, "src/Rosetta/codecs/image/Jpeg/init.luau"], [362, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], [770, "src/Rosetta/codecs/image/Jpeg/Color.luau"], [1135, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], [1900, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], [2781, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], [3250, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], [3328, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"]],
|
||||
"Vp8": [[8, "src/Rosetta/codecs/image/Vp8/init.luau"], [139, "src/Rosetta/codecs/image/Vp8/Decode.luau"], [2095, "src/Rosetta/codecs/image/Vp8/Predict.luau"], [2358, "src/Rosetta/codecs/image/Vp8/Tables.luau"], [2608, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], [2750, "src/Rosetta/codecs/image/Vp8L/init.luau"], [2854, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], [3794, "src/Rosetta/codecs/image/Vp8L/Encode.luau"]],
|
||||
"Bcn": [[8, "src/Rosetta/codecs/image/Bcn/init.luau"], [115, "src/Rosetta/codecs/image/Bcn/Decode.luau"], [599, "src/Rosetta/codecs/image/Bcn/Encode.luau"]],
|
||||
"Png": [[8, "src/Rosetta/image/png/init.luau"], [588, "src/Rosetta/image/png/Apng.luau"], [668, "src/Rosetta/image/png/Decode.luau"], [1041, "src/Rosetta/image/png/Encode.luau"]],
|
||||
"Deflate": [[8, "src/Rosetta/codecs/compress/Deflate/init.luau"], [334, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], [816, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"]],
|
||||
"Brotli": [[8, "src/Rosetta/codecs/compress/Brotli/init.luau"], [95, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], [1071, "src/Rosetta/codecs/compress/Brotli/Static.luau"]],
|
||||
"Lzma": [[8, "src/Rosetta/codecs/compress/Lzma/init.luau"], [548, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], [615, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], [1088, "src/Rosetta/codecs/compress/Lzma/Filters.luau"]],
|
||||
"Zstd": [[8, "src/Rosetta/codecs/compress/Zstd/init.luau"], [65, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], [1049, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"]],
|
||||
"Mpa": [[8, "src/Rosetta/codecs/audio/Mpa/init.luau"], [23, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], [82, "src/Rosetta/codecs/audio/Mpa/Core.luau"], [1740, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], [2033, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], [2418, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], [3059, "src/Rosetta/codecs/audio/Mpa/Header.luau"], [3200, "src/Rosetta/codecs/audio/Mpa/Tables.luau"]],
|
||||
"Opus": [[8, "src/Rosetta/codecs/audio/Opus/init.luau"], [23, "src/Rosetta/codecs/audio/Opus/Celt.luau"], [1895, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], [2960, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], [3021, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], [3485, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], [3836, "src/Rosetta/codecs/audio/Opus/Packet.luau"], [4069, "src/Rosetta/codecs/audio/Opus/Silk.luau"], [6111, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"]],
|
||||
"Vorbis": [[8, "src/Rosetta/codecs/audio/Vorbis/init.luau"], [22, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], [406, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], [979, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], [1401, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"]],
|
||||
"Aac": [[8, "src/Rosetta/codecs/audio/Aac/init.luau"], [416, "src/Rosetta/codecs/audio/Aac/Decode.luau"], [1392, "src/Rosetta/codecs/audio/Aac/Ps.luau"], [1982, "src/Rosetta/codecs/audio/Aac/Sbr.luau"], [3049, "src/Rosetta/codecs/audio/Aac/SbrBits.luau"], [3168, "src/Rosetta/codecs/audio/Aac/SbrDct.luau"], [4410, "src/Rosetta/codecs/audio/Aac/SbrHf.luau"], [4902, "src/Rosetta/codecs/audio/Aac/SbrQmf.luau"], [5019, "src/Rosetta/codecs/audio/Aac/SbrTables.luau"], [5432, "src/Rosetta/codecs/audio/Aac/Tables.luau"]],
|
||||
"Flac": [[8, "src/Rosetta/codecs/audio/Flac/init.luau"], [20, "src/Rosetta/codecs/audio/Flac/Encode.luau"], [969, "src/Rosetta/codecs/audio/Flac/Frame.luau"]],
|
||||
"Musepack": [[8, "src/Rosetta/codecs/audio/Musepack/init.luau"], [354, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], [1248, "src/Rosetta/codecs/audio/Musepack/Tables.luau"]],
|
||||
"WavPack": [[8, "src/Rosetta/codecs/audio/WavPack/init.luau"], [231, "src/Rosetta/codecs/audio/WavPack/Block.luau"], [1686, "src/Rosetta/codecs/audio/WavPack/Tables.luau"]],
|
||||
"Tracker": [[8, "src/Rosetta/codecs/audio/Tracker/init.luau"], [491, "src/Rosetta/codecs/audio/Tracker/Load.luau"], [770, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], [1017, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], [1146, "src/Rosetta/codecs/audio/Tracker/Player.luau"], [3135, "src/Rosetta/codecs/audio/Tracker/Tables.luau"]],
|
||||
"Hively": [[8, "src/Rosetta/codecs/audio/Hively/init.luau"], [205, "src/Rosetta/codecs/audio/Hively/Load.luau"], [455, "src/Rosetta/codecs/audio/Hively/Player.luau"], [1414, "src/Rosetta/codecs/audio/Hively/Tables.luau"]],
|
||||
"SoundFont": [[8, "src/Rosetta/codecs/audio/SoundFont/init.luau"], [63, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], [207, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], [721, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"]],
|
||||
"Draco": [[8, "src/Rosetta/codecs/model/Draco/init.luau"], [340, "src/Rosetta/codecs/model/Draco/Attributes.luau"], [809, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], [1998, "src/Rosetta/codecs/model/Draco/Int64.luau"], [2147, "src/Rosetta/codecs/model/Draco/KdTree.luau"], [2506, "src/Rosetta/codecs/model/Draco/Predict.luau"], [3468, "src/Rosetta/codecs/model/Draco/Reader.luau"]],
|
||||
"archive_1": [[8, "src/Rosetta/archive/7z/init.luau"], [393, "src/Rosetta/archive/7z/Header.luau"], [920, "src/Rosetta/archive/adf/init.luau"], [1202, "src/Rosetta/archive/applesingle/init.luau"], [1388, "src/Rosetta/archive/ar/init.luau"], [1791, "src/Rosetta/archive/arj/init.luau"], [2001, "src/Rosetta/archive/binhex/init.luau"], [2250, "src/Rosetta/archive/br/init.luau"], [2325, "src/Rosetta/archive/bz2/init.luau"], [2389, "src/Rosetta/archive/cab/init.luau"], [2802, "src/Rosetta/archive/cab/Sum.luau"], [2843, "src/Rosetta/archive/cpio/init.luau"], [3011, "src/Rosetta/archive/d64/init.luau"], [3425, "src/Rosetta/archive/fat/init.luau"], [3547, "src/Rosetta/archive/grp/init.luau"], [3661, "src/Rosetta/archive/gzip/init.luau"], [3846, "src/Rosetta/archive/iso/init.luau"], [3918, "src/Rosetta/archive/lha/init.luau"], [4343, "src/Rosetta/archive/lz4/init.luau"], [4687, "src/Rosetta/archive/macbinary/init.luau"], [4885, "src/Rosetta/archive/mpq/init.luau"], [5291, "src/Rosetta/archive/mpq/Crypt.luau"], [5356, "src/Rosetta/archive/pak/init.luau"], [5490, "src/Rosetta/archive/rpm/init.luau"], [5814, "src/Rosetta/archive/tar/init.luau"], [5932, "src/Rosetta/archive/unitypackage/init.luau"], [6168, "src/Rosetta/archive/uu/init.luau"], [6438, "src/Rosetta/archive/vpk/init.luau"], [6749, "src/Rosetta/archive/vswap/init.luau"], [7019, "src/Rosetta/archive/wad/init.luau"], [7473, "src/Rosetta/archive/wad/Picture.luau"], [7575, "src/Rosetta/archive/wad2/init.luau"], [7857, "src/Rosetta/archive/xz/init.luau"]],
|
||||
"archive_2": [[8, "src/Rosetta/archive/yenc/init.luau"], [280, "src/Rosetta/archive/z/init.luau"], [376, "src/Rosetta/archive/zip/init.luau"], [595, "src/Rosetta/archive/zoo/init.luau"], [791, "src/Rosetta/archive/zst/init.luau"]],
|
||||
"audio": [[8, "src/Rosetta/audio/aac/init.luau"], [221, "src/Rosetta/audio/ac3/init.luau"], [368, "src/Rosetta/audio/adpcm/init.luau"], [514, "src/Rosetta/audio/adx/init.luau"], [746, "src/Rosetta/audio/aiff/init.luau"], [1138, "src/Rosetta/audio/ape/init.luau"], [1267, "src/Rosetta/audio/au/init.luau"], [1429, "src/Rosetta/audio/brstm/init.luau"], [1721, "src/Rosetta/audio/caf/init.luau"], [2388, "src/Rosetta/audio/flac/init.luau"], [2537, "src/Rosetta/audio/flac/Meta.luau"], [2759, "src/Rosetta/audio/flac/Stream.luau"], [3129, "src/Rosetta/audio/m4a/init.luau"], [3472, "src/Rosetta/audio/mp3/init.luau"], [3733, "src/Rosetta/audio/mp3/Index.luau"], [3924, "src/Rosetta/audio/mp3/Stream.luau"], [4151, "src/Rosetta/audio/mp3/Tags.luau"], [4463, "src/Rosetta/audio/mpc/init.luau"], [4558, "src/Rosetta/audio/opus/init.luau"], [4937, "src/Rosetta/audio/opus/Encode.luau"], [5049, "src/Rosetta/audio/qoa/init.luau"], [5230, "src/Rosetta/audio/tta/init.luau"], [5349, "src/Rosetta/audio/vag/init.luau"], [5573, "src/Rosetta/audio/voc/init.luau"], [5849, "src/Rosetta/audio/vorbis/init.luau"], [6304, "src/Rosetta/audio/vorbis/Encode.luau"], [7117, "src/Rosetta/audio/wav/init.luau"], [7738, "src/Rosetta/audio/wav/Codecs.luau"], [7917, "src/Rosetta/audio/wavpack/init.luau"]],
|
||||
"cad": [[8, "src/Rosetta/cad/step/init.luau"], [390, "src/Rosetta/cad/step/Brep.luau"], [625, "src/Rosetta/cad/step/Parse.luau"], [1182, "src/Rosetta/cad/step/Write.luau"]],
|
||||
"codecs_audio": [[8, "src/Rosetta/codecs/audio/Ac3/init.luau"], [168, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], [1053, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], [1155, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], [1458, "src/Rosetta/codecs/audio/Alac/init.luau"], [1693, "src/Rosetta/codecs/audio/Alac/Decode.luau"], [2112, "src/Rosetta/codecs/audio/Alac/Encode.luau"], [2524, "src/Rosetta/codecs/audio/Ape/init.luau"], [2740, "src/Rosetta/codecs/audio/Ape/Decode.luau"], [3501, "src/Rosetta/codecs/audio/ApeTag.luau"], [3599, "src/Rosetta/codecs/audio/Mdct/init.luau"], [3819, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], [4073, "src/Rosetta/codecs/audio/MidiRender.luau"], [4420, "src/Rosetta/codecs/audio/Pcm/init.luau"], [4684, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], [4981, "src/Rosetta/codecs/audio/Qoa/init.luau"], [5263, "src/Rosetta/codecs/audio/Resample/init.luau"], [5658, "src/Rosetta/codecs/audio/Stream.luau"], [5820, "src/Rosetta/codecs/audio/Tta/init.luau"], [5938, "src/Rosetta/codecs/audio/Tta/Decode.luau"], [6190, "src/Rosetta/codecs/audio/VorbisComment.luau"]],
|
||||
"codecs_compress": [[8, "src/Rosetta/codecs/compress/Bzip2/init.luau"], [52, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], [565, "src/Rosetta/codecs/compress/Explode.luau"], [761, "src/Rosetta/codecs/compress/Lz4.luau"], [1030, "src/Rosetta/codecs/compress/Lzh/init.luau"], [1634, "src/Rosetta/codecs/compress/Lzw/init.luau"], [1902, "src/Rosetta/codecs/compress/Lzx.luau"], [2336, "src/Rosetta/codecs/compress/PackBits.luau"], [2426, "src/Rosetta/codecs/compress/Quantum.luau"], [2663, "src/Rosetta/codecs/compress/UnixCompress.luau"], [2967, "src/Rosetta/codecs/compress/Xxh32.luau"]],
|
||||
"codecs_entropy": [[8, "src/Rosetta/codecs/entropy/Huffman.luau"], [295, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], [306, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], [527, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"]],
|
||||
"codecs_font": [[8, "src/Rosetta/codecs/font/Bitmap.luau"], [209, "src/Rosetta/codecs/font/Cff/init.luau"], [850, "src/Rosetta/codecs/font/GlyphNames.luau"], [1000, "src/Rosetta/codecs/font/TrueType/init.luau"], [1314, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], [1706, "src/Rosetta/codecs/font/TrueType/Tables.luau"]],
|
||||
"codecs_image": [[8, "src/Rosetta/codecs/image/Blend.luau"], [387, "src/Rosetta/codecs/image/Etc.luau"], [685, "src/Rosetta/codecs/image/Half.luau"], [754, "src/Rosetta/codecs/image/Miptex.luau"], [1054, "src/Rosetta/codecs/image/Pixels.luau"], [1374, "src/Rosetta/codecs/image/Quantize/init.luau"], [1835, "src/Rosetta/codecs/image/Raster.luau"], [2532, "src/Rosetta/codecs/image/Texel.luau"], [2905, "src/Rosetta/codecs/image/Texture.luau"]],
|
||||
"codecs_model": [[8, "src/Rosetta/codecs/model/Brush.luau"], [648, "src/Rosetta/codecs/model/Displacement.luau"], [797, "src/Rosetta/codecs/model/DoomMap/init.luau"], [1242, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], [1492, "src/Rosetta/codecs/model/Mat4.luau"], [1751, "src/Rosetta/codecs/model/MeshFlatten.luau"], [2279, "src/Rosetta/codecs/model/Minecraft/init.luau"], [2831, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], [2910, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], [3017, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], [3223, "src/Rosetta/codecs/model/Patch.luau"], [3347, "src/Rosetta/codecs/model/Polygon.luau"], [3581, "src/Rosetta/codecs/model/Rbx/Binary.luau"], [4335, "src/Rosetta/codecs/model/Rig.luau"], [4578, "src/Rosetta/codecs/model/Sampler.luau"], [4738, "src/Rosetta/codecs/model/SourceAnim.luau"], [4959, "src/Rosetta/codecs/model/Vrml/init.luau"], [5107, "src/Rosetta/codecs/model/Vrml/Build.luau"], [5681, "src/Rosetta/codecs/model/Vrml/Fields.luau"], [5844, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], [6593, "src/Rosetta/codecs/model/Vrml/Parse.luau"], [7115, "src/Rosetta/codecs/model/Vrml/Write.luau"], [7842, "src/Rosetta/codecs/model/Vrml/Xml.luau"]],
|
||||
"codecs_text": [[8, "src/Rosetta/codecs/text/GodotVariant.luau"], [667, "src/Rosetta/codecs/text/Json/init.luau"], [936, "src/Rosetta/codecs/text/Json/Decode.luau"], [1371, "src/Rosetta/codecs/text/Json/Encode.luau"], [1716, "src/Rosetta/codecs/text/KeyValues/init.luau"], [2286, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [2592, "src/Rosetta/codecs/text/Lexer/init.luau"], [2724, "src/Rosetta/codecs/text/Nbt/init.luau"], [3077, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [3769, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [4409, "src/Rosetta/codecs/text/Nbt/Value.luau"], [4647, "src/Rosetta/codecs/text/Text/init.luau"], [4738, "src/Rosetta/codecs/text/Url/init.luau"], [4943, "src/Rosetta/codecs/text/Xml/init.luau"], [5393, "src/Rosetta/codecs/text/Xml/Parse.luau"]],
|
||||
"codecs_video": [[8, "src/Rosetta/codecs/video/Video/Source.luau"]],
|
||||
"containers": [[8, "src/Rosetta/containers/Archive.luau"], [275, "src/Rosetta/containers/Avi/init.luau"], [828, "src/Rosetta/containers/Blend.luau"], [1567, "src/Rosetta/containers/Chunks.luau"], [1702, "src/Rosetta/containers/Cpio.luau"], [2130, "src/Rosetta/containers/Demux.luau"], [2405, "src/Rosetta/containers/Ebml/init.luau"], [2719, "src/Rosetta/containers/Fat.luau"], [3407, "src/Rosetta/containers/Iso9660.luau"], [3912, "src/Rosetta/containers/IsoBmff/init.luau"], [4083, "src/Rosetta/containers/IsoBmff/Box.luau"], [4272, "src/Rosetta/containers/IsoBmff/Demux.luau"], [5118, "src/Rosetta/containers/IsoBmff/Meta.luau"], [5640, "src/Rosetta/containers/IsoBmff/Mux.luau"], [6157, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], [6275, "src/Rosetta/containers/MacFile.luau"], [6424, "src/Rosetta/containers/Ogg/init.luau"], [6849, "src/Rosetta/containers/Ogg/Page.luau"], [7015, "src/Rosetta/containers/Riff/init.luau"], [7332, "src/Rosetta/containers/Tar.luau"], [7746, "src/Rosetta/containers/Zip/init.luau"]],
|
||||
"core": [[8, "src/Rosetta/core/Adler32.luau"], [68, "src/Rosetta/core/Base64.luau"], [296, "src/Rosetta/core/Bits.luau"], [589, "src/Rosetta/core/Crc16.luau"], [641, "src/Rosetta/core/Md5.luau"], [799, "src/Rosetta/core/Sniff.luau"]],
|
||||
"data": [[8, "src/Rosetta/data/cbor/init.luau"], [107, "src/Rosetta/data/cbor/Codec.luau"], [676, "src/Rosetta/data/csv/init.luau"], [988, "src/Rosetta/data/ini/init.luau"], [1234, "src/Rosetta/data/json/init.luau"], [1326, "src/Rosetta/data/msgpack/init.luau"], [1415, "src/Rosetta/data/msgpack/Codec.luau"], [1857, "src/Rosetta/data/nbt/init.luau"], [1916, "src/Rosetta/data/plist/init.luau"], [2222, "src/Rosetta/data/plist/Binary.luau"], [2489, "src/Rosetta/data/q3shader/init.luau"], [2728, "src/Rosetta/data/q3skin/init.luau"], [2824, "src/Rosetta/data/snbt/init.luau"], [2887, "src/Rosetta/data/toml/init.luau"], [2954, "src/Rosetta/data/toml/Decode.luau"], [3582, "src/Rosetta/data/toml/Encode.luau"], [3791, "src/Rosetta/data/tres/init.luau"], [3936, "src/Rosetta/data/vdf/init.luau"], [4037, "src/Rosetta/data/xml/init.luau"], [4093, "src/Rosetta/data/yaml/init.luau"], [4166, "src/Rosetta/data/yaml/Emit.luau"], [4456, "src/Rosetta/data/yaml/Parse.luau"]],
|
||||
"font": [[8, "src/Rosetta/font/bdf/init.luau"], [297, "src/Rosetta/font/bmfont/init.luau"], [724, "src/Rosetta/font/bmfont/Parse.luau"], [1177, "src/Rosetta/font/eot/init.luau"], [1409, "src/Rosetta/font/fon/init.luau"], [1692, "src/Rosetta/font/hershey/init.luau"], [1887, "src/Rosetta/font/pcf/init.luau"], [2167, "src/Rosetta/font/psf/init.luau"], [2487, "src/Rosetta/font/ttf/init.luau"], [2538, "src/Rosetta/font/type1/init.luau"], [2897, "src/Rosetta/font/type1/Charstring.luau"], [3175, "src/Rosetta/font/woff/init.luau"], [3307, "src/Rosetta/font/woff2/init.luau"], [3364, "src/Rosetta/font/woff2/Rebuild.luau"]],
|
||||
"host": [[8, "src/Rosetta/host/Love.luau"], [151, "src/Rosetta/host/LuaJIT.luau"], [201, "src/Rosetta/host/Luau.luau"], [224, "src/Rosetta/host/Roblox.luau"]],
|
||||
"image_1": [[8, "src/Rosetta/image/ani/init.luau"], [188, "src/Rosetta/image/art/init.luau"], [676, "src/Rosetta/image/blp/init.luau"], [934, "src/Rosetta/image/bmp/init.luau"], [1349, "src/Rosetta/image/dds/init.luau"], [1832, "src/Rosetta/image/exr/init.luau"], [2592, "src/Rosetta/image/exr/Codec.luau"], [2703, "src/Rosetta/image/exr/Piz.luau"], [3060, "src/Rosetta/image/gif/init.luau"], [3576, "src/Rosetta/image/gif/Decode.luau"], [3652, "src/Rosetta/image/hdr/init.luau"], [3881, "src/Rosetta/image/hdr/Codec.luau"], [4092, "src/Rosetta/image/icns/init.luau"], [4423, "src/Rosetta/image/ico/init.luau"], [4700, "src/Rosetta/image/ico/Dib.luau"], [4795, "src/Rosetta/image/ilbm/init.luau"], [5114, "src/Rosetta/image/jpeg/init.luau"], [5250, "src/Rosetta/image/ktx/init.luau"], [5910, "src/Rosetta/image/lmp/init.luau"], [6043, "src/Rosetta/image/pcx/init.luau"], [6307, "src/Rosetta/image/pnm/init.luau"], [6685, "src/Rosetta/image/pnm/Codec.luau"], [6962, "src/Rosetta/image/qoi/init.luau"], [7084, "src/Rosetta/image/qoi/Codec.luau"], [7241, "src/Rosetta/image/sgi/init.luau"], [7526, "src/Rosetta/image/spr/init.luau"]],
|
||||
"image_2": [[8, "src/Rosetta/image/sunras/init.luau"], [254, "src/Rosetta/image/tga/init.luau"], [524, "src/Rosetta/image/tga/Codec.luau"], [724, "src/Rosetta/image/tiff/init.luau"], [1551, "src/Rosetta/image/tiff/Pixels.luau"], [1941, "src/Rosetta/image/tim/init.luau"], [2183, "src/Rosetta/image/vtf/init.luau"], [2418, "src/Rosetta/image/webp/init.luau"], [3028, "src/Rosetta/image/webp/Alpha.luau"], [3104, "src/Rosetta/image/webp/Anim.luau"], [3259, "src/Rosetta/image/xbm/init.luau"], [3420, "src/Rosetta/image/xpm/init.luau"], [3688, "src/Rosetta/image/xpm/Names.luau"]],
|
||||
"layered": [[8, "src/Rosetta/layered/aseprite/init.luau"], [746, "src/Rosetta/layered/ora/init.luau"], [1033, "src/Rosetta/layered/psd/init.luau"], [1768, "src/Rosetta/layered/psd/Channels.luau"]],
|
||||
"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/ase/init.luau"], [3237, "src/Rosetta/model/ase/Build.luau"], [3811, "src/Rosetta/model/ase/Parse.luau"], [3880, "src/Rosetta/model/ase/Write.luau"], [4343, "src/Rosetta/model/b3d/init.luau"], [4398, "src/Rosetta/model/b3d/Read.luau"], [4969, "src/Rosetta/model/blend/init.luau"], [5065, "src/Rosetta/model/blend/Anim.luau"], [5411, "src/Rosetta/model/blend/Material.luau"], [5763, "src/Rosetta/model/blend/Mesh.luau"], [6398, "src/Rosetta/model/blend/Normals.luau"], [6559, "src/Rosetta/model/blend/Prim.luau"]],
|
||||
"model_2": [[8, "src/Rosetta/model/blend/Read.luau"], [908, "src/Rosetta/model/bsp/init.luau"], [1099, "src/Rosetta/model/bsp/Lightmap.luau"], [1165, "src/Rosetta/model/bsp/Quake.luau"], [1554, "src/Rosetta/model/bsp/Quake3.luau"], [1783, "src/Rosetta/model/bsp/Tree.luau"], [2171, "src/Rosetta/model/buildmap/init.luau"], [2443, "src/Rosetta/model/buildmap/Geometry.luau"], [2846, "src/Rosetta/model/d3map/init.luau"], [3128, "src/Rosetta/model/d3map/Parse.luau"], [3326, "src/Rosetta/model/dae/init.luau"], [3515, "src/Rosetta/model/dae/Math.luau"], [3562, "src/Rosetta/model/dae/Read.luau"], [5412, "src/Rosetta/model/dae/Write.luau"], [5781, "src/Rosetta/model/fbx/init.luau"], [5929, "src/Rosetta/model/fbx/Ascii.luau"], [6199, "src/Rosetta/model/fbx/Binary.luau"]],
|
||||
"model_3": [[8, "src/Rosetta/model/fbx/Read.luau"], [1370, "src/Rosetta/model/fbx/Write.luau"], [2355, "src/Rosetta/model/fbx/Xform.luau"], [2396, "src/Rosetta/model/gltf/init.luau"], [2633, "src/Rosetta/model/gltf/Pack.luau"], [2702, "src/Rosetta/model/gltf/Read.luau"], [3433, "src/Rosetta/model/gltf/Write.luau"], [4113, "src/Rosetta/model/godot/init.luau"], [4204, "src/Rosetta/model/godot/Build.luau"], [4746, "src/Rosetta/model/godot/Primitives.luau"], [5021, "src/Rosetta/model/godot/Surface.luau"], [5506, "src/Rosetta/model/godot/Write.luau"], [5835, "src/Rosetta/model/iqm/init.luau"], [5911, "src/Rosetta/model/iqm/Read.luau"], [6266, "src/Rosetta/model/iqm/Write.luau"], [6953, "src/Rosetta/model/ldraw/init.luau"], [7031, "src/Rosetta/model/ldraw/Colors.luau"]],
|
||||
"model_4": [[8, "src/Rosetta/model/ldraw/Read.luau"], [585, "src/Rosetta/model/lwo/init.luau"], [661, "src/Rosetta/model/lwo/Build.luau"], [1123, "src/Rosetta/model/lwo/Parse.luau"], [1666, "src/Rosetta/model/map/init.luau"], [1983, "src/Rosetta/model/map/Build.luau"], [2227, "src/Rosetta/model/map/Parse.luau"], [2612, "src/Rosetta/model/map/Write.luau"], [2758, "src/Rosetta/model/mca/init.luau"], [3100, "src/Rosetta/model/mca/Chunk.luau"], [3233, "src/Rosetta/model/mca/Lz4Block.luau"], [3303, "src/Rosetta/model/md2/init.luau"], [3502, "src/Rosetta/model/md3/init.luau"], [3730, "src/Rosetta/model/md5/init.luau"], [3811, "src/Rosetta/model/md5/Read.luau"], [4244, "src/Rosetta/model/mdl/init.luau"], [4326, "src/Rosetta/model/mdl/HalfLife.luau"], [4630, "src/Rosetta/model/mdl/Quake.luau"], [4848, "src/Rosetta/model/ms3d/init.luau"], [4920, "src/Rosetta/model/ms3d/Read.luau"], [5366, "src/Rosetta/model/ms3d/Write.luau"], [5835, "src/Rosetta/model/obj/init.luau"], [6653, "src/Rosetta/model/obj/Mtl.luau"], [6941, "src/Rosetta/model/off/init.luau"]],
|
||||
"model_5": [[8, "src/Rosetta/model/ply/init.luau"], [1113, "src/Rosetta/model/ply/Binary.luau"], [1314, "src/Rosetta/model/pmx/init.luau"], [1383, "src/Rosetta/model/pmx/Build.luau"], [1679, "src/Rosetta/model/pmx/Pmd.luau"], [2014, "src/Rosetta/model/pmx/Read.luau"], [2418, "src/Rosetta/model/proc/init.luau"], [2800, "src/Rosetta/model/qb/init.luau"], [3193, "src/Rosetta/model/rbxm/init.luau"], [3786, "src/Rosetta/model/rbxmx/init.luau"], [4462, "src/Rosetta/model/robloxmesh/init.luau"], [5121, "src/Rosetta/model/robloxmesh/Parse.luau"], [5578, "src/Rosetta/model/robloxmesh/Write.luau"], [5687, "src/Rosetta/model/schematic/init.luau"], [6008, "src/Rosetta/model/schematic/Common.luau"], [6128, "src/Rosetta/model/schematic/Litematic.luau"], [6339, "src/Rosetta/model/schematic/Mcedit.luau"], [6583, "src/Rosetta/model/schematic/Sponge.luau"], [6712, "src/Rosetta/model/smd/init.luau"], [6779, "src/Rosetta/model/smd/Read.luau"], [7048, "src/Rosetta/model/smd/Write.luau"], [7291, "src/Rosetta/model/sourcemdl/init.luau"], [7462, "src/Rosetta/model/sourcemdl/Build.luau"], [7892, "src/Rosetta/model/sourcemdl/Material.luau"]],
|
||||
"model_6": [[8, "src/Rosetta/model/sourcemdl/Mdl.luau"], [535, "src/Rosetta/model/sourcemdl/Phy.luau"], [658, "src/Rosetta/model/sourcemdl/Vtx.luau"], [840, "src/Rosetta/model/sourcemdl/Vvd.luau"], [934, "src/Rosetta/model/stl/init.luau"], [1384, "src/Rosetta/model/stl/Decode.luau"], [1458, "src/Rosetta/model/t3d/init.luau"], [1552, "src/Rosetta/model/t3d/Build.luau"], [1957, "src/Rosetta/model/t3d/Parse.luau"], [2125, "src/Rosetta/model/udmf/init.luau"], [2208, "src/Rosetta/model/usda/init.luau"], [2417, "src/Rosetta/model/usda/Build.luau"], [3695, "src/Rosetta/model/usda/Parse.luau"], [4493, "src/Rosetta/model/usda/Write.luau"], [5310, "src/Rosetta/model/vbsp/init.luau"], [5756, "src/Rosetta/model/vbsp/Faces.luau"], [5980, "src/Rosetta/model/vbsp/Props.luau"], [6072, "src/Rosetta/model/vmf/init.luau"], [6397, "src/Rosetta/model/vmf/Build.luau"], [6821, "src/Rosetta/model/vox/init.luau"], [7707, "src/Rosetta/model/vox/Grid.luau"], [7764, "src/Rosetta/model/vrml/init.luau"], [7830, "src/Rosetta/model/x/init.luau"]],
|
||||
"model_7": [[8, "src/Rosetta/model/x/Build.luau"], [571, "src/Rosetta/model/x/Parse.luau"], [868, "src/Rosetta/model/x3d/init.luau"]],
|
||||
"music": [[8, "src/Rosetta/music/669/init.luau"], [215, "src/Rosetta/music/ahx/init.luau"], [267, "src/Rosetta/music/far/init.luau"], [497, "src/Rosetta/music/hmp/init.luau"], [762, "src/Rosetta/music/hvl/init.luau"], [814, "src/Rosetta/music/it/init.luau"], [1233, "src/Rosetta/music/it/Itsex.luau"], [1350, "src/Rosetta/music/med/init.luau"], [1998, "src/Rosetta/music/midi/init.luau"], [2142, "src/Rosetta/music/midi/Smf.luau"], [2554, "src/Rosetta/music/mod/init.luau"], [2908, "src/Rosetta/music/mtm/init.luau"], [3131, "src/Rosetta/music/mus/init.luau"], [3289, "src/Rosetta/music/okt/init.luau"], [3571, "src/Rosetta/music/ptm/init.luau"], [3794, "src/Rosetta/music/s3m/init.luau"], [4031, "src/Rosetta/music/sf2/init.luau"], [4075, "src/Rosetta/music/stm/init.luau"], [4307, "src/Rosetta/music/ult/init.luau"], [4612, "src/Rosetta/music/umx/init.luau"], [4829, "src/Rosetta/music/xm/init.luau"], [5391, "src/Rosetta/music/xmi/init.luau"]],
|
||||
"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [487, "src/Rosetta/ops/LayerOps.luau"], [580, "src/Rosetta/ops/MeshOps/init.luau"], [1632, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1799, "src/Rosetta/ops/MusicOps.luau"]],
|
||||
"playlist": [[8, "src/Rosetta/playlist/m3u/init.luau"], [361, "src/Rosetta/playlist/pls/init.luau"], [539, "src/Rosetta/playlist/xspf/init.luau"]],
|
||||
"subtitle": [[8, "src/Rosetta/subtitle/ass/init.luau"], [452, "src/Rosetta/subtitle/srt/init.luau"], [625, "src/Rosetta/subtitle/vtt/init.luau"]],
|
||||
"vector": [[8, "src/Rosetta/vector/gamemaps/init.luau"], [195, "src/Rosetta/vector/gamemaps/Expand.luau"], [292, "src/Rosetta/vector/ldtk/init.luau"], [384, "src/Rosetta/vector/ldtk/Read.luau"], [720, "src/Rosetta/vector/ldtk/Write.luau"], [1368, "src/Rosetta/vector/ogmo/init.luau"], [1487, "src/Rosetta/vector/ogmo/Read.luau"], [1892, "src/Rosetta/vector/ogmo/Write.luau"], [2246, "src/Rosetta/vector/svg/init.luau"], [2332, "src/Rosetta/vector/svg/Parse.luau"], [3078, "src/Rosetta/vector/svg/PathData.luau"], [3446, "src/Rosetta/vector/svg/Render.luau"], [3863, "src/Rosetta/vector/svg/Style.luau"], [4235, "src/Rosetta/vector/svg/Write.luau"], [4435, "src/Rosetta/vector/tiled/init.luau"], [4615, "src/Rosetta/vector/tiled/Data.luau"], [4766, "src/Rosetta/vector/tiled/Tmj.luau"], [5397, "src/Rosetta/vector/tiled/Tmx.luau"]],
|
||||
"video": [[8, "src/Rosetta/video/avi/init.luau"], [302, "src/Rosetta/video/fli/init.luau"], [453, "src/Rosetta/video/flv/init.luau"], [837, "src/Rosetta/video/flv/Amf.luau"], [995, "src/Rosetta/video/flv/Mux.luau"], [1276, "src/Rosetta/video/h264/init.luau"], [1415, "src/Rosetta/video/mkv/init.luau"], [1571, "src/Rosetta/video/mkv/Mux.luau"], [1850, "src/Rosetta/video/mkv/Parse.luau"], [2571, "src/Rosetta/video/mp4/init.luau"], [2899, "src/Rosetta/video/mpegps/init.luau"], [3086, "src/Rosetta/video/mpegts/init.luau"], [3332, "src/Rosetta/video/ogv/init.luau"], [3727, "src/Rosetta/video/smk/init.luau"], [4036, "src/Rosetta/video/smk/Audio.luau"], [4156, "src/Rosetta/video/y4m/init.luau"]]
|
||||
}
|
||||
+221292
File diff suppressed because it is too large.
Load diff
+30227
-1749
File diff suppressed because it is too large.
Load diff
+616
-537
File diff suppressed because it is too large.
Load diff
+8
-2
@@ -462,9 +462,11 @@ do
|
||||
if x ~= x then return x end
|
||||
return mmin(mmax(x, lo), hi)
|
||||
end
|
||||
-- branch-free for the same reason (a data-dependent sign spawned side traces: WavPack's decorrelation 2x slower);
|
||||
-- x * 1e300 * 1e300 is +-inf or beyond +-1 for every non-zero x, 0 for 0; + 0 turns -0 into 0
|
||||
math.sign = math.sign or function(x)
|
||||
if x > 0 then return 1 elseif x < 0 then return -1 end
|
||||
return 0
|
||||
if x ~= x then return 0 end
|
||||
return mmin(mmax(x * 1e300 * 1e300, -1), 1) + 0
|
||||
end
|
||||
-- Luau rounds half away from zero
|
||||
math.round = math.round or function(x)
|
||||
@@ -573,6 +575,10 @@ do
|
||||
if j < 0 then j = #s + j + 1 end
|
||||
local n = 0
|
||||
while i <= j do
|
||||
local h = string.find(s, "[\128-\255]", i)
|
||||
if not h or h > j then return n + j - i + 1 end
|
||||
n = n + h - i
|
||||
i = h
|
||||
local c, l = dec(s, i)
|
||||
if not c then return nil, i end
|
||||
n = n + 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Rosetta",
|
||||
"tree": {
|
||||
"$path": "build/Rosetta.luau"
|
||||
"$path": "build/Rosetta.rbxm"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -45,7 +45,7 @@ VideoDecoder saved to an image format (`gif`, `apng`, `webp`) becomes an animate
|
||||
one category. Extras:
|
||||
|
||||
- `F.video.open(src, opts?)`: `opts.maxSide` shrinks the frames (longer side at most n pixels), `opts.yield` is a
|
||||
cooperative yield point for slow codecs (H.264; see the video guide), `opts.audio = false` skips the audio track.
|
||||
cooperative yield point for slow codecs (H.264; see the video guide), `opts.audio = false` skips the audio track, `opts.sbr = false` decodes only the AAC-LC core of an HE-AAC track.
|
||||
It also opens animated images (GIF / APNG / WebP) as videos; `F.video.fromImage(img)`,
|
||||
`F.video.fromFrames(images, delays?)` (an image sequence: `F.save(F.video.fromFrames(list, 1 / 25), "out.avi")`),
|
||||
`F.video.codecs` (the codec registry `codecs/video/Video`).
|
||||
|
||||
+37
-3
@@ -6,6 +6,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| Category | Format | Extensions | Read | Write | Capabilities | Test |
|
||||
|---|---|---|---|---|---|---|
|
||||
| image | ani | .ani | yes | yes | alpha: true, animation: true, frames: true | `tests/image/ani.luau` |
|
||||
| image | art | .art | yes | yes | alpha: true, palette: true, frames: true, depths: 8 | `tests/image/art.luau` |
|
||||
| image | blp | .blp | yes | yes | alpha: true, variants: "blp1", "blp2", compressions: "jpeg", "palette", "dxt1", "dxt3", "dxt5", "bgra" | `tests/image/blp.luau` |
|
||||
| image | bmp | .bmp .dib | yes | yes | alpha: true, depths: 1, 2, 4, 8, 16, 24, 32, rle: true | `tests/image/bmp.luau` |
|
||||
| image | dds | .dds | yes | yes | alpha: true, float: true, mipmaps: true, cubemap: true, compressed: "bc1", "bc2", "bc3", "bc4", "bc5", "bc6h", "bc7" | `tests/image/dds.luau` |
|
||||
@@ -17,11 +18,13 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| image | ilbm | .iff .ilbm .lbm .pbm | yes | yes | alpha: true, palette: true, depths: 1, 2, 3, 4, 5, 6, 7, 8, 24, 32 | `tests/image/ilbm.luau` |
|
||||
| image | jpeg | .jpg .jpeg .jpe .jfif | yes | yes | lossy: true, alpha: false, depths: 8, 12, progressive: true, arithmetic: true | `tests/image/jpeg.luau` |
|
||||
| image | ktx | .ktx2 .ktx | yes | yes | alpha: true, float: true, mipmaps: true, cubemap: true, compressed: "bc1", "bc2", "bc3", "bc4", "bc5", "bc6h", "bc7", "etc1", "etc2", "eac" | `tests/image/ktx.luau` |
|
||||
| image | lmp | .lmp | yes | yes | alpha: true, depths: 8, variants: "qpic", "palette", "colormap" | `tests/image/lmp.luau` |
|
||||
| image | pcx | .pcx .pcc .dcx | yes | yes | alpha: true, palette: true, depths: 1, 2, 4, 8, 24, 32 | `tests/image/pcx.luau` |
|
||||
| image | png | .png .apng | yes | yes | animation: true, alpha: true, depths: 1, 2, 4, 8, 16 | `tests/image/png.luau` |
|
||||
| image | pnm | .pnm .pbm .pgm .ppm .pam .pfm | yes | yes | alpha: true, depths: 1, 8, 16, 32, float: true | `tests/image/pnm.luau` |
|
||||
| image | qoi | .qoi | yes | yes | alpha: true, depths: 8 | `tests/image/qoi.luau` |
|
||||
| image | sgi | .sgi .rgb .rgba .bw .int .inta | yes | yes | alpha: true, depths: 8, 16 | `tests/image/sgi.luau` |
|
||||
| image | spr | .spr | yes | yes | alpha: true, animation: true, variants: "quake", "halflife", "spr32" | `tests/image/spr.luau` |
|
||||
| image | sunras | .ras .sun .rs .im1 .im8 .im24 .im32 | yes | yes | alpha: true, palette: true, depths: 1, 8, 24, 32 | `tests/image/sunras.luau` |
|
||||
| image | tga | .tga .icb .vda .vst .tpic | yes | yes | alpha: true, palette: true, depths: 8, 15, 16, 24, 32 | `tests/image/tga.luau` |
|
||||
| image | tiff | .tif .tiff | yes | yes | alpha: true, pages: true, depths: 1, 2, 4, 8, 16, 32, float: true | `tests/image/tiff.luau` |
|
||||
@@ -64,14 +67,20 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | `tests/video/y4m.luau` |
|
||||
| model | 3ds | .3ds | yes | yes | materials: true, textures: true, animation: true, cameras: true, lights: true, instancing: true | `tests/model/3ds.luau` |
|
||||
| model | 3mf | .3mf | yes | yes | materials: true, vertexColors: true, textures: true, units: true | `tests/model/3mf.luau` |
|
||||
| model | ase | .ase .ask | yes | yes | text: true, materials: true, cameras: true, lights: true, vertexColors: true | `tests/model/ase.luau` |
|
||||
| model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` |
|
||||
| model | bsp | .bsp | yes | - | variants: "quake", "halflife", "quake2", "quake3", lightmaps: "quake3" | `tests/model/bsp.luau` |
|
||||
| model | blend | .blend | yes | - | materials: true, textures: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true, compressed: true | `tests/model/blend.luau` |
|
||||
| model | bsp | .bsp | yes | - | variants: "quake", "bsp2", "2psb", "halflife", "quake2", "quake3", lightmaps: true, collision: true, visibility: true | `tests/model/bsp.luau` |
|
||||
| model | buildmap | .map | yes | yes | sprites: true, slopes: true | `tests/model/buildmap.luau` |
|
||||
| model | d3map | .map | yes | - | patches: true, variants: "doom3", "quake4" | `tests/model/d3map.luau` |
|
||||
| model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` |
|
||||
| model | fbx | .fbx | yes | yes | binary: true, ascii: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true | `tests/model/fbx.luau` |
|
||||
| model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, draco: true | `tests/model/gltf.luau` |
|
||||
| model | godot | .tscn .escn | yes | yes | text: true, materials: true, cameras: true, lights: true, instances: true | `tests/model/godot.luau` |
|
||||
| model | iqm | .iqm | yes | yes | materials: true, skins: true, animation: true, vertexColors: true | `tests/model/iqm.luau` |
|
||||
| model | ldraw | .ldr .mpd .dat | yes | - | materials: true, lines: true, instancing: true | `tests/model/ldraw.luau` |
|
||||
| model | lwo | .lwo .lxo | yes | - | materials: true, polygons: true, vertexColors: true, morphTargets: true | `tests/model/lwo.luau` |
|
||||
| model | map | .map | yes | yes | variants: "quake", "valve220", "quake2", "quake3", patches: true | `tests/model/map.luau` |
|
||||
| model | mca | .mca .mcr | yes | - | voxels: true, blocks: true | `tests/model/mca.luau` |
|
||||
| model | md2 | .md2 | yes | - | morph: true, animation: true | `tests/model/md2.luau` |
|
||||
| model | md3 | .md3 | yes | - | morph: true, animation: true, tags: true | `tests/model/md3.luau` |
|
||||
@@ -82,14 +91,20 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| model | off | .off | yes | yes | polygons: true, points: true, colors: true, binary: false | `tests/model/off.luau` |
|
||||
| model | ply | .ply | yes | yes | ascii: true, binary: true, polygons: true, points: true, colors: true | `tests/model/ply.luau` |
|
||||
| model | pmx | .pmx .pmd | yes | - | materials: true, skins: true, morphTargets: true, pmd: true | `tests/model/pmx.luau` |
|
||||
| model | proc | .proc | yes | - | portals: true | `tests/model/proc.luau` |
|
||||
| model | qb | .qb | yes | yes | voxels: true, truecolor: true | `tests/model/qb.luau` |
|
||||
| model | rbxm | .rbxm .rbxl | yes | yes | tree: true, compression: "none", "lz4", "zstd" | `tests/model/rbxm.luau` |
|
||||
| model | rbxmx | .rbxmx .rbxlx | yes | yes | tree: true | `tests/model/rbxmx.luau` |
|
||||
| model | robloxmesh | .mesh | yes | yes | skinning: true, lods: true, versions: "1.00", "1.01", "2.00", "3.00", "3.01", "4.00", "4.01", "5.00", "6.00", "7.00" | `tests/model/robloxmesh.luau` |
|
||||
| model | schematic | .schem .schematic .litematic | yes | yes | voxels: true, blocks: true, variants: "schem", "schematic", "litematic" | `tests/model/schematic.luau` |
|
||||
| model | smd | .smd | yes | yes | skins: true, animation: true | `tests/model/smd.luau` |
|
||||
| model | sourcemdl | .mdl | yes | - | skins: true, morph: true, animation: true, lods: true | `tests/model/sourcemdl.luau` |
|
||||
| model | stl | .stl | yes | yes | ascii: true, binary: true, colors: true, indexed: false | `tests/model/stl.luau` |
|
||||
| model | t3d | .t3d | yes | - | text: true, brushes: true, actors: true | `tests/model/t3d.luau` |
|
||||
| model | udmf | .udmf .textmap | yes | - | maps: true | `tests/model/udmf.luau` |
|
||||
| model | usda | .usda .usd .usdz | yes | yes | materials: true, animation: true, cameras: true, lights: true, polygons: true, vertexColors: true, usdz: "read", usdc: false | `tests/model/usda.luau` |
|
||||
| model | vbsp | .bsp | yes | - | versions: 19, 20, 21, displacements: true, staticProps: true, pak: true | `tests/model/vbsp.luau` |
|
||||
| model | vmf | .vmf .vmx | yes | yes | displacements: true, roundTrip: true | `tests/model/vmf.luau` |
|
||||
| model | vox | .vox | yes | yes | voxels: true, sceneGraph: true, materials: true | `tests/model/vox.luau` |
|
||||
| model | vrml | .wrl .wrz .vrml | yes | yes | materials: true, polygons: true, animation: true, cameras: true, lights: true, lines: true, points: true | `tests/model/vrml.luau` |
|
||||
| model | x | .x | yes | - | text: true, binary: true, compressed: true, materials: true, skins: true, animation: true, polygons: true, vertexColors: true | `tests/model/x.luau` |
|
||||
@@ -128,9 +143,12 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| archive | pak | .pak .sin | yes | yes | variants: "quake", "sin" | `tests/archive/pak.luau` |
|
||||
| archive | rpm | .rpm | yes | - | compressors: "gzip", "bzip2", "xz", "lzma", "zstd" | `tests/archive/rpm.luau` |
|
||||
| archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` |
|
||||
| archive | unitypackage | .unitypackage | yes | yes | | `tests/archive/unitypackage.luau` |
|
||||
| archive | uu | .uu .uue .xxe .b64 | yes | yes | variants: "uu", "xx", "base64" | `tests/archive/uu.luau` |
|
||||
| archive | vpk | .vpk | yes | yes | versions: 1, 2, multipart: true | `tests/archive/vpk.luau` |
|
||||
| archive | vswap | .wl6 .wl1 .sod .sdm .vswap | yes | - | images: true, sounds: true | `tests/archive/vswap.luau` |
|
||||
| archive | wad | .wad | yes | yes | images: true, maps: true, variants: "iwad", "pwad" | `tests/archive/wad.luau` |
|
||||
| archive | wad2 | .wad | yes | yes | images: true, variants: "wad2", "wad3" | `tests/archive/wad2.luau` |
|
||||
| archive | xz | .xz .txz .lzma | yes | - | stream: true, filters: "lzma2", "lzma", "delta", "x86", "powerpc", "arm", "armthumb", "sparc", "arm64" | `tests/archive/xz.luau` |
|
||||
| archive | yenc | .yenc .ync | yes | yes | multipart: true | `tests/archive/yenc.luau` |
|
||||
| archive | z | .z .taz .tz | yes | yes | stream: true, bits: 9, 16 | `tests/archive/z.luau` |
|
||||
@@ -144,10 +162,17 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| data | msgpack | .msgpack .mpk | yes | yes | binary: true, ordered: true | `tests/data/msgpack.luau` |
|
||||
| data | nbt | .nbt .dat .mcstructure .dat_old | yes | yes | binary: true, ordered: true, typed: true | `tests/data/nbt.luau` |
|
||||
| data | plist | .plist | yes | yes | binary: "read", ordered: true | `tests/data/plist.luau` |
|
||||
| data | q3shader | .shader | yes | yes | | `tests/data/q3shader.luau` |
|
||||
| data | q3skin | .skin | yes | yes | | `tests/data/q3skin.luau` |
|
||||
| data | snbt | .snbt | yes | yes | ordered: true, typed: true | `tests/data/snbt.luau` |
|
||||
| data | toml | .toml | yes | yes | ordered: true, dates: true | `tests/data/toml.luau` |
|
||||
| data | tres | .tres | yes | yes | ordered: true | `tests/data/tres.luau` |
|
||||
| data | vdf | .vdf .acf .res .kv | yes | yes | ordered: true, binary: true | `tests/data/vdf.luau` |
|
||||
| data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` |
|
||||
| data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` |
|
||||
| vector | gamemaps | .wl6 .wl1 .sod .sdm | yes | - | tilemap: true | `tests/vector/gamemaps.luau` |
|
||||
| vector | ldtk | .ldtk | yes | yes | levels: true, worlds: true, intGrid: true, entities: true | `tests/vector/ldtk.luau` |
|
||||
| vector | ogmo | .ogmo | yes | yes | projects: true, entities: true, decals: true | `tests/vector/ogmo.luau` |
|
||||
| vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` |
|
||||
| vector | tiled | .tmx .tmj .tsx .tsj | yes | yes | tilesets: true, infinite: true | `tests/vector/tiled.luau` |
|
||||
| layered | aseprite | .aseprite .ase | yes | yes | layers: true, groups: true, animation: true, depths: 8, 16, 32 | `tests/layered/aseprite.luau` |
|
||||
@@ -183,7 +208,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
|
||||
- **audio**
|
||||
- codecs/audio/Aac: AAC-LC decoder (ISO/IEC 14496-3 subpart 4, ISO/IEC 13818-7): AudioSpecificConfig, ADTS, raw_data_block.
|
||||
- codecs/audio/Aac: AAC-LC decoder (ISO/IEC 14496-3 subpart 4, ISO/IEC 13818-7): AudioSpecificConfig, ADTS, raw_data_block;
|
||||
- codecs/audio/Ac3: AC-3 (Dolby Digital, ATSC A/52) syncframes: syncinfo / BSI, CRC check and decoder.
|
||||
- codecs/audio/Adpcm: the 4-bit ADPCM family, decode (and encode where it is cheap).
|
||||
- codecs/audio/Alac: Apple Lossless (ALAC) decoder and encoder.
|
||||
@@ -236,7 +261,8 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/image/Etc: ETC1 / ETC2 / EAC block texture decoding (Khronos Data Format Specification 1.3, section 21).
|
||||
- codecs/image/Half: IEEE 754 binary16 <-> number (round to nearest even, overflow to infinity). New in rosetta.
|
||||
- codecs/image/Jpeg: the JPEG codec (ITU T.81), bit-exact with libjpeg-turbo's djpeg and byte-identical with cjpeg.
|
||||
- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB.
|
||||
- codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write.
|
||||
- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers.
|
||||
- codecs/image/Quantize: palette quantization of rgba8 pixels (median cut or octree, Floyd-Steinberg dithering).
|
||||
- codecs/image/Raster: an antialiased scanline rasterizer (nonzero / even-odd) for line and Bézier paths, plus a stroker.
|
||||
- codecs/image/Texel: uncompressed GPU texel formats -> the standard pixel formats. New in rosetta.
|
||||
@@ -245,17 +271,25 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/image/Vp8L: WebP lossless (VP8L, RFC 9649 section 3).
|
||||
- codecs/image/Yuv: planar 4:2:0 Y'CbCr <-> rgba8, BT.601 / BT.709, limited or full range.
|
||||
- **model**
|
||||
- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection.
|
||||
- codecs/model/Displacement: Source engine displacement surfaces (VBSP ddispinfo_t / Hammer dispinfo), as
|
||||
- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to
|
||||
- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7).
|
||||
- codecs/model/Mat4: 4x4 matrix (column-major, glTF / Types.Scene layout) and quaternion { x, y, z, w } helpers.
|
||||
- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF).
|
||||
- codecs/model/Minecraft: what Minecraft's voxel formats share (model/schematic, model/mca). New code.
|
||||
- codecs/model/Patch: Quake III / Doom 3 Bezier patches (control grids) -> evaluated grids, triangles, normals.
|
||||
- codecs/model/Polygon: 2D polygons with holes to triangles by hole bridging and ear clipping. New code.
|
||||
- codecs/model/Rbx: the Roblox instance tree and property values shared by model/rbxm and model/rbxmx.
|
||||
- codecs/model/Rig: the Scene mapping shared by game model formats (MD2 / MD3 / MDL / MD5 / SMD / ...). New code.
|
||||
- codecs/model/Sampler: Scene animation sampling, STEP / LINEAR (slerp) / CUBICSPLINE as in glTF 2.0 animations. New code.
|
||||
- codecs/model/SourceAnim: studio model animation data: the run-length coded mstudioanimvalue_t shorts (GoldSrc and
|
||||
- codecs/model/Vrml: VRML97 / X3D scene-graph engine (classic and XML encodings) for model/vrml and model/x3d.
|
||||
- **text**
|
||||
- codecs/text/GodotVariant: Godot's text resource syntax (.tscn / .tres / .escn, formats 2-4; Godot's
|
||||
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
|
||||
- codecs/text/KeyValues: Valve KeyValues text (tier1/KeyValues.cpp of the Source SDK 2013, srctools' reading of it)
|
||||
- codecs/text/Lexer: C-style tokens for id Tech / UDMF text (idLib idLexer conventions, UDMF 1.1 §I; no code taken):
|
||||
- codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT").
|
||||
- codecs/text/Text: text decoding helpers: BOM stripping, Windows-1252 for text that is not UTF-8, line splitting.
|
||||
- codecs/text/Url: RFC 3986 reference resolution (section 5.2), local-path classification and percent-encoding.
|
||||
|
||||
+13
-3
@@ -29,13 +29,17 @@ src/Rosetta/
|
||||
codecs/<domain>/<Name> codecs (layer 3) generic algorithms, by domain:
|
||||
compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum UnixCompress Xxh32 Zstd
|
||||
entropy/ Huffman RangeCoder
|
||||
image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
|
||||
image/ Bcn Blend Dct Etc Half Jpeg Miptex Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
|
||||
audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample
|
||||
SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack
|
||||
video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry)
|
||||
text/ Json Nbt Text Url Xml
|
||||
text/ Json KeyValues Nbt Text Url Xml
|
||||
text/ GodotVariant Json Nbt Text Url Xml
|
||||
font/ Bitmap Cff GlyphNames TrueType
|
||||
model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml
|
||||
model/ Brush Displacement Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler SourceAnim Vrml
|
||||
text/ Json Lexer Nbt Text Url Xml
|
||||
font/ Bitmap Cff GlyphNames TrueType
|
||||
model/ Brush DoomMap Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler Vrml
|
||||
host/ host (layer 2) runtime adapters; only the api uses them
|
||||
Types.luau types (layer 1) standard types + constructors
|
||||
core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input
|
||||
@@ -242,7 +246,13 @@ them. Anything generic goes down a layer and is called:
|
||||
| GPU texture pixels (BCn, ETC / EAC, uncompressed texel layouts, half floats) | `codecs/image/Texture` (`Bcn`, `Etc`, `Texel`, `Half`) |
|
||||
| animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` |
|
||||
| polygons with holes -> triangles | `codecs/model/Polygon` |
|
||||
| studio model animation values (GoldSrc / Source run-length shorts, Quaternion48 / 64, bone records) | `codecs/model/SourceAnim` |
|
||||
| Doom-engine maps (binary lumps, UDMF) -> tables and a Scene | `codecs/model/DoomMap` |
|
||||
| C-style tokens (id Tech / UDMF text: comments, strings, numbers, words) | `codecs/text/Lexer` |
|
||||
| plane brushes -> polygons (CSG hull, coplanar merge, Quake / Valve 220 / brush-primitive texturing); Bezier patches | `codecs/model/Brush`, `codecs/model/Patch` |
|
||||
| Quake / GoldSrc mip textures, WAD2 / WAD3 directories; palettes (keyed index, grey, colormap) | `codecs/image/Miptex`, `codecs/image/Pixels` |
|
||||
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
|
||||
| Valve KeyValues (text, binary, the BSP entity lump); Source displacement surfaces | `codecs/text/KeyValues`, `codecs/model/Displacement` |
|
||||
| Roblox instance trees and property values | `codecs/model/Rbx` |
|
||||
| bitmap fonts as a Font; PostScript glyph names | `codecs/font/Bitmap`, `codecs/font/GlyphNames` |
|
||||
| CRC-16 (XMODEM / ARC), xxHash32 | `core/Crc16`, `codecs/compress/Xxh32` |
|
||||
|
||||
+19
-9
@@ -13,16 +13,16 @@ and the host notes. Each standard type has its own page:
|
||||
| [Audio](audio.md) | `Audio`, `Decoder` | WAV, FLAC, MP3, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC, WavPack, APE, TTA, Musepack, AC-3, QOA, ADPCM, ADX, VAG, BRSTM |
|
||||
| [Music](music.md) | `Module`, `Midi` | MOD, S3M, XM, IT, MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX, AHX / HVL, MIDI, MUS, XMI, HMP, SoundFont 2 |
|
||||
| [Video](video.md) | `VideoDecoder`, `Demuxer`, `Track`, `Packet` | MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Ogg Theora, FLV, FLI / FLC, Smacker, Y4M, H.264 |
|
||||
| [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, B3D, LDraw, LWO, .x, IQM, PMX / PMD, VRML, X3D, MD2, MD3, MDL, MD5, BSP, SMD |
|
||||
| [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, B3D, LDraw, LWO, .x, IQM, PMX / PMD, VRML, X3D, MD2, MD3, MDL, MD5, BSP, SMD, Godot TSCN / ESCN, Unreal T3D, ASE |
|
||||
| [Roblox](roblox.md) | `RbxTree` (`F.Rbx`), `Scene` | rbxm / rbxl, rbxmx / rbxlx, Roblox .mesh |
|
||||
| [CAD](cad.md) | `Cad` (STEP) | STEP (B-rep through a plug-in) |
|
||||
| [Fonts](font.md) | `Font` | TTF / OTF, WOFF, WOFF2, BMFont, BDF, PCF, PSF, FON, Type 1, EOT, Hershey |
|
||||
| [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2, PAK, WAD, GRP, VPK, MPQ, cpio, ar / deb, rpm, .Z, LZ4, ISO 9660, LHA, ARJ, Zoo, uu / yEnc / BinHex / MacBinary / AppleSingle, D64, ADF, FAT, CAB |
|
||||
| [Data](data.md) | plain values, `XmlNode`, `Date` | JSON, XML, YAML, TOML, CSV, INI, MessagePack, CBOR, plist |
|
||||
| [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2, PAK, WAD, GRP, VPK, MPQ, cpio, ar / deb, rpm, .Z, LZ4, ISO 9660, LHA, ARJ, Zoo, uu / yEnc / BinHex / MacBinary / AppleSingle, D64, ADF, FAT, CAB, Unity packages |
|
||||
| [Data](data.md) | plain values, `XmlNode`, `Date` | JSON, XML, YAML, TOML, CSV, INI, MessagePack, CBOR, plist, Godot `.tres` |
|
||||
| [Minecraft and voxels](voxel.md) | typed values, `Scene` + `Voxels` | NBT, SNBT, `.schem` / `.schematic` / `.litematic`, Anvil `.mca`, Qubicle `.qb` |
|
||||
| [Vector](vector.md) | `Vector` | SVG |
|
||||
| [Layered images](layered.md) | `Layered` | PSD, Aseprite, OpenRaster |
|
||||
| [Tile maps](tilemap.md) | `TileMap` | Tiled TMX / TMJ (+ TSX / TSJ tilesets) |
|
||||
| [Tile maps](tilemap.md) | `TileMap` | Tiled TMX / TMJ (+ TSX / TSJ tilesets), LDtk, Ogmo Editor 3 |
|
||||
| [Subtitles](subtitles.md) | `Subtitles`, `Cue` | SRT, WebVTT, ASS / SSA |
|
||||
| [Playlists](playlist.md) | `Playlist` | M3U / M3U8 (HLS), PLS, XSPF |
|
||||
|
||||
@@ -41,11 +41,21 @@ as `F`, and its input files as variables such as `pngBytes` (a buffer) or `srtTe
|
||||
|
||||
## Installing
|
||||
|
||||
**Roblox.** The library is one ModuleScript, [`build/Rosetta.luau`](../../build/Rosetta.luau) (committed; rebuilt by
|
||||
`python3 -I tools/build.py roblox`). Paste it into a ModuleScript named `Rosetta`, or mount it with Rojo
|
||||
(`"Rosetta": { "$path": "rosetta/build/Rosetta.luau" }`; this repository's `default.project.json` does, so
|
||||
`rojo build -o Rosetta.rbxm` or `rojo serve` works from here). Put it where both client and server can see it, for
|
||||
example ReplicatedStorage:
|
||||
**Roblox.** Two builds, both committed (rebuilt by `python3 -I tools/build.py roblox`):
|
||||
|
||||
- [`build/Rosetta.rbxm`](../../build/Rosetta.rbxm), the native build: a ModuleScript `Rosetta` with child
|
||||
ModuleScripts, the chunks (Core, one per heavy codec such as Mpeg2, H264, Jpeg, Opus, and the rest by folder). A
|
||||
chunk is required the first time one of its modules is, so an Actor that only decodes MPEG-1 and JPEG loads only
|
||||
those chunks and Core. Roblox compiles native code per ModuleScript within a budget per module; each chunk stays
|
||||
well under it (tools/bundle.py checks it). Insert the file, or mount it with Rojo
|
||||
(`"Rosetta": { "$path": "rosetta/build/Rosetta.rbxm" }`; this repository's `default.project.json` does, so
|
||||
`rojo build -o Rosetta.rbxm` or `rojo serve` works from here). [`build/Rosetta.rbxmx`](../../build/Rosetta.rbxmx)
|
||||
is the same model as XML.
|
||||
- [`build/Rosetta.luau`](../../build/Rosetta.luau), one ModuleScript with no native code (one 5.9 MB module is over
|
||||
the native budget): paste it into a ModuleScript named `Rosetta`, or mount it with
|
||||
`"$path": "rosetta/build/Rosetta.luau"`.
|
||||
|
||||
Put it where both client and server can see it, for example ReplicatedStorage:
|
||||
|
||||
<!-- doc:display needs Roblox -->
|
||||
```luau
|
||||
|
||||
+62
-2
@@ -210,7 +210,7 @@ assert(F.archive.load(bytes):read("maps/e1m1.bsp"))
|
||||
A WAD's lumps keep their order; lumps of a map are named `"<map>/<lump>"` (`"E1M1/THINGS"`) and repeated names get
|
||||
`"~2"`, `"~3"`, ... so every entry is unique (writing strips both again). The format module turns lumps into game
|
||||
data: graphics (flats, patches, sprites, menu pictures) into Images through the `PLAYPAL` palette, wall textures
|
||||
composed from their patches, and maps into a Scene (z up, map units: floors and ceilings triangulated from the
|
||||
composed from their patches, and maps (binary lumps or UDMF `TEXTMAP`) into a Scene (z up, map units: floors and ceilings triangulated from the
|
||||
sector outlines, walls, things as nodes standing on their floor).
|
||||
|
||||
```luau
|
||||
@@ -232,6 +232,28 @@ local data = assert(Wad.mapData(wad, "E1M1"))
|
||||
assert(#data.sectors == 2 and #data.things == 2)
|
||||
```
|
||||
|
||||
Quake's and Half-Life's texture WADs (WAD2 / WAD3, format `wad2`; Doom's IWAD / PWAD is `wad`) list their lumps
|
||||
by name; `image` decodes miptex textures (any mip level), qpic pictures, the console font and the palette lump. Quake 1
|
||||
lumps use the WAD's own `palette` lump (gfx.wad), `palette` or `gfx/palette.lmp` through `files` / `resolve` (Quake's
|
||||
palette is not redistributable, so rosetta never embeds it); WAD3 lumps carry their own. `addImage` writes images
|
||||
back as lumps (WAD3: with a palette made by median cut):
|
||||
|
||||
```luau
|
||||
local Wad2 = F.format("wad2")
|
||||
local gfx = assert(F.archive.load(gfxWadBytes))
|
||||
assert(gfx.format == "wad2" and gfx.meta.source.variant == "wad2")
|
||||
local brick = assert(Wad2.image(gfx, "brick")) -- through the WAD's palette lump
|
||||
local small = assert(Wad2.image(gfx, "brick", { mip = 2 })) -- 8 x 8
|
||||
assert(brick.width == 32 and small.width == 8)
|
||||
local disc = assert(Wad2.image(gfx, "disc")) -- a qpic: index 255 transparent
|
||||
assert(disc.meta.source.kind == "qpic")
|
||||
|
||||
local hl = Wad2.new("wad3")
|
||||
assert(Wad2.addImage(hl, "{FENCE", brick)) -- '{' textures key index 255
|
||||
local wad3 = assert(F.save(hl))
|
||||
assert(F.archive.load(wad3).meta.source.variant == "wad3")
|
||||
```
|
||||
|
||||
VPK directories (`pak01_dir.vpk`) hold small files themselves and point to numbered part files for the rest; pass
|
||||
those through `files` or `resolve` (loading a path does it for you):
|
||||
|
||||
@@ -254,6 +276,22 @@ local named = assert(F.archive.load(mpqBytes, { names = { "war3map.w3e" } }))
|
||||
assert(#named:list() >= 2)
|
||||
```
|
||||
|
||||
Wolfenstein 3D's page file (`VSWAP.WL6`, also `.WL1`, Spear of Destiny's `.SOD` / `.SDM`) loads as an Archive of
|
||||
its pages (`walls/000`, `sprites/000`, `sounds/000`, `soundinfo`). The format module turns walls and sprites into
|
||||
64 x 64 Images and the digitized sounds into Audio. The game's palette is not part of the file (nor redistributable):
|
||||
pass its 768 bytes as `palette` (6-bit VGA values are scaled up); without it the images are grey.
|
||||
|
||||
```luau
|
||||
local Vswap = F.format("vswap")
|
||||
local pages = assert(F.archive.load(vswapBytes, { name = "VSWAP.WL6" }))
|
||||
assert(pages:list()[1].name == "walls/000")
|
||||
local wall = assert(Vswap.image(pages, "wall", 0, { palette = wolfPaletteBytes }))
|
||||
local guard = assert(Vswap.image(pages, "sprite", 0, { palette = wolfPaletteBytes })) -- alpha 0 = hole
|
||||
assert(wall.width == 64 and guard.height == 64)
|
||||
local sound = assert(Vswap.sound(pages, 1)) -- u8 PCM at 7042 Hz, as f32 Audio
|
||||
assert(sound.sampleRate == 7042 and Vswap.sounds(pages) == 2)
|
||||
```
|
||||
|
||||
## Unix, package and disc archives
|
||||
|
||||
### cpio
|
||||
@@ -418,6 +456,26 @@ local out = assert(F.save(cab, nil, { format = "cab", compression = "none" }))
|
||||
assert(F.archive.load(out):list()[1].method == "store")
|
||||
```
|
||||
|
||||
## Unity packages
|
||||
|
||||
A `.unitypackage` is a gzip'd tar of one folder per asset guid (`asset`, `asset.meta`, `pathname`). It loads as an
|
||||
Archive keyed by the asset paths, each `.meta` next to its asset as in a Unity project folder; folders are `dir`
|
||||
entries with their own `.meta`. Every entry carries its `guid`, and an asset's `preview` (when the package has a
|
||||
`preview.png`) is a function returning its bytes. Without a name the file is plain gzip (it unwraps to the tar of
|
||||
guid folders): pass a `.unitypackage` name or `format = "unitypackage"`. Any Archive saves as a package: guids come
|
||||
from `entry.guid`, then the `.meta` entry's `guid:` line, else the path's MD5; missing `.meta` files are made.
|
||||
|
||||
```luau
|
||||
local pack = F.format("unitypackage").new()
|
||||
pack:add("Assets/Scripts", "", { dir = true })
|
||||
pack:add("Assets/Scripts/Player.cs", "public class Player { }\n")
|
||||
local bytes = assert(F.save(pack))
|
||||
local back = assert(F.load(bytes, { name = "game.unitypackage" }))
|
||||
assert(back.format == "unitypackage")
|
||||
local meta = buffer.tostring(assert(back:read("Assets/Scripts/Player.cs.meta")))
|
||||
assert(string.match(meta, "guid: (%x+)") == back:list()[3].guid)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -431,7 +489,8 @@ assert(F.archive.load(out):list()[1].method == "store")
|
||||
| bzip2 (`.bz2`, `.tbz2`) | yes | - | single stream |
|
||||
| Brotli (`.br`) | yes | - | single stream; no magic number, so pass a `.br` name or `format = "br"` |
|
||||
| PAK (`.pak`) | yes | yes | Quake / Quake II / Half-Life (and SiN `SPAK`) |
|
||||
| WAD (`.wad`) | yes | yes | IWAD / PWAD; lumps, graphics, wall textures and maps through `F.format("wad")` |
|
||||
| WAD (`.wad`) | yes | yes | IWAD / PWAD; lumps, graphics, wall textures and maps (binary and UDMF) through `F.format("wad")` |
|
||||
| VSWAP (Wolfenstein 3D `.wl6` / `.wl1` / `.sod` / `.sdm`) | yes | | pages; walls, sprites and sounds through `F.format("vswap")` |
|
||||
| GRP (`.grp`) | yes | yes | Build engine |
|
||||
| VPK (`.vpk`) | yes | yes | versions 1 / 2, multi-part reading, preload bytes; writes one directory file |
|
||||
| MPQ (`.mpq`, `.w3x`, `.sc2map`, ...) | yes | - | versions 1-4 (classic tables), encryption; no Huffman / ADPCM (WAVE) sectors |
|
||||
@@ -452,6 +511,7 @@ assert(F.archive.load(out):list()[1].method == "store")
|
||||
| C64 disks (`.d64`, `.d71`, `.d81`) | yes | yes | PETSCII names; no GEOS VLIR |
|
||||
| Amiga disks (`.adf`) | yes | - | OFS / FFS; no long-name (DOS 6 / 7) volumes |
|
||||
| FAT images (`.img`, `.ima`) | yes | yes | FAT12 / 16 / 32, VFAT names, MBR partitions; writes FAT12 floppies |
|
||||
| Unity package (`.unitypackage`) | yes | yes | assets by path, `.meta` files beside them, guids, previews; needs the extension to beat gzip |
|
||||
| Cabinet (`.cab`) | yes | yes | stored / MSZIP / LZX / Quantum (read), stored / MSZIP (write); no spanned files |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
+15
-1
@@ -102,6 +102,7 @@ the guide's [README](README.md#inputs)). Options:
|
||||
| `maxFrames` | wav, flac, mp3, aiff, au, voc, aac, mpc, ac3 | `Err.LIMIT` past this many frames |
|
||||
| `drc` | ac3 | dynamic range control: 0 = off (default), 1 = as the stream says |
|
||||
| `stereo` | opus | downmix surround streams to stereo |
|
||||
| `sbr` | aac, m4a, the AAC tracks of mp4 / mkv / ts | `false`: decode only the AAC-LC core of HE-AAC (half the rate, mono for HE-AACv2, about 4x faster) |
|
||||
|
||||
```luau
|
||||
local tags = assert(F.audio.open(mp3Bytes)).tags -- opening reads the tags; nothing is decoded yet
|
||||
@@ -112,6 +113,19 @@ local bad, err = F.audio.load("not audio at all")
|
||||
assert(bad == nil and err.code == F.Err.UNKNOWN_FORMAT)
|
||||
```
|
||||
|
||||
### HE-AAC
|
||||
|
||||
HE-AAC (SBR) and HE-AACv2 (SBR + parametric stereo) decode at the full output rate in every AAC path: ADTS, M4A,
|
||||
and the audio tracks of MP4, Matroska and MPEG-TS (HLS radio). ADTS cannot signal SBR, so the decoder looks for SBR
|
||||
and PS data in the first frames, as ffmpeg does; `sampleRate`, `channels` and `frames` report the output.
|
||||
|
||||
```luau
|
||||
local dec = assert(F.audio.open(heAacBytes)) -- HE-AACv2 in ADTS: a 24 kHz mono core
|
||||
assert(dec.sampleRate == 48000 and dec.channels == 2) -- SBR doubles the rate, PS makes it stereo
|
||||
local core = assert(F.audio.open(heAacBytes, { sbr = false })) -- the AAC-LC core only, for slow devices
|
||||
assert(core.sampleRate == 24000 and core.channels == 1 and core.frames * 2 == dec.frames)
|
||||
```
|
||||
|
||||
## Editing: `F.ops.audio`
|
||||
|
||||
Every function returns a new Audio, or `nil, err` for bad arguments. Times are in seconds. Rates and channel counts
|
||||
@@ -192,7 +206,7 @@ Tags are written from `audio.tags`, or from the Decoder's `tags`, wherever the f
|
||||
|
||||
| Read and write | Read only |
|
||||
|---|---|
|
||||
| wav (+ RF64), flac (+ Ogg FLAC), mp3 / mp2, vorbis (.ogg), opus, aiff / aifc, au, voc, caf, m4a (ALAC), qoa, adx, vag, adpcm (raw IMA / MS) | aac (ADTS), m4a / caf AAC, mpc (Musepack SV7 / SV8), ac3 (Dolby Digital), brstm / bcstm / bfstm, KVAG, wav / aifc / caf IMA and MS ADPCM, wavpack (.wv + .wvc), ape, tta |
|
||||
| wav (+ RF64), flac (+ Ogg FLAC), mp3 / mp2, vorbis (.ogg), opus, aiff / aifc, au, voc, caf, m4a (ALAC), qoa, adx, vag, adpcm (raw IMA / MS) | aac (ADTS; AAC-LC, HE-AAC, HE-AACv2), m4a / caf AAC, mpc (Musepack SV7 / SV8), ac3 (Dolby Digital), brstm / bcstm / bfstm, KVAG, wav / aifc / caf IMA and MS ADPCM, wavpack (.wv + .wvc), ape, tta |
|
||||
|
||||
Each format's capabilities are listed in [FORMATS.md](../FORMATS.md). The audio tracks of video files open as
|
||||
Decoders too: see `v.audio` in [video.md](video.md). Music files (MOD, MIDI, ...) render to a Decoder: see
|
||||
|
||||
+65
-1
@@ -306,6 +306,68 @@ local xml = assert(F.saveString(p, { format = "plist" }))
|
||||
assert(string.find(xml, "<key>CFBundleName</key>\n\t<string>Demo</string>", 1, true))
|
||||
```
|
||||
|
||||
## VDF (Valve KeyValues)
|
||||
|
||||
`.vdf`, `.acf`, `.res` and other KeyValues files decode to `Types.object`s of strings; a key that repeats gets an array
|
||||
of its values (`duplicates = "last"` / `"first"` keep one). `[$CONDITION]`s are evaluated for a PC (`defines =
|
||||
{ OSX = true }` changes the flags, `defines = false` keeps every pair), `#include` / `#base` files come through
|
||||
`resolve`, `escapes = false` reads backslashes as they are. `pairs = true` gives the ordered pair list of
|
||||
`codecs/text/KeyValues` (`{ key, value, cond?, type? }`), which keeps everything. Binary KeyValues (`shortcuts.vdf`)
|
||||
are sniffed; encode with `binary = true`.
|
||||
|
||||
```luau
|
||||
local acf = assert(F.data.load('"AppState"\n{\n\t"appid"\t"440"\n\t"x" "1"\n\t"x" "2"\n}\n', { format = "vdf" }))
|
||||
assert(acf.AppState.appid == "440" and acf.AppState.x[2] == "2")
|
||||
local text = assert(F.saveString(acf, { format = "vdf" }))
|
||||
assert(string.find(text, '\t"x"\t"1"\n\t"x"\t"2"\n', 1, true))
|
||||
local pairs = assert(F.data.load('"r" { "a" "1" [$X360] }', { format = "vdf", pairs = true, defines = false }))
|
||||
assert(pairs[1].value[1].cond == "$X360")
|
||||
local bin = assert(F.save(acf, nil, { format = "vdf", binary = true }))
|
||||
assert(F.data.load(bin, { format = "vdf" }).AppState.appid == "440")
|
||||
```
|
||||
|
||||
## Godot resources (.tres)
|
||||
|
||||
Godot text resources load as a table: `type` (the resource class), `format`, `uid`, `scriptClass`, `external` (the
|
||||
`ext_resource` list: `id`, `type`, `path`, `uid`), `subresources` (`id`, `type`, `properties`) and `properties` (the
|
||||
`[resource]` section, in file order). Godot values that Luau lacks are `{ type, args }` tables: `Vector3(1, 2, 3)` is
|
||||
`{ type = "Vector3", args = { 1, 2, 3 } }`, likewise `Color`, `Transform3D`, `PackedFloat32Array`, `NodePath`,
|
||||
`&"StringName"` (`type = "StringName"`), `SubResource("id")` and `ExtResource("id")`; `Object(Class, ...)` has `class`
|
||||
and its properties in `args[1]`. Godot dictionaries keep their order and may have number keys. Godot tells integers
|
||||
from floats, so integral floats read from a file (`1.0`) are written back as floats.
|
||||
`F.format("tres")` and the codec `F._internal("codecs/text/GodotVariant")` (`value`, `format`, `isCtor`, `ctor`)
|
||||
help with the values. Scenes (`.tscn`) are models: see [the scene guide](scene.md).
|
||||
|
||||
```luau
|
||||
local res = assert(F.data.load(tresText))
|
||||
assert(res.type == "StandardMaterial3D" and res.external[1].path == "res://brick.png")
|
||||
local c = res.properties.albedo_color
|
||||
assert(c.type == "Color" and c.args[1] == 0.8)
|
||||
assert(res.properties.albedo_texture.type == "ExtResource")
|
||||
res.properties.metallic = 0.5
|
||||
local text = assert(F.saveString(res, { format = "tres" }))
|
||||
assert(string.find(text, "metallic = 0.5", 1, true) and string.find(text, "roughness = 1.0", 1, true))
|
||||
```
|
||||
|
||||
## Quake III shaders and skins
|
||||
|
||||
Quake III `.shader` scripts load as a list of shaders: `{ name, directives, stages }`, each directive its tokens
|
||||
(`{ "surfaceparm", "nolightmap" }`), each stage a list of directives; they write back. `.skin` files (format
|
||||
`q3skin`) are lists of `{ surface, shader }` (tags have an empty shader).
|
||||
|
||||
```luau
|
||||
local Q3Shader = F.format("q3shader")
|
||||
local shaders = assert(F.data.load(shaderText, { format = "q3shader" }))
|
||||
local wall = assert(Q3Shader.find(shaders, "textures/base_wall/metalfloor_wall_10"))
|
||||
assert(Q3Shader.directive(wall.directives, "surfaceparm")[2] == "metalsteps")
|
||||
assert(wall.stages[1][1][2] == "$lightmap" and #wall.stages == 2)
|
||||
local again = assert(F.saveString(shaders, { format = "q3shader" }))
|
||||
assert(#assert(F.data.load(again, { format = "q3shader" })) == #shaders)
|
||||
|
||||
local skin = assert(F.data.load(skinText, { format = "q3skin" }))
|
||||
assert(F.format("q3skin").shader(skin, "h_head") == "models/players/sarge/band.tga")
|
||||
```
|
||||
|
||||
## Save and convert
|
||||
|
||||
Data values have no `kind`, so saving needs `opts.format` or a destination extension (an `XmlNode` document too):
|
||||
@@ -337,10 +399,12 @@ is an error there), CSV needs rows, INI needs sections of scalars, JSON has no b
|
||||
| toml (`.toml`) | yes | yes | ordered tables, Dates |
|
||||
| csv (`.csv`, `.tsv`) | yes | yes | rows (arrays or records) |
|
||||
| ini (`.ini`, `.cfg`, `.conf`, `.desktop`) | yes | yes | sections of strings |
|
||||
| vdf (`.vdf`, `.acf`, `.res`, `.kv`) | text + binary | text + binary | ordered objects of strings, or pairs |
|
||||
| msgpack (`.msgpack`, `.mpk`) | yes | yes | values, buffers, Dates |
|
||||
| cbor (`.cbor`) | yes | yes | values, buffers, Dates, tagged values |
|
||||
| plist (`.plist`) | XML + binary | XML | values, buffers, Dates |
|
||||
| nbt (`.nbt`, `.dat`, `.mcstructure`), snbt (`.snbt`) | yes | yes | typed values: see [Minecraft and voxels](voxel.md) |
|
||||
| tres (`.tres`) | yes | yes | Godot resources: sections, Variant values as `{ type, args }` |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
@@ -351,7 +415,7 @@ Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
- Luau has one number type: `1.0` reads back as `1`, and TOML / plist write integral floats as integers. Integers
|
||||
past 2^53 need `bigInts = "string"` to survive.
|
||||
- An empty plain table `{}` is written as an array; use `F.Types.object()` (or `emptyTable = "object"`) for `{}`.
|
||||
- Text formats sniff weakly: give `format` (or a file name) for YAML, TOML, INI, CSV, MessagePack and CBOR without
|
||||
- Text formats sniff weakly: give `format` (or a file name) for YAML, TOML, INI, VDF, CSV, MessagePack and CBOR without
|
||||
its self-describe tag.
|
||||
- XML whitespace-only text between elements is dropped by default (`whitespace = true` keeps it); text is never
|
||||
trimmed otherwise.
|
||||
|
||||
+41
-1
@@ -1,7 +1,7 @@
|
||||
# Images
|
||||
|
||||
Every image format (PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO / CUR, PNM / PAM / PFM, Radiance HDR,
|
||||
OpenEXR, the [game textures](#game-textures) DDS / KTX / VTF / BLP / TIM, and the [older formats](#formats) PCX, SGI,
|
||||
OpenEXR, the [game textures](#game-textures) DDS / KTX / VTF / BLP / TIM / ART, and the [older formats](#formats) PCX, SGI,
|
||||
Sun Raster, ILBM, XPM, XBM, ICNS, ANI) loads as one `Image`: a width, a height, a pixel format and one tightly packed `buffer`. Animations (GIF, APNG, animated
|
||||
WebP) and multi-image files (TIFF pages, ICO entries) add a list of `Frame`s. Editing goes through `F.ops.image`.
|
||||
|
||||
@@ -214,8 +214,47 @@ local small = assert(F.image.load(vtfBytes, { mip = 1 })) -- or face = n (cub
|
||||
assert(F.detect(tim) == "tim")
|
||||
```
|
||||
|
||||
Build engine ART files (`TILES000.ART` ..., Duke Nukem 3D, Shadow Warrior) hold many tiles: each is one entry of
|
||||
`frames` (in tile order, empty tiles 0 x 0), with its tile number in `meta.tile` and its picanm animation and centre
|
||||
offsets in `meta.picanm`; the top-level image is the first non-empty tile. Colours come from the game's
|
||||
`PALETTE.DAT`, passed as `palette` or found next to the file through `resolve` (without it the tiles decode as a grey
|
||||
ramp). Index 255 is transparent. `shade` / `pal` apply a PALETTE.DAT shade table / a LOOKUP.DAT palookup, `native`
|
||||
keeps the palette indices (gray8), and ART writes back from either form:
|
||||
|
||||
```luau
|
||||
local tiles = assert(F.image.load(artBytes, { palette = paletteBytes }))
|
||||
local second = tiles.frames[2].image
|
||||
assert(second.meta.tile == 1 and second.width == 8)
|
||||
assert(second.meta.picanm.type == "forward" and second.meta.picanm.frames == 2)
|
||||
local raw = assert(F.image.load(artBytes, { format = "art", native = true }))
|
||||
assert(raw.frames[1].image.format == "gray8")
|
||||
assert(buffer.tostring(assert(F.save(raw, nil, { format = "art" }))) == buffer.tostring(artBytes))
|
||||
```
|
||||
|
||||
Doom's graphics come from WAD lumps rather than files: `F.format("wad").image(wad, name)` (see
|
||||
[archive.md](archive.md#game-archives)).
|
||||
Quake's `.lmp` pictures (qpics), `palette.lmp` and `colormap.lmp`, and Quake / Half-Life sprites (`.spr`) load
|
||||
too. Quake pictures and sprites are 8-bit images over Quake's palette, which is not redistributable: pass it as
|
||||
`palette` (768 bytes) or as `gfx/palette.lmp` through `files` / `resolve` (without it they load grey,
|
||||
`meta.source.palette = false`). Half-Life sprites carry their own palette. Sprite frames are `img.frames` on one
|
||||
canvas around the sprite's origin (`meta.origin`); frame groups give the delays.
|
||||
|
||||
```luau
|
||||
local disc = assert(F.image.load(discLmpBytes, { name = "disc.lmp", palette = quakePaletteBytes }))
|
||||
assert(disc.width == 24 and disc.meta.source.palette) -- index 255 is transparent
|
||||
local pal = assert(F.image.load(quakePaletteBytes, { format = "lmp" })) -- a 16 x 16 swatch
|
||||
assert(#pal.meta.palette == 256)
|
||||
local back = assert(F.save(disc, nil, { format = "lmp", palette = quakePaletteBytes }))
|
||||
assert(buffer.len(back) == buffer.len(discLmpBytes))
|
||||
|
||||
local flame = assert(F.image.load(flameSprBytes)) -- Half-Life: its own palette
|
||||
assert(#flame.frames == 3 and flame.meta.source.texFormat == "alphatest")
|
||||
local spr = assert(F.save(flame, nil, { format = "spr" })) -- version 2; version = 1 (Quake) needs palette
|
||||
assert(#F.image.load(spr).frames == 3)
|
||||
```
|
||||
|
||||
Doom's graphics come from WAD lumps rather than files: `F.format("wad").image(wad, name)`, and Quake / Half-Life
|
||||
textures from WAD2 / WAD3: `F.format("wad2").image(wad, name)` (see [archive.md](archive.md#game-archives)).
|
||||
|
||||
## Formats
|
||||
|
||||
@@ -233,6 +272,7 @@ Read and write unless noted; see [FORMATS.md](../FORMATS.md) for depths and deta
|
||||
| TIM | | yes | PlayStation; 4 / 8-bit CLUT, 15 / 24-bit |
|
||||
| BLP | | yes | Blizzard BLP1 / BLP2 (DXT through the BCn codec); writes BLP2 BGRA |
|
||||
| VTF | frames | yes | Valve; read only; mips / faces / slices by option |
|
||||
| ART | tiles as frames | index 255 | Build engine tiles; palette from PALETTE.DAT (`palette` / `resolve`), picanm in `meta.picanm` |
|
||||
| DDS, KTX / KTX2 | faces / layers / slices | yes | GPU textures: BC1..BC7, ETC / EAC, every uncompressed layout; mips in `meta.mipmaps` |
|
||||
| OpenEXR | parts (`opts.part`) | yes | half / float / uint, NONE / RLE / ZIPS / ZIP / PIZ, tiles; writes NONE / ZIPS / ZIP |
|
||||
| PCX, SGI, Sun Raster, IFF ILBM / PBM, XPM, XBM | | yes (XBM 1-bit) | old paint / workstation formats; ILBM reads HAM and EHB |
|
||||
|
||||
+379
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw, LightWave
|
||||
LWO, DirectX .x, IQM, PMX / PMD, VRML, X3D, the [game models](#game-models) MD2 / MD3 / MDL / MD5 / BSP / SMD,
|
||||
[Roblox meshes](roblox.md) and the [Minecraft and Qubicle voxel files](voxel.md)) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes
|
||||
[Blender .blend](#blender-blend), [Roblox meshes](roblox.md) and the [Minecraft and Qubicle voxel files](voxel.md)) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes
|
||||
made of primitives, flat attribute buffers (accessors), PBR materials, textures, cameras, lights, skins and animations.
|
||||
Mesh-only formats (STL, PLY, OFF) give a one-node scene. MagicaVoxel files also carry voxel grids (`scene.voxels`).
|
||||
Editing goes through `F.ops.mesh`.
|
||||
@@ -470,6 +470,9 @@ Game model formats load as Scenes too, with what games need: skins (joints + inv
|
||||
| MD5 (Doom 3 `.md5mesh` / `.md5anim`) | skeleton, weighted meshes, shaders as URIs | the `.md5anim` files named in `anims` |
|
||||
| SMD (Valve, read + write) | skeleton, weight links, a primitive per material | the skeleton frames |
|
||||
| BSP (Quake 1 / 2 / 3, Half-Life) | each model a mesh, a primitive per texture (and Quake III lightmap); entities in `meta.entities` | - |
|
||||
| VBSP (Source 19 / 20 / 21) | each model a mesh, a primitive per material, displacements; static props as nodes; lights; entities; the pak lump | - |
|
||||
| VMF (Hammer, read + write) | a mesh per entity with solids, displacements; point entities as nodes; cameras; visgroups | - |
|
||||
| BSP (Quake 1 / 2 / 3, Half-Life; BSP2, 2PSB) | each model a mesh, a primitive per texture; lightmaps as `TEXCOORD_1`; entities in `meta.entities`; tree, hulls and PVS in `meta.bsp` | - |
|
||||
|
||||
```luau
|
||||
local tank = assert(F.model.load(md2Bytes))
|
||||
@@ -507,6 +510,230 @@ local again = assert(F.save(barney, nil, { format = "smd" })) -- SMD writes ba
|
||||
assert(F.model.load(again).skins[1])
|
||||
```
|
||||
|
||||
## Build engine maps
|
||||
|
||||
Duke Nukem 3D / Shadow Warrior `.map` files (versions 7-9; the text Quake `.map` is a different format, told apart by
|
||||
content) load as one mesh: floors and ceilings triangulated with their slopes, walls with upper and lower parts at red
|
||||
walls (and masked walls), a primitive per surface kind and tile (`extras.build = { kind, tile }`); materials and
|
||||
textures are named `tile<n>`. Sprites become nodes under the map with their tile in `extras.build.tile` (the raw
|
||||
sprite in `extras.build.sprite`), and the player start is the node `start`. Coordinates turn z up (Build's y and z
|
||||
point down), z is divided by 16 so all axes share Build's xy unit, and `scale` multiplies everything. `tiles` (tile
|
||||
number to Image, e.g. from an ART file) gives the texture sizes for the UVs and attaches the images.
|
||||
|
||||
The raw sector, wall and sprite tables stay in `meta.build`, and saving writes them back:
|
||||
|
||||
```luau
|
||||
local map = assert(F.model.load(buildmapBytes, { scale = 1 / 512 }))
|
||||
local level = map.meta.build
|
||||
assert(level.version == 7 and #level.sectors == 3)
|
||||
assert(map.nodes[2].name == "start" and map.nodes[3].extras.build.tile == level.sprites[1].picnum)
|
||||
local again = assert(F.save(map, nil, { format = "buildmap" }))
|
||||
assert(buffer.tostring(again) == buffer.tostring(buildmapBytes))
|
||||
local Build = F.format("buildmap") -- the floor height under a point, slopes included
|
||||
assert(Build.slopeZ(level, 0, true, 100, 100) == level.sectors[1].floorz)
|
||||
```
|
||||
|
||||
## Source engine models (MDL v44-49)
|
||||
|
||||
`sourcemdl` reads Source studio models (Half-Life 2 to CS:GO-era v44-49; GoldSrc v10 stays `mdl`). The geometry is
|
||||
in sibling files found through `files` / `resolve` (or `vvd` / `vtx` / `phy` / `ani` buffers): `<name>.vvd`
|
||||
vertices, `<name>.dx90.vtx` (else `.dx80` / `.sw` / `.vtx`) strips, optional `<name>.phy` collision and the `.ani`
|
||||
animation blocks; `<name>` is the stem of `opts.name`, else of the name stored in the MDL. Without them the Scene has
|
||||
the skeleton and the animations only (`meta.source.warnings` says what was missing).
|
||||
|
||||
- Bones become a skin (`poseToBone` as the inverse bind matrices); procedural bones (jiggle, aim-at, ...) are data in
|
||||
the joint nodes' `extras.procedural`.
|
||||
- Each body part model is a mesh (one primitive per studio mesh); `bodies` picks the model per body part for the
|
||||
nodes (default 1), the others are in `scene.meshes` and `meta.source.bodyParts`. `lod` picks the LOD of
|
||||
`prim.indices`; every LOD's indices are in `prim.extras.lods`.
|
||||
- Flexes are morph targets (stereo flexes split by side), named in `mesh.extras.targetNames`; attachments are nodes
|
||||
under their bones; hitboxes, sequences (activities, events, blends), pose parameters and flex rules are in
|
||||
`meta.source`.
|
||||
- Each animation (decoded from the run-length / Quaternion48 / 64 data, sections and `.ani` blocks; delta
|
||||
animations added to the rest pose) is named after the first sequence that plays it.
|
||||
- Materials: each texture name is looked up as `materials/<cdmaterials dir><name>.vmt`; `$basetexture` / `$bumpmap`
|
||||
become `.vtf` texture URIs (`F.model.loadTextures` with a `resolve` for the game's files decodes them),
|
||||
`$translucent` / `$alphatest` / `$nocull` / `$color` map to the material, and every parameter is kept in
|
||||
`material.extras.vmt`.
|
||||
|
||||
```luau
|
||||
local files = {
|
||||
["model.vvd"] = sourceVvdBytes,
|
||||
["model.dx90.vtx"] = sourceVtxBytes,
|
||||
["model.phy"] = sourcePhyBytes,
|
||||
["materials/models/test/skin_a.vmt"] = skinVmtText,
|
||||
}
|
||||
local model = assert(F.model.load(sourceMdlBytes, { name = "model.mdl", files = files }))
|
||||
local src = model.meta.source
|
||||
assert(src.format == "sourcemdl" and src.version == 49 and model.meta.up == "z")
|
||||
assert(#model.skins[1].joints == 6)
|
||||
local body = model.meshes[src.bodyParts[1].models[1].mesh]
|
||||
assert(#body.primitives == 2 and body.extras.targetNames[1] == "AU1L")
|
||||
assert(#body.primitives[1].extras.lods == 2)
|
||||
assert(model.animations[1].name == "idle" and src.sequences[1].activity == "ACT_IDLE")
|
||||
local skinA = model.materials[1]
|
||||
assert(model.textures[skinA.baseColorTexture.texture].uri == "materials/models/test/skin_a.vtf")
|
||||
assert(#src.physics.solids[1].hulls == 2)
|
||||
```
|
||||
|
||||
### Source maps (VBSP)
|
||||
|
||||
Compiled Source maps (`.bsp` with the `VBSP` magic: HL2, TF2, Portal, L4D2, CS:GO) load as one mesh per brush model
|
||||
(`world`, `*1`, ...) with a primitive per material; brush entities place their model by `origin` / `angles`.
|
||||
Displacements are tessellated (their blend alpha is the `_BLEND` attribute), tool faces (nodraw, skip, hint, sky) are
|
||||
left out unless `tools = true`. Static props are nodes with `extras.model` (the `.mdl` path) and
|
||||
`extras.vbsp` (skin, solid, fade, ...); `light`, `light_spot` and `light_environment` become lights. Entities are
|
||||
`meta.entities` (KeyValues objects: a repeated output is an array), the pak lump `meta.pak` (an Archive), and a
|
||||
material's texture is `materials/<name>.vtf`, embedded when the pak has it. LZMA-compressed lumps and the L4D2 lump
|
||||
header are read; lightmaps and visibility are not.
|
||||
|
||||
```luau
|
||||
local room = assert(F.model.load(vbspBytes, { name = "room.bsp" }))
|
||||
assert(room.meta.source.format == "vbsp" and room.meta.source.version == 21)
|
||||
local props = {}
|
||||
for _, n in room.nodes do
|
||||
if n.extras and n.extras.model then
|
||||
table.insert(props, n.extras.model)
|
||||
end
|
||||
end
|
||||
assert(props[1] == "models/props_junk/wood_crate001a.mdl")
|
||||
assert(room.meta.entities[1].classname == "worldspawn")
|
||||
assert(room.meta.pak:read("materials/custom/note.txt"))
|
||||
```
|
||||
|
||||
### Hammer maps (VMF)
|
||||
|
||||
`.vmf` sources load like `.map` files: a mesh per entity with solids (Valve 220 texture axes through
|
||||
`codecs/model/Brush`), displacements tessellated as the compiler does (a brush with a displaced side keeps only its
|
||||
displaced sides), point entities as nodes (`extras.model` for props), Hammer cameras as cameras. `tools/*` materials
|
||||
are left out unless `tools = true`; texture sizes come from `textureSizes`, or `materials/<name>.vtf` through
|
||||
`resolve` and `decodeImage`, else 512 x 512. `meta.entities` holds the keys (outputs under `connections`),
|
||||
`meta.visgroups`, `meta.groups` and `meta.solids` the editor data, and `meta.vmf` the parsed document, which `F.save`
|
||||
writes back exactly as Hammer lays it out. `F.format("vmf")` builds documents: `document`, `world`, `box`, `solid`,
|
||||
`entity`.
|
||||
|
||||
```luau
|
||||
local hammer = assert(F.model.load(vmfText, { format = "vmf" }))
|
||||
assert(hammer.meta.entities[1].classname == "worldspawn" and hammer.meta.visgroups[1].name == "Walls")
|
||||
assert(#hammer.cameras == 2)
|
||||
assert(F.saveString(hammer, { format = "vmf" }) == vmfText) -- unchanged documents write back byte for byte
|
||||
|
||||
local Vmf = F.format("vmf")
|
||||
local doc = Vmf.document({ skyname = "sky_day01_01" })
|
||||
table.insert(Vmf.world(doc), Vmf.box({ -128, -128, -16 }, { 128, 128, 0 }, "DEV/DEV_MEASUREGENERIC01B"))
|
||||
Vmf.entity(doc, { { "classname", "info_player_start" }, { "origin", "0 0 8" } })
|
||||
local built = assert(F.model.load(assert(F.saveString(doc, { format = "vmf" })), { format = "vmf" }))
|
||||
assert(#built.meshes[1].primitives == 1 and built.meta.entities[2].classname == "info_player_start")
|
||||
```
|
||||
|
||||
## Doom maps (UDMF)
|
||||
|
||||
Doom-engine maps load as Scenes (z up, map units): floors and ceilings triangulated from the sector outlines, walls
|
||||
with vanilla texture alignment, things as child nodes standing on their floor. Maps inside a WAD (binary lumps or a
|
||||
UDMF `TEXTMAP`) load through `F.format("wad").map(wad, name)` (see the archive page); a standalone UDMF text
|
||||
(`.udmf`, or a `TEXTMAP` lump saved alone) loads directly, with texture sizes from `textureSize` (else 64 x 128 walls
|
||||
and 64 x 64 flats) and the textures as URIs. `F.format("udmf").data` gives the tables: every UDMF block keeps its
|
||||
fields as written (`fields`, lower-case keys: namespace and `user_` keys too), flags are rebuilt in the binary layout
|
||||
(Doom bits for the Doom / Heretic / Strife namespaces, Hexen bits otherwise), and unknown blocks stay in `blocks`.
|
||||
|
||||
```luau
|
||||
local room = assert(F.model.load(udmfText))
|
||||
assert(room.meta.source.format == "udmf" and room.meta.source.namespace == "ZDoom")
|
||||
assert(room.nodes[3].translation[3] == 40) -- a thing 8 units above the 32-unit pillar
|
||||
local Udmf = F.format("udmf")
|
||||
local data = assert(Udmf.data(F.Bytes.reader(buffer.fromstring(udmfText))))
|
||||
assert(data.sectors[1].fields.user_gravity == 0.5)
|
||||
assert(data.linedefs[4].tag == 7 and data.blocks[1].type == "vavoombox")
|
||||
```
|
||||
|
||||
## Doom 3 / Quake 4 levels
|
||||
|
||||
A compiled `.proc` file (dmap's render geometry: `mapProcFile003`, Quake 4's `PROC "4"`) loads as a Scene: each model
|
||||
(the areas `_area0`, `_area1`, ... and the inline models of entities) is a mesh with a primitive per surface
|
||||
(positions, normals, texture coordinates, Quake 4 vertex colours as `COLOR_0`) and a child node of the root; the
|
||||
materials are URIs. id Tech 4 triangles are clockwise-front, so they are turned counter-clockwise. The portals between
|
||||
areas, the BSP nodes and the shadow models load as data in `meta.proc`.
|
||||
|
||||
The editor's `.map` (`Version 2` for Doom 3, `Version 3` for Quake 4; told apart from Quake's `.map` by that line)
|
||||
loads as a Scene too: `brushDef3` brushes (plane equations) become polygons through the same brush clipper as the
|
||||
Quake maps, with Doom 3's texture matrices, and `patchDef2` / `patchDef3` surfaces become triangle grids (patchDef3 at
|
||||
its stored subdivisions, patchDef2 at `patchLevel` segments per sub-patch). Each entity is a node with its keys in
|
||||
`extras.keys`; entities with geometry get a mesh (in world coordinates), point entities their `origin`, `rotation`
|
||||
or `angle`. `skip` leaves materials out (`"textures/common/caulk"`), `hull` drops faces hidden inside other brushes.
|
||||
|
||||
```luau
|
||||
local level = assert(F.model.load(procText))
|
||||
assert(level.meshes[1].name == "_area0" and level.meta.up == "z")
|
||||
local proc = level.meta.proc
|
||||
assert(proc.areas == 2 and proc.portals[1].positive == 1 and #proc.portals[1].points == 12)
|
||||
assert(proc.nodes[1].negative == -1) -- < 0: area -1 - n; > 0: a node (1-based); 0: solid
|
||||
assert(level.materials[1].name == "textures/base_wall/lfwall1")
|
||||
|
||||
local room = assert(F.model.load(d3mapText, { name = "room.map", skip = { "textures/common/caulk" } }))
|
||||
assert(room.meta.source.format == "d3map" and room.meta.source.variant == "doom3")
|
||||
assert(#room.meshes[1].primitives == 1) -- the floor material; caulk skipped
|
||||
local start = room.nodes[3]
|
||||
assert(start.extras.classname == "info_player_start" and start.translation[3] == 1)
|
||||
```
|
||||
|
||||
## Quake maps: editor `.map` and compiled BSP
|
||||
|
||||
`model/map` reads and writes the editor maps of Quake, Half-Life (Valve 220), Quake II (with content / surface flags)
|
||||
and Quake III (`brushDef` brush primitives, `patchDef2` / `patchDef3` patches). Every entity is a node (child of the
|
||||
`map` root) with `extras.classname`, `extras.keys` (an ordered object) and `extras.brushes` (the brushes as written);
|
||||
entities with brushes get a mesh, a primitive per texture. Point entities stand at their `origin`. Brushes become
|
||||
polygons the way qbsp builds them (`codecs/model/Brush`; tested against ericw-tools); `hull = true` drops the faces
|
||||
inside or touching other brushes of the same entity, `merge = true` merges coplanar faces. Texture coordinates need
|
||||
texture sizes: they come from `textureSizes`, the worldspawn's WADs (`"wad"` key), Quake II `.wal` files or Quake III
|
||||
images (with `decodeImage`) through `files` / `resolve`; unknown textures count as 64 x 64
|
||||
(`material.extras.map.sizeKnown = false`).
|
||||
|
||||
```luau
|
||||
local Map = F.format("map")
|
||||
local room = assert(F.model.load(roomMapText, { files = { ["gfx/tex.wad"] = texWadBytes }, hull = true }))
|
||||
assert(room.meta.source.variant == "quake" and room.meta.up == "z")
|
||||
local world = room.nodes[2] -- node 1 is the "map" root
|
||||
assert(world.extras.classname == "worldspawn" and world.mesh)
|
||||
local door = room.nodes[3]
|
||||
assert(door.name == "door1" and door.extras.keys.angle == "90")
|
||||
assert(room.materials[1].extras.map.sizeKnown) -- sizes from the WAD
|
||||
local start = room.nodes[4] -- a point entity at its origin
|
||||
assert(start.translation[1] == -128)
|
||||
|
||||
start.translation = { 0, 0, 24 } -- edit and write back
|
||||
door.extras.keys.speed = "200"
|
||||
local text = buffer.tostring(assert(F.save(room, nil, { format = "map" })))
|
||||
assert(string.find(text, '"origin" "0 0 24"', 1, true))
|
||||
local valve = assert(F.save(room, nil, { format = "map", variant = "valve220" })) -- Quake standard -> Valve 220 axes
|
||||
assert(F.model.load(valve).meta.source.variant == "valve220")
|
||||
local parsed = assert(Map.parse(roomMapText)) -- the raw entities: keys, brushes, faces as written
|
||||
assert(#parsed.entities == 4 and parsed.entities[1].brushes[1].faces[1].texture)
|
||||
```
|
||||
|
||||
Compiled `.bsp` maps carry what the engines need beyond the triangles. Quake 1 (BSP 29, BSP2, 2PSB), Half-Life and
|
||||
Quake II lightmaps (the first light style) are packed into one atlas texture named `"lightmap"`, mapped by
|
||||
`TEXCOORD_1` and named by each material's `extras.bsp.lightmap` (Quake III keeps its own 128 x 128 pages). Coloured
|
||||
Quake light comes from the map's `.lit` (`lit`, or `<map>.lit` through `files` / `resolve` with `name`). The BSP tree,
|
||||
the collision hulls (Quake 1 clipnodes, Quake II / III brushes) and the visibility data are tables in `meta.bsp`,
|
||||
with point queries on the format module:
|
||||
|
||||
```luau
|
||||
local Bsp = F.format("bsp")
|
||||
local map = assert(F.model.load(roomBspBytes))
|
||||
assert(map.meta.source.variant == "quake")
|
||||
local prim = map.meshes[1].primitives[1]
|
||||
assert(prim.attributes.TEXCOORD_1) -- lightmap coordinates
|
||||
local atlas = map.textures[map.materials[prim.material].extras.bsp.lightmap]
|
||||
assert(atlas.name == "lightmap" and atlas.image.width > 0)
|
||||
assert(Bsp.contents(map, -128, -128, 100) == -1) -- CONTENTS_EMPTY in the room
|
||||
assert(Bsp.contents(map, 0, 0, -8) == -2) -- CONTENTS_SOLID: the floor
|
||||
assert(Bsp.contents(map, -250, 0, 100, 1) == -2) -- hull 1 (player size) touches the wall
|
||||
local here = assert(Bsp.leafAt(map, -128, -128, 24))
|
||||
local seen = assert(Bsp.pvs(map, here)) -- leaves potentially visible from here
|
||||
assert(table.find(seen, Bsp.leafAt(map, 0, 0, 220)))
|
||||
assert(#map.meta.bsp.planes > 0 and #map.meta.bsp.clipnodes > 0)
|
||||
```
|
||||
|
||||
## Blitz3D (B3D)
|
||||
|
||||
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
|
||||
@@ -716,6 +943,144 @@ assert(back.meta.source.format == "iqm" and back.meshes[1].name == "tri")
|
||||
assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
```
|
||||
|
||||
## Blender (.blend)
|
||||
|
||||
`.blend` files load read only, from every Blender version since 2.4x: plain, gzip (before 3.0) or zstd (3.0+)
|
||||
compressed, 32 or 64-bit pointers, either byte order, and the 5.0+ header. Each file is read through its own SDNA (the
|
||||
struct catalogue Blender writes into every file), so fields are found by name whatever version wrote them. The
|
||||
current scene loads: objects (transforms with euler orders, quaternions, axis angles, delta transforms, the parent
|
||||
inverse, bone parents), collections as nodes (`collections = false` flattens them), meshes, materials, images,
|
||||
cameras, lights, armatures, skins, shape keys and actions. Blender is z-up (`meta.up = "z"`).
|
||||
|
||||
| Part | What loads |
|
||||
|---|---|
|
||||
| Meshes | every storage generation: MFace (before 2.63 and the 2.7x "legacy mesh format"), MPoly / MLoop (2.63 - 3.x), attribute layers (`position`, `.corner_vert`, ... 3.x - 4.x), AttributeStorage (5.x); a primitive per used material slot, `triangulate = false` keeps the faces (`"polygons"`) |
|
||||
| Mesh data | UV maps (`TEXCOORD_n`, v flipped to glTF's origin), colour attributes (byte and float, point and corner) as linear `COLOR_n`, corner normals from Blender's smooth fans (sharp edges / faces, auto smooth before 4.1) or the stored custom normals, weights (`JOINTS_0` / `WEIGHTS_0`: the 4 largest deform-bone groups, normalized) |
|
||||
| Materials | the Principled BSDF (base colour, metallic, roughness, alpha, emission and its strength, image textures on Base Color / Emission, Normal through a Normal Map node, Roughness / Metallic through Separate RGB), else the legacy `r, g, b` colour |
|
||||
| Images | packed images as encoded bytes (`texture.data`), external ones as `uri` (relative to the `.blend`, bytes through `files` / `resolve`) |
|
||||
| Cameras, lights | perspective (`yfov` from the lens, sensor fit and render aspect) / orthographic; point, sun, spot (watts to candela / lux as Blender's glTF exporter does); area lights are skipped (`meta.source.skippedLights`) |
|
||||
| Armatures | a joint node per bone (rest pose times the saved pose), one skin per deformed mesh |
|
||||
| Animation | the active action of each object, armature (pose bones) and shape key set, f-curves evaluated (constant, linear, bezier, easing; extrapolation) and sampled once per frame (`sampleStep`) into channels; time 0 is `meta.source.frameZero` at `meta.source.fps` |
|
||||
| Not loaded | modifiers (listed per object in `meta.source.modifiers`, never applied), curves, text, metaballs, grease pencil, volumes, NLA strips, drivers, constraints, linked libraries |
|
||||
|
||||
```luau
|
||||
local scene = assert(F.model.load(riggedBlendBytes))
|
||||
local src = scene.meta.source
|
||||
assert(src.format == "blend" and src.version >= 500 and src.compression == "zstd")
|
||||
assert(scene.meta.up == "z" and #scene.skins == 1 and #scene.animations == 1)
|
||||
local tube = scene.meshes[1].primitives[1]
|
||||
assert(tube.attributes.JOINTS_0 and tube.attributes.WEIGHTS_0 and #tube.targets == 1)
|
||||
assert(scene.materials[1].name == "Skin" and scene.materials[1].roughness > 0.69)
|
||||
print(src.modifiers.Tube[1].type) -- Armature (not applied)
|
||||
```
|
||||
|
||||
Anything else in the file is reachable through the container: `F.format("blend").open` parses the blocks and the
|
||||
SDNA, and every struct reads by field name (`get`, `num`, `str`, `vec`, `sub`, `deref`, `list` for ListBase, `array`
|
||||
and `pointers` behind pointers).
|
||||
|
||||
```luau
|
||||
local blend = F.format("blend")
|
||||
local file = assert(blend.open(F.Bytes.reader(riggedBlendBytes)))
|
||||
local Blend = blend.container
|
||||
for _, block in Blend.blocks(file, "OB") do
|
||||
local ob = assert(Blend.struct(file, block))
|
||||
print(ob:idName(), ob:num("type"), ob:vec("loc")[3]) -- Rig 25 0 / Tube 1 0
|
||||
end
|
||||
local arm = assert(Blend.struct(file, Blend.blocks(file, "AR")[1]))
|
||||
local bones = arm:list("bonebase")
|
||||
assert(bones[1]:str("name") == "lower" and bones[1]:list("childbase")[1]:str("name") == "upper")
|
||||
```
|
||||
|
||||
## 3ds Max ASCII export (ASE)
|
||||
|
||||
`.ase` files (`*3DSMAX_ASCIIEXPORT`) load as a Z-up scene: one node per geometry, helper, camera and light object,
|
||||
parented by `*NODE_PARENT`. ASE stores mesh vertices in world space; the reader moves them into the node's frame (the
|
||||
inverse `*NODE_TM`), so `Scene.flatten` puts them back where 3ds Max had them. Faces split into one primitive per
|
||||
sub-material of a Multi/Sub-Object material (`*MESH_MTLID`); each corner is its own vertex (texture channels,
|
||||
vertex colours and `*MESH_VERTEXNORMAL`s are per corner). Materials are Phong (the raw values in `extras`), bitmaps
|
||||
become textures with a `uri` (data through `opts.resolve`), UVW tiling / offset a texture transform. Camera FOVs
|
||||
stay the stored horizontal angle. `*TM_ANIMATION` tracks are not read (`meta.source.animated` says they exist).
|
||||
The writer puts every scene material in one Multi/Sub-Object material and writes world-space vertices.
|
||||
|
||||
```luau
|
||||
local scene = assert(F.load(aseText))
|
||||
assert(scene.meta.source.format == "ase" and scene.meta.up == "z")
|
||||
assert(#scene.materials == 2 and scene.materials[1].name == "Brick")
|
||||
local quad = scene.nodes[2]
|
||||
assert(quad.name == "Quad" and #scene.meshes[quad.mesh].primitives == 2)
|
||||
local tex = scene.textures[scene.materials[1].baseColorTexture.texture]
|
||||
assert(tex.uri == "textures\\brick.png")
|
||||
local again = assert(F.load(F.save(scene, nil, { format = "ase" })))
|
||||
assert(#again.meshes[again.nodes[2].mesh].primitives == 2)
|
||||
```
|
||||
|
||||
## Godot scenes (TSCN / ESCN)
|
||||
|
||||
Godot text scenes load as a Y-up Scene (one node per `[node]`, the scene root first), checked against Godot 4's own
|
||||
loader. Node3D transforms come from `transform = Transform3D(...)` (or `position` / `rotation` / `scale`); a
|
||||
MeshInstance3D gets its ArrayMesh sub-resource (Godot 4.2+ surfaces, and the `"arrays"` surfaces of Godot 3 / Blender
|
||||
`.escn` files) or its primitive mesh (Box, Plane, Quad, Sphere and Cylinder are built as Godot builds them), with
|
||||
`surface_material_override/N` applied. StandardMaterial3D / SpatialMaterial become PBR materials (Godot's sRGB
|
||||
albedo and emission converted to linear; the raw values in `material.extras.godot`); textures are `ExtResource`
|
||||
paths (`res://` dropped) with their bytes through `opts.resolve`. Camera3D (`fov` is vertical) and Omni / Spot /
|
||||
Directional lights map to cameras and lights (`intensity` = `light_energy`). Instanced scenes
|
||||
(`instance=ExtResource(...)`) are read through `opts.resolve` and grafted under their node. Godot's front faces are
|
||||
clockwise: indices are reversed into glTF's counter-clockwise winding (and back on save). Every node keeps its Godot
|
||||
type and raw properties in `node.extras.godot`, so 2D trees (Node2D, Sprite2D, Control) are kept there too.
|
||||
|
||||
```luau
|
||||
local scene = assert(F.load(tscnText, { resolve = function(path) return nil end }))
|
||||
assert(scene.meta.source.format == "godot" and scene.meta.up == "y")
|
||||
local box = scene.nodes[2]
|
||||
assert(box.name == "Box" and box.extras.godot.type == "MeshInstance3D")
|
||||
assert(box.matrix[13] == 2) -- Transform3D origin x
|
||||
local mat = scene.materials[scene.meshes[box.mesh].primitives[1].material]
|
||||
assert(mat.extras.godot.albedo[1] == 1 and mat.metallic == 0.5)
|
||||
assert(scene.cameras[1].type == "perspective" and math.abs(math.deg(scene.cameras[1].yfov) - 60) < 1e-9)
|
||||
local hud = scene.nodes[4]
|
||||
assert(hud.extras.godot.type == "Node2D" and hud.extras.godot.properties.position.args[1] == 10)
|
||||
local tscn = assert(F.saveString(scene, { format = "godot" })) -- Godot 4 text, format 3
|
||||
assert(string.find(tscn, '[node name="Box" type="MeshInstance3D" parent="."]', 1, true))
|
||||
```
|
||||
|
||||
The writer makes Node3D / MeshInstance3D / Camera3D / light nodes, ArrayMesh sub-resources (uncompressed format 2
|
||||
surfaces with positions, normals, tangents, colours, two UV sets) and StandardMaterial3D, plus a `Texture2D`
|
||||
`ext_resource` per texture with a `uri`. Skins, animations and morph targets are not written. Godot resources
|
||||
(`.tres`) are data: see [data.md](data.md).
|
||||
|
||||
## Unreal T3D
|
||||
|
||||
UnrealEd's text export (`.t3d`: `Begin Map` / `Begin Actor` / `Begin Brush` / `Begin PolyList` / `Begin Polygon`,
|
||||
UE1 to UE4) loads as a Scene in Unreal's own Z-up, left-handed coordinates (`meta.handedness = "left"`; nothing is
|
||||
mirrored). Every actor is a root node with its class, properties, CSG operation and components in
|
||||
`node.extras.t3d`; its matrix is the brush transform (PrePivot, MainScale, Rotation, PostScale, Location; rotations
|
||||
in 65536ths of a turn, or degrees in UE4 text) or the actor's Location / Rotation / DrawScale (UE4: the root
|
||||
component's `Relative*`). Brush polygons become one primitive per texture through `codecs/model/Brush`, with UVs from
|
||||
`TextureU` / `TextureV` / `Origin` / `Pan` divided by the texture size (`opts.textureSize`: a function or a
|
||||
`{ [name] = { w, h } }` table, default 256). Triangles wind counter-clockwise about each polygon's stored normal;
|
||||
subtractive brushes are turned inside out (a room is seen from within), the red builder brush is skipped unless
|
||||
`builder = true`. No BSP CSG is done: overlapping brushes stay separate meshes. Lights (UE1 hue / saturation /
|
||||
brightness, UE3-4 light components) and cameras map across; static mesh actors keep their mesh path in
|
||||
`extras.t3d.staticMesh`.
|
||||
|
||||
```luau
|
||||
local level = assert(F.load(t3dText, { textureSize = { Bricks = { 128, 64 }, Floor = { 256, 256 } } }))
|
||||
assert(level.meta.source.format == "t3d" and level.meta.up == "z")
|
||||
local room
|
||||
for _, n in level.nodes do
|
||||
if n.name == "Brush0" then
|
||||
room = n
|
||||
end
|
||||
end
|
||||
assert(room.extras.t3d.csg == "CSG_Subtract" and room.mesh)
|
||||
assert(room.matrix[13] == 64) -- Location X
|
||||
local names = {}
|
||||
for _, p in level.meshes[room.mesh].primitives do
|
||||
names[level.materials[p.material].name] = true
|
||||
end
|
||||
assert(names.Bricks and names.Floor)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -745,7 +1110,20 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
| X3D (XML / classic) | yes | yes | the VRML reader plus the X3D triangle / quad / line sets; no binary `.x3db` |
|
||||
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
|
||||
| MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above |
|
||||
| Build engine MAP (v7-9) | yes | yes | sloped sectors, walls, sprites as nodes, raw tables in `meta.build`; see "Build engine maps" above |
|
||||
| Source MDL (v44-49) + VVD / VTX / PHY | yes | - | skeleton, body parts, LODs, flexes, animations, VMT materials: see above |
|
||||
| MD2, MD3, MDL, MD5, BSP, VBSP | yes | - | game models and maps: see "Game models" above |
|
||||
| VMF | yes | yes (round trip, builders) | Hammer maps: see "Hammer maps (VMF)" above |
|
||||
| MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above; BSP lightmaps, hulls, PVS: "Quake maps" |
|
||||
| Quake / Half-Life / Quake II / Quake III `.map` | yes | yes | entities as nodes, brushes CSG'd, patches: see "Quake maps" |
|
||||
| SMD | yes | yes | Valve studiomdl data |
|
||||
| Doom 3 / Quake 4 `.proc` | yes | | render geometry per area, portals and BSP nodes as data |
|
||||
| Doom 3 / Quake 4 `.map` (d3map) | yes | | brushDef3, patchDef2 / 3, entities as nodes |
|
||||
| UDMF (`.udmf`, `TEXTMAP`) | yes | | Doom maps as text: see "Doom maps (UDMF)" above |
|
||||
| Blender `.blend` | yes | | 2.4x - 5.x, compressed; meshes of every generation, materials, skins, shape keys, actions; see "Blender" above |
|
||||
| Unreal T3D (`.t3d`) | yes | - | brushes as polygons per texture (no CSG), actors with properties, lights, cameras; Z up, left-handed |
|
||||
| Godot `.tscn` / `.escn` | yes | yes (`.tscn`) | Node3D trees, ArrayMesh and primitive meshes, StandardMaterial3D, cameras, lights, instances; 2D nodes in extras |
|
||||
| ASE (3ds Max ASCII) | yes | yes | Multi/Sub-Object materials, texture channels, vertex colours, normals, helpers, cameras, lights; no animation; Z up |
|
||||
| Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) |
|
||||
| Roblox `.rbxm` / `.rbxl`, `.rbxmx` / `.rbxlx` | as an `RbxTree` | yes | instance trees with typed properties: see [roblox.md](roblox.md) |
|
||||
|
||||
|
||||
+102
-2
@@ -1,4 +1,4 @@
|
||||
# Tile maps (Tiled TMX / TMJ)
|
||||
# Tile maps (Tiled, LDtk, Ogmo)
|
||||
|
||||
[Tiled](https://www.mapeditor.org) maps load as a `TileMap`: the map grid, its tilesets, and a list of layers
|
||||
(tile layers, object layers, image layers and groups) with Tiled's custom properties. The XML flavour (TMX) and the
|
||||
@@ -194,14 +194,114 @@ local back = assert(F.load(tmx))
|
||||
assert(back.layers[1].data[6] == 0x80000009)
|
||||
```
|
||||
|
||||
## Wolfenstein 3D maps
|
||||
|
||||
Wolfenstein 3D / Spear of Destiny maps are two files: `GAMEMAPS.WL6` (the Carmack + RLEW compressed planes) and
|
||||
`MAPHEAD.WL6` (the RLEW tag and where each map starts). Load either one: the other comes through `files` /
|
||||
`resolve` (loading a path finds it next to the file) or `mapHead` / `gameMaps`. A map loads as a TileMap with one
|
||||
tile layer per plane (`walls`, `objects`, `plane3`) holding the raw tile values (1..63 walls, 90..101 doors, 106+
|
||||
floor areas; things in `objects`), without a tileset; `map` picks the slot (default: the first present) and
|
||||
`F.format("gamemaps").maps` lists them.
|
||||
|
||||
```luau
|
||||
local files = { ["MAPHEAD.WL6"] = mapheadBytes }
|
||||
local level = assert(F.load(gamemapsBytes, { name = "GAMEMAPS.WL6", files = files }))
|
||||
assert(level.kind == "tilemap" and level.width == 16 and level.properties.name == "Tiny map")
|
||||
assert(level.layers[1].name == "walls" and level.layers[1].data[1] == 1) -- the border wall
|
||||
local maps = assert(F.format("gamemaps").maps(F.Bytes.reader(mapheadBytes), { gameMaps = gamemapsBytes }))
|
||||
assert(#maps == 1 and maps[1].slot == 1)
|
||||
```
|
||||
|
||||
## LDtk
|
||||
|
||||
[LDtk](https://ldtk.io) projects (`.ldtk`) load as a `TileMap` whose top layers are the **levels**: one `"group"`
|
||||
layer per level (`level = true`, `offsetX` / `offsetY` = its world position in pixels, `pxWidth` / `pxHeight`, the
|
||||
level fields as `properties`), holding the level's layers bottom first. Multi-world projects add one group per
|
||||
world (`world = true`) around its levels. External levels (`.ldtkl`) load through `opts.resolve(relPath)`; without
|
||||
it the level group has `unresolved = true` and no layers.
|
||||
|
||||
| LDtk layer | `TileLayer` |
|
||||
|---|---|
|
||||
| Tiles, AutoLayer | `type = "tiles"`, `tiles` (every tile: `x`, `y` pixels, `tile` id, `flip` bits, `srcX` / `srcY`, `alpha`), `data` (a gid grid of the top tile per cell), `tileset` |
|
||||
| IntGrid | the same plus `intGrid` (one value per cell, 0 = empty) and `intGridValues` (`{ value, identifier, color }`) |
|
||||
| Entities | `type = "objects"`: `class` = the entity identifier, `x` / `y` top-left (pixel position minus `pivot` x size), `width`, `height`, `pivot`, `tags`, `tile`, the fields as `properties` / `propertyTypes` (LDtk type names) |
|
||||
|
||||
Every layer also has `ldtkType` and `gridSize` (LDtk layers have their own cell size), and the raw LDtk tables
|
||||
(definitions, iids, uids, rules) ride along in `.ldtk` fields so a save keeps them. Gids are the tileset's
|
||||
`firstGid` plus the LDtk tile id, with LDtk's X / Y flips as Tiled's flip bits.
|
||||
|
||||
```luau
|
||||
local map = assert(F.load(ldtkText))
|
||||
assert(map.meta.source.format == "ldtk")
|
||||
local level = map.layers[1]
|
||||
assert(level.level and level.name == "Stamps" and level.pxWidth == 272)
|
||||
local walls = level.layers[1]
|
||||
assert(walls.ldtkType == "IntGrid" and walls.intGridValues[1].identifier == "walls")
|
||||
assert(#walls.tiles == 118 and map.tilesets[1].imageSource == "atlas/Inca_front_by_Kronbits-extended.png")
|
||||
local cx, cy = walls.tiles[1].x // walls.gridSize, walls.tiles[1].y // walls.gridSize
|
||||
assert(walls.data[1 + cx + cy * walls.width] ~= 0)
|
||||
```
|
||||
|
||||
Saving writes an LDtk project: maps read from LDtk keep their definitions and raw fields (changed `properties` get
|
||||
new `realEditorValues`, so the editor sees them); other maps (a Tiled map, a new `TileMap`) get layer, tileset and
|
||||
entity definitions made from their content, their loose layers forming one level. A tile layer writes its `tiles`
|
||||
list when it has one, else its `data` grid; set `tiles = nil` after editing `data`. Levels are always embedded.
|
||||
|
||||
```luau
|
||||
local map = F.Types.TileMap.new(2, 1, 16, 16)
|
||||
table.insert(map.tilesets, { name = "t", firstGid = 1, tileWidth = 16, tileHeight = 16, columns = 2, count = 4,
|
||||
imageSource = "t.png", imageWidth = 32, imageHeight = 32 })
|
||||
table.insert(map.layers, { type = "tiles", name = "Floor", width = 2, height = 1, visible = true, opacity = 1,
|
||||
properties = {}, data = { 1, 4 } })
|
||||
local ldtk = assert(F.save(map, nil, { format = "ldtk" }))
|
||||
local back = assert(F.load(ldtk))
|
||||
assert(back.layers[1].layers[1].tiles[2].tile == 3)
|
||||
```
|
||||
|
||||
## Ogmo Editor 3
|
||||
|
||||
[Ogmo Editor 3](https://ogmo-editor-3.github.io) keeps a project (`.ogmo`: layer definitions, entity templates,
|
||||
tilesets with their images embedded) and one JSON file per level. A level loads as a `TileMap`; pass its project as
|
||||
`opts.project` (bytes or decoded JSON) to get the tilesets (gids), the map grid, entity template sizes and value
|
||||
types. Without it tile layers keep `id + 1` as their gids. A project alone loads with `meta.project = true`, its
|
||||
tilesets and one empty layer per definition.
|
||||
|
||||
| Ogmo layer | `TileLayer` (`ogmoType`) |
|
||||
|---|---|
|
||||
| tile (ids or coords, 1D or 2D) | `"tiles"` (`"tile"`): `data` gids, `tileset`, the tile flags as Tiled flip bits |
|
||||
| grid | `"tiles"` (`"grid"`): `grid` (the cell strings, `"0"` empty), `data` (their numbers), `legend` |
|
||||
| entity | `"objects"` (`"entity"`): `x` / `y` top-left (position minus `originX` / `originY`), `width`, `height`, `rotation` in degrees, `flippedX` / `flippedY`, `nodes` (`{ { x, y } }`), values as `properties` |
|
||||
| decal | `"objects"` (`"decal"`): `texture`, `x` / `y`, `scaleX` / `scaleY`, `rotation` in degrees, `originX` / `originY` |
|
||||
|
||||
Ogmo's first layer is drawn on top, so the layers are reversed (bottom first, as everywhere in `TileMap`). Layers keep
|
||||
their cell size (`cellWidth`, `cellHeight`) and save layout (`exportMode`, `arrayMode`). Tileset images stay bytes
|
||||
(`tileset.imageData`, a PNG) next to their `imageSource` path.
|
||||
|
||||
```luau
|
||||
local map = assert(F.load(ogmoLevelText, { format = "ogmo", project = ogmoProjectText }))
|
||||
assert(map.pxWidth == 640 and map.tileWidth == 8) -- the project's grid
|
||||
local walls = map.layers[1]
|
||||
assert(walls.ogmoType == "tile" and walls.tileset == "tiles" and walls.width == 40)
|
||||
local things = map.layers[2]
|
||||
assert(things.objects[1].class == "player" and things.objects[1].x == 128)
|
||||
local level = assert(F.save(map, nil, { format = "ogmo" })) -- a level
|
||||
local project = assert(F.save(map, nil, { format = "ogmo", kind = "project" })) -- a project for any map
|
||||
assert(F.detect(project) == "ogmo")
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
|---|---|---|---|
|
||||
| TMX / TSX | yes | yes | CSV, base64 (raw, zlib, gzip) and `<tile>` data; zstd data returns `UNSUPPORTED` |
|
||||
| TMJ / TSJ | yes | yes | |
|
||||
| Wolfenstein 3D GAMEMAPS + MAPHEAD | yes | | the `gamemaps` format: raw tile values, no tileset |
|
||||
|
||||
Both are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped.
|
||||
TMX and TMJ are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped.
|
||||
| LDtk (`.ldtk`) | yes | yes | levels as groups, worlds, IntGrid / auto / tile / entity layers, fields; `.ldtkl` through `resolve`; writes embedded levels |
|
||||
| Ogmo Editor 3 (`.ogmo`, level `.json`) | yes | yes | tile / grid / entity / decal layers, values; the project through `opts.project` |
|
||||
|
||||
TMX and TMJ are both the `tiled` format in [FORMATS.md](../FORMATS.md) (Wang sets and terrains are dropped).
|
||||
|
||||
## Gotchas
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
| `tests/fixtures/pngsuite/` | PngSuite by Willem van Schaik | [PngSuite-LICENSE.txt](PngSuite-LICENSE.txt) |
|
||||
| `tests/fixtures/vox/{chr_knight,chr_sword,deer,maze}.vox`, `tests/fixtures/vox/MagicaVoxel-file-format-vox*.txt` (the format spec) | ephtracy/voxel-model (MagicaVoxel sample models) | MIT: [voxel-model-LICENSE.txt](voxel-model-LICENSE.txt) |
|
||||
| `tests/fixtures/vox/ogt_*.vox` | jpaver/opengametools `demo/vox/` (files saved by MagicaVoxel 0.99.x) | MIT: [opengametools-LICENSE.txt](opengametools-LICENSE.txt) |
|
||||
| `tests/fixtures/ogmo/{turnBasedRPG.ogmo,room-001.json}` | HaxeFlixel/flixel-demos `Tutorials/TurnBasedRPG/assets/data/` (an Ogmo Editor 3.3 project and level) | MIT: [flixel-demos-LICENSE.txt](flixel-demos-LICENSE.txt) |
|
||||
| `tests/fixtures/gltf/` | KhronosGroup/glTF-Sample-Assets `Models/` (one LICENSE.md per model folder; `UnicodeTest` is `Unicode❤♻Test` renamed) | CC-BY-4.0 or CC0-1.0 per model, see each folder's LICENSE.md |
|
||||
| `src/Rosetta/codecs/Vp8/` (Decode, Yuv, Tables), `src/Rosetta/codecs/Vp8L/Decode.luau`, `src/Rosetta/image/webp/` (Alpha unfilters, Anim.coalesce) | ports of libwebp 1.6.0 (Google): src/dec, src/dsp, src/utils, src/demux/anim_decode.c | BSD-3-Clause + patent grant: [libwebp-LICENSE.txt](libwebp-LICENSE.txt) |
|
||||
| `src/Rosetta/codecs/Tracker/`, `src/Rosetta/music/{mod,s3m,xm,it}/` | written for this library from the format documents: ProTracker 2.3 effect docs, the XM specification (Mr.H / Triton) and FT2 behaviour notes, ST3 TECH.DOC (Sami Tammilehto / Future Crew), ITTECH.TXT (Jeffrey Lim); OpenMPT (libopenmpt, BSD) was used only as the reference player in the tests, and its documented playback quirks (mix levels, MOD panning, FT2 E6x / tremor / instrument behaviour) are matched | no third-party code |
|
||||
@@ -58,6 +59,8 @@
|
||||
| `tests/gen/ldraw_*` (read at fixture time from the nix store, not committed) | LDraw.org Parts Library parts and sample models (complete.zip, as packaged for nixpkgs' LeoCAD) | CC BY 2.0 / CC BY 4.0, test data |
|
||||
| `src/Rosetta/codecs/image/Bcn/Decode.luau` (the BC1..BC7 block decoders and the BPTC tables; changed to follow the D3D11 rules) | Pillow 12 `src/libImaging/BcnDecode.c` | CC0 1.0: [pillow-bcn-CC0.txt](pillow-bcn-CC0.txt) |
|
||||
| `src/Rosetta/image/exr/Piz.luau`, `src/Rosetta/image/exr/Codec.luau` (the PIZ Huffman / wavelet / LUT steps and the ZIP / RLE byte predictor, re-implemented in Luau after the OpenEXR algorithms) | OpenEXR 3.x (ImfPizCompressor, ImfHuf, ImfWav, ImfZip, ImfRle) | BSD-3-Clause: [openexr-LICENSE.md](openexr-LICENSE.md) |
|
||||
| `src/Rosetta/model/godot/Primitives.luau` (BoxMesh, PlaneMesh, QuadMesh, SphereMesh, CylinderMesh generation, ported to Luau without UV2) | Godot Engine 4.4 `scene/resources/3d/primitive_meshes.cpp` | MIT: [godot-LICENSE.txt](godot-LICENSE.txt) |
|
||||
| `src/Rosetta/codecs/audio/Aac/Sbr.luau`, `SbrHf.luau`, `Ps.luau`, `SbrTables.luau` (HE-AAC SBR / PS: the bitstream, band tables, HF generation and adjustment, the PS hybrid filterbank / decorrelator / mixing, ported to Luau; the QMF banks are new) | syom 0.8.1 `src/engine/sbr_*.rs`, `ps_*.rs` (Evgeny Khodzitsky; its tables are ISO/IEC 14496-3 numbers) | MIT: [syom-LICENSE.txt](syom-LICENSE.txt) |
|
||||
|
||||
Ports of third-party code (minimp3, stb_vorbis, libopus, ...) add a row here and their upstream licence text in this
|
||||
folder (see docs/STYLE.md, "Absorbing an existing repo").
|
||||
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md).
|
||||
Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Evgeny Khodzitsky
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+304
-4
@@ -26,6 +26,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/image/ani")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "art",
|
||||
category = "image",
|
||||
path = "image/art",
|
||||
extensions = { "art" },
|
||||
mime = { "image/x-build-art" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/image/Pixels", "codecs/image/Quantize" },
|
||||
caps = { decode = true, encode = true, alpha = true, palette = true, frames = true, depths = { 8 } },
|
||||
load = function()
|
||||
return require("@rosetta/image/art")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "blp",
|
||||
category = "image",
|
||||
@@ -158,6 +170,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/image/ktx")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "lmp",
|
||||
category = "image",
|
||||
path = "image/lmp",
|
||||
extensions = { "lmp" },
|
||||
mime = { "image/x-quake-lmp" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex" },
|
||||
caps = { decode = true, encode = true, alpha = true, depths = { 8 }, variants = { "qpic", "palette", "colormap" } },
|
||||
load = function()
|
||||
return require("@rosetta/image/lmp")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "pcx",
|
||||
category = "image",
|
||||
@@ -218,6 +242,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/image/sgi")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "spr",
|
||||
category = "image",
|
||||
path = "image/spr",
|
||||
extensions = { "spr" },
|
||||
mime = { "image/x-quake-sprite" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex" },
|
||||
caps = { decode = true, encode = true, alpha = true, animation = true, variants = { "quake", "halflife", "spr32" } },
|
||||
load = function()
|
||||
return require("@rosetta/image/spr")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "sunras",
|
||||
category = "image",
|
||||
@@ -722,6 +758,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/3mf")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "ase",
|
||||
category = "model",
|
||||
path = "model/ase",
|
||||
extensions = { "ase", "ask" },
|
||||
mime = { "model/x-ase", "text/plain" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" },
|
||||
caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/ase")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "b3d",
|
||||
category = "model",
|
||||
@@ -734,18 +782,54 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/b3d")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "blend",
|
||||
category = "model",
|
||||
path = "model/blend",
|
||||
extensions = { "blend" },
|
||||
mime = { "application/x-blender" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Blend", "codecs/compress/Deflate", "codecs/compress/Zstd", "codecs/model/Mat4", "codecs/model/Rig", "codecs/model/Polygon" },
|
||||
caps = { decode = true, encode = false, materials = true, textures = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true, polygons = true, compressed = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/blend")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "bsp",
|
||||
category = "model",
|
||||
path = "model/bsp",
|
||||
extensions = { "bsp" },
|
||||
mime = { "model/x-bsp" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" },
|
||||
caps = { decode = true, encode = false, variants = { "quake", "bsp2", "2psb", "halflife", "quake2", "quake3" }, lightmaps = true, collision = true, visibility = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/bsp")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "buildmap",
|
||||
category = "model",
|
||||
path = "model/buildmap",
|
||||
extensions = { "map" },
|
||||
mime = { "application/x-build-map" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Polygon" },
|
||||
caps = { decode = true, encode = true, sprites = true, slopes = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/buildmap")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "d3map",
|
||||
category = "model",
|
||||
path = "model/d3map",
|
||||
extensions = { "map" },
|
||||
mime = { "text/x-doom3-map" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/Brush", "codecs/model/Patch", "codecs/model/Mat4", "codecs/text/Lexer" },
|
||||
caps = { decode = true, encode = false, patches = true, variants = { "doom3", "quake4" } },
|
||||
load = function()
|
||||
return require("@rosetta/model/d3map")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "dae",
|
||||
category = "model",
|
||||
@@ -782,6 +866,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/gltf")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "godot",
|
||||
category = "model",
|
||||
path = "model/godot",
|
||||
extensions = { "tscn", "escn" },
|
||||
mime = { "application/x-godot-scene" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" },
|
||||
caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/godot")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "iqm",
|
||||
category = "model",
|
||||
@@ -818,6 +914,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/lwo")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "map",
|
||||
category = "model",
|
||||
path = "model/map",
|
||||
extensions = { "map" },
|
||||
mime = { "text/x-quake-map" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" },
|
||||
caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/map")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "mca",
|
||||
category = "model",
|
||||
@@ -872,7 +980,7 @@ local list: { Entry } = {
|
||||
path = "model/mdl",
|
||||
extensions = { "mdl" },
|
||||
mime = { "model/x-mdl" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/model/Mat4", "codecs/model/Rig" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/model/Mat4", "codecs/model/Rig", "codecs/model/SourceAnim" },
|
||||
caps = { decode = true, encode = false, variants = { "quake", "halflife" }, morph = true, skins = true, animation = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/mdl")
|
||||
@@ -938,6 +1046,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/pmx")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "proc",
|
||||
category = "model",
|
||||
path = "model/proc",
|
||||
extensions = { "proc" },
|
||||
mime = { "model/x-doom3-proc" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Lexer" },
|
||||
caps = { decode = true, encode = false, portals = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/proc")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "qb",
|
||||
category = "model",
|
||||
@@ -1010,6 +1130,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/smd")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "sourcemdl",
|
||||
category = "model",
|
||||
path = "model/sourcemdl",
|
||||
extensions = { "mdl" },
|
||||
mime = { "model/x-source-mdl" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Half", "codecs/model/Mat4", "codecs/model/Rig", "codecs/model/SourceAnim", "codecs/text/KeyValues" },
|
||||
caps = { decode = true, encode = false, skins = true, morph = true, animation = true, lods = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/sourcemdl")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "stl",
|
||||
category = "model",
|
||||
@@ -1022,6 +1154,30 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/stl")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "t3d",
|
||||
category = "model",
|
||||
path = "model/t3d",
|
||||
extensions = { "t3d" },
|
||||
mime = { "text/x-unreal-t3d" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" },
|
||||
caps = { decode = true, encode = false, text = true, brushes = true, actors = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/t3d")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "udmf",
|
||||
category = "model",
|
||||
path = "model/udmf",
|
||||
extensions = { "udmf", "textmap" },
|
||||
mime = { "text/x-udmf" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = false, maps = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/udmf")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "usda",
|
||||
category = "model",
|
||||
@@ -1034,6 +1190,30 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/usda")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "vbsp",
|
||||
category = "model",
|
||||
path = "model/vbsp",
|
||||
extensions = { "bsp" },
|
||||
mime = { "model/x-vbsp" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Lzma", "codecs/text/KeyValues", "codecs/model/Mat4", "codecs/model/Displacement", "containers/Zip", "containers/Archive" },
|
||||
caps = { decode = true, encode = false, versions = { 19, 20, 21 }, displacements = true, staticProps = true, pak = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/vbsp")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "vmf",
|
||||
category = "model",
|
||||
path = "model/vmf",
|
||||
extensions = { "vmf", "vmx" },
|
||||
mime = { "model/x-vmf" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "core/Sniff", "Types", "codecs/text/KeyValues", "codecs/model/Brush", "codecs/model/Displacement", "codecs/model/Mat4" },
|
||||
caps = { decode = true, encode = true, displacements = true, roundTrip = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/vmf")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "vox",
|
||||
category = "model",
|
||||
@@ -1490,6 +1670,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/archive/tar")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "unitypackage",
|
||||
category = "archive",
|
||||
path = "archive/unitypackage",
|
||||
extensions = { "unitypackage" },
|
||||
mime = { "application/x-unitypackage" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" },
|
||||
caps = { decode = true, encode = true },
|
||||
load = function()
|
||||
return require("@rosetta/archive/unitypackage")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "uu",
|
||||
category = "archive",
|
||||
@@ -1514,18 +1706,42 @@ local list: { Entry } = {
|
||||
return require("@rosetta/archive/vpk")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "vswap",
|
||||
category = "archive",
|
||||
path = "archive/vswap",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm", "vswap" },
|
||||
mime = { "application/x-wolf3d-vswap" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = false, images = true, sounds = true },
|
||||
load = function()
|
||||
return require("@rosetta/archive/vswap")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "wad",
|
||||
category = "archive",
|
||||
path = "archive/wad",
|
||||
extensions = { "wad" },
|
||||
mime = { "application/x-doom" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/Polygon" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = true, images = true, maps = true, variants = { "iwad", "pwad" } },
|
||||
load = function()
|
||||
return require("@rosetta/archive/wad")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "wad2",
|
||||
category = "archive",
|
||||
path = "archive/wad2",
|
||||
extensions = { "wad" },
|
||||
mime = { "application/x-quake-wad" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/image/Miptex" },
|
||||
caps = { decode = true, encode = true, images = true, variants = { "wad2", "wad3" } },
|
||||
load = function()
|
||||
return require("@rosetta/archive/wad2")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "xz",
|
||||
category = "archive",
|
||||
@@ -1682,6 +1898,30 @@ local list: { Entry } = {
|
||||
return require("@rosetta/data/plist")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "q3shader",
|
||||
category = "data",
|
||||
path = "data/q3shader",
|
||||
extensions = { "shader" },
|
||||
mime = { "text/x-quake3-shader" },
|
||||
deps = { "core/Err", "core/Bytes" },
|
||||
caps = { decode = true, encode = true },
|
||||
load = function()
|
||||
return require("@rosetta/data/q3shader")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "q3skin",
|
||||
category = "data",
|
||||
path = "data/q3skin",
|
||||
extensions = { "skin" },
|
||||
mime = { "text/x-quake3-skin" },
|
||||
deps = { "core/Err", "core/Bytes" },
|
||||
caps = { decode = true, encode = true },
|
||||
load = function()
|
||||
return require("@rosetta/data/q3skin")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "snbt",
|
||||
category = "data",
|
||||
@@ -1706,6 +1946,30 @@ local list: { Entry } = {
|
||||
return require("@rosetta/data/toml")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "tres",
|
||||
category = "data",
|
||||
path = "data/tres",
|
||||
extensions = { "tres" },
|
||||
mime = { "application/x-godot-resource" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" },
|
||||
caps = { decode = true, encode = true, ordered = true },
|
||||
load = function()
|
||||
return require("@rosetta/data/tres")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "vdf",
|
||||
category = "data",
|
||||
path = "data/vdf",
|
||||
extensions = { "vdf", "acf", "res", "kv" },
|
||||
mime = { "text/x-vdf" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "codecs/text/KeyValues" },
|
||||
caps = { decode = true, encode = true, ordered = true, binary = true },
|
||||
load = function()
|
||||
return require("@rosetta/data/vdf")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "xml",
|
||||
category = "data",
|
||||
@@ -1730,6 +1994,42 @@ local list: { Entry } = {
|
||||
return require("@rosetta/data/yaml")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "gamemaps",
|
||||
category = "vector",
|
||||
path = "vector/gamemaps",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm" },
|
||||
mime = { "application/x-wolf3d-gamemaps" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types" },
|
||||
caps = { decode = true, encode = false, tilemap = true },
|
||||
load = function()
|
||||
return require("@rosetta/vector/gamemaps")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "ldtk",
|
||||
category = "vector",
|
||||
path = "vector/ldtk",
|
||||
extensions = { "ldtk" },
|
||||
mime = { "application/x-ldtk+json" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" },
|
||||
caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true },
|
||||
load = function()
|
||||
return require("@rosetta/vector/ldtk")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "ogmo",
|
||||
category = "vector",
|
||||
path = "vector/ogmo",
|
||||
extensions = { "ogmo" },
|
||||
mime = { "application/x-ogmo+json" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" },
|
||||
caps = { decode = true, encode = true, projects = true, entities = true, decals = true },
|
||||
load = function()
|
||||
return require("@rosetta/vector/ogmo")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "svg",
|
||||
category = "vector",
|
||||
|
||||
+43
-13
@@ -652,23 +652,47 @@ Types.null = table.freeze(setmetatable({}, nullMeta))
|
||||
-- Objects (maps) whose key order matters, and empty objects (which would otherwise read back as empty arrays), carry
|
||||
-- an "object" metatable with their key order. Decoders mark empty objects always and every object when asked
|
||||
-- (opts.ordered); encoders write an object's keys in that order (keys added later, or plain tables: sorted).
|
||||
local OBJECT = { __object = true }
|
||||
-- The key order is the __keys field of the object's own metatable, or (for a table that came with a metatable of its
|
||||
-- own) an entry in a weak map.
|
||||
local objectMeta: { [any]: { any } } = setmetatable({}, { __mode = "k" }) :: any -- object -> its key order
|
||||
local function orderOf(v: any): { any }?
|
||||
local mt: any = getmetatable(v)
|
||||
if type(mt) == "table" then
|
||||
local k: any = rawget(mt, "__keys")
|
||||
if k ~= nil then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return objectMeta[v]
|
||||
end
|
||||
local NOKEYS: { any } = table.freeze({}) :: any
|
||||
function Types.object(t: { [any]: any }?, keys: { any }?): { [any]: any }
|
||||
local o: { [any]: any } = t or {}
|
||||
if getmetatable(o) == nil then
|
||||
setmetatable(o, OBJECT)
|
||||
local k: { any } = keys or NOKEYS
|
||||
local mt: any = getmetatable(o)
|
||||
if mt == nil or (type(mt) == "table" and rawget(mt, "__keys") ~= nil) then
|
||||
setmetatable(o, { __object = true, __keys = k })
|
||||
else
|
||||
objectMeta[o] = k
|
||||
end
|
||||
objectMeta[o] = keys or {}
|
||||
return o
|
||||
end
|
||||
function Types.isObject(v: any): boolean
|
||||
return type(v) == "table" and objectMeta[v] ~= nil
|
||||
return type(v) == "table" and orderOf(v) ~= nil
|
||||
end
|
||||
function Types.set(o: { [any]: any }, k: any, v: any)
|
||||
local order = objectMeta[o]
|
||||
local order = orderOf(o)
|
||||
if order and o[k] == nil and v ~= nil then
|
||||
table.insert(order, k)
|
||||
if order == NOKEYS then
|
||||
local mt: any = getmetatable(o)
|
||||
if type(mt) == "table" and rawget(mt, "__keys") == NOKEYS then
|
||||
mt.__keys = { k }
|
||||
else
|
||||
objectMeta[o] = { k }
|
||||
end
|
||||
else
|
||||
table.insert(order, k)
|
||||
end
|
||||
end
|
||||
o[k] = v
|
||||
end
|
||||
@@ -702,25 +726,31 @@ function Types.isArray(t: { [any]: any }, emptyIsMap: boolean?): boolean
|
||||
return c == n
|
||||
end
|
||||
function Types.keys(t: { [any]: any }): { any }
|
||||
local order = objectMeta[t]
|
||||
local order = orderOf(t)
|
||||
local out, seen = {}, {}
|
||||
local n = 0
|
||||
if order then
|
||||
for _, k in order do
|
||||
if t[k] ~= nil and not seen[k] then
|
||||
seen[k] = true
|
||||
table.insert(out, k)
|
||||
n += 1
|
||||
out[n] = k
|
||||
end
|
||||
end
|
||||
end
|
||||
local rest = {}
|
||||
local rest: { any }? = nil
|
||||
for k in next, t do
|
||||
if not seen[k] then
|
||||
table.insert(rest, k)
|
||||
if rest then
|
||||
table.insert(rest, k)
|
||||
else
|
||||
rest = { k }
|
||||
end
|
||||
end
|
||||
end
|
||||
if #rest > 0 then
|
||||
if rest then
|
||||
table.sort(rest, keyLess)
|
||||
table.move(rest, 1, #rest, #out + 1, out)
|
||||
table.move(rest, 1, #rest, n + 1, out)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
--!strict
|
||||
-- archive/unitypackage: Unity asset packages, a gzip'd tar of <guid>/asset, <guid>/asset.meta, <guid>/pathname
|
||||
-- (+ preview.png), read + write as an Archive keyed by the asset paths (Assets/...), each .meta next to its asset as
|
||||
-- in a Unity project. Supports: folders (meta only), lazy entries, guids kept (entry.guid) or made from the path.
|
||||
-- Not supported: pre-5.x packages without pathname files.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Md5 = require("@rosetta/core/Md5")
|
||||
local Deflate = require("@rosetta/codecs/compress/Deflate")
|
||||
local Archive = require("@rosetta/containers/Archive")
|
||||
local Tar = require("@rosetta/containers/Tar")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local UnityPackage = {
|
||||
name = "unitypackage",
|
||||
category = "archive",
|
||||
extensions = { "unitypackage" },
|
||||
mime = { "application/x-unitypackage" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" },
|
||||
caps = { decode = true, encode = true },
|
||||
}
|
||||
|
||||
export type DecodeOptions = {
|
||||
maxEntries: number?, -- default 1e6
|
||||
maxBytes: number?, -- inflated size, default 2^31
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
level: number?, -- deflate 0..9, default 6
|
||||
mtime: number?, -- tar entry time, default 0
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
local function guidOf(name: string): (string?, string?)
|
||||
local n = string.gsub(name, "^%./", "")
|
||||
local guid, rest = string.match(n, "^(%x+)/?(.*)$")
|
||||
if guid and #guid == 32 then
|
||||
return string.lower(guid), rest
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function UnityPackage.sniff(r: Bytes.Reader): number
|
||||
if r:peek(3) ~= "\31\139\8" then
|
||||
return 0
|
||||
end
|
||||
local head = Deflate.peek(r.buf, r.pos, r.limit - r.pos, 512)
|
||||
if not head or buffer.len(head) < 512 or not Tar.valid(head, 0) then
|
||||
return 0
|
||||
end
|
||||
local z = 0
|
||||
while z < 100 and buffer.readu8(head, z) ~= 0 do
|
||||
z += 1
|
||||
end
|
||||
return if guidOf(buffer.readstring(head, 0, z)) then 1 else 0 -- ties with archive/gzip go to the extension
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
local function encode(archive: any, opts: any?): (buffer?, Err.Err?)
|
||||
return UnityPackage.encode(archive, opts)
|
||||
end
|
||||
|
||||
type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry?, [string]: any }
|
||||
|
||||
local function text(b: buffer, e: Tar.Entry): string
|
||||
return buffer.readstring(b, e.offset, e.size)
|
||||
end
|
||||
|
||||
function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
local o: DecodeOptions = opts or {}
|
||||
local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base)
|
||||
if not tar then
|
||||
return nil, err
|
||||
end
|
||||
if buffer.len(tar) > (o.maxBytes or 2 ^ 31) then
|
||||
return nil, Err.new(Err.LIMIT, "inflated size over the byte limit")
|
||||
end
|
||||
local list, terr = Tar.read(tar, 0, buffer.len(tar), { maxEntries = o.maxEntries })
|
||||
if not list then
|
||||
return nil, terr
|
||||
end
|
||||
local byGuid: { [string]: Asset } = {}
|
||||
local order: { string } = {}
|
||||
for _, e in list do
|
||||
local guid, rest = guidOf(e.name)
|
||||
if guid and not e.dir then
|
||||
local a = byGuid[guid]
|
||||
if not a then
|
||||
a = {} :: Asset
|
||||
byGuid[guid] = a
|
||||
table.insert(order, guid)
|
||||
end
|
||||
if rest == "asset" then
|
||||
a.asset = e
|
||||
elseif rest == "asset.meta" then
|
||||
a.meta = e
|
||||
elseif rest == "pathname" then
|
||||
a.pathname = e
|
||||
elseif rest == "preview.png" then
|
||||
a.preview = e
|
||||
end
|
||||
end
|
||||
end
|
||||
local arc = Archive.new("unitypackage", encode)
|
||||
local skipped = 0
|
||||
for _, guid in order do
|
||||
local a = byGuid[guid]
|
||||
local pn = a.pathname
|
||||
if not pn then
|
||||
skipped += 1
|
||||
else
|
||||
-- the first line is the path (Unity 5+ may add a second line, e.g. "00")
|
||||
local path = string.match(text(tar, pn), "^[^\r\n]*") or ""
|
||||
path = string.gsub(path, "\\", "/")
|
||||
if path ~= "" then
|
||||
local asset, meta = a.asset, a.meta
|
||||
local isDir = asset == nil
|
||||
Archive.put(arc, {
|
||||
name = path,
|
||||
size = if asset then asset.size else 0,
|
||||
dir = isDir,
|
||||
mtime = if asset then asset.mtime elseif meta then meta.mtime else nil,
|
||||
method = "deflate",
|
||||
guid = guid,
|
||||
load = if asset and asset.size > 0 then Archive.slice(tar, asset.offset, asset.size) else nil,
|
||||
preview = if a.preview then Archive.slice(tar, a.preview.offset, a.preview.size) else nil,
|
||||
})
|
||||
if meta then
|
||||
Archive.put(arc, {
|
||||
name = path .. ".meta",
|
||||
size = meta.size,
|
||||
dir = false,
|
||||
mtime = meta.mtime,
|
||||
method = "deflate",
|
||||
guid = guid,
|
||||
load = if meta.size > 0 then Archive.slice(tar, meta.offset, meta.size) else nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
arc.meta.source = { format = "unitypackage", assets = #order - skipped, skipped = if skipped > 0 then skipped else nil }
|
||||
return arc, nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
local function metaGuid(b: buffer): string?
|
||||
local s = buffer.readstring(b, 0, math.min(buffer.len(b), 4096))
|
||||
local g = string.match(s, "\nguid:%s*(%x+)") or string.match(s, "^guid:%s*(%x+)")
|
||||
if g and #g == 32 then
|
||||
return string.lower(g)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function defaultMeta(guid: string, dir: boolean): string
|
||||
if dir then
|
||||
return "fileFormatVersion: 2\nguid: " .. guid .. "\nfolderAsset: yes\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n"
|
||||
end
|
||||
return "fileFormatVersion: 2\nguid: " .. guid .. "\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n"
|
||||
end
|
||||
|
||||
function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local o: EncodeOptions = opts or {}
|
||||
local items = Archive.entries(archive)
|
||||
if not items then
|
||||
return nil, Err.new(Err.ARG, "expected an Archive")
|
||||
end
|
||||
local byName: { [string]: any } = {}
|
||||
for _, it in items do
|
||||
byName[string.gsub(it.entry.name, "\\", "/")] = it
|
||||
end
|
||||
local mtime = o.mtime or 0
|
||||
local list: { Tar.WriteEntry } = {}
|
||||
local used: { [string]: boolean } = {}
|
||||
for _, it in items do
|
||||
local e: any = it.entry
|
||||
local path = string.gsub((string.gsub(e.name, "\\", "/")), "/+$", "")
|
||||
local metaIt = byName[path .. ".meta"]
|
||||
local isMeta = string.sub(path, -5) == ".meta" and byName[string.sub(path, 1, -6)] ~= nil
|
||||
if path ~= "" and not isMeta then
|
||||
local data: buffer? = nil
|
||||
if not e.dir then
|
||||
local b, rerr = it.read()
|
||||
if not b then
|
||||
return nil, rerr
|
||||
end
|
||||
data = b
|
||||
end
|
||||
local metaData: buffer? = nil
|
||||
if metaIt then
|
||||
local mb, merr = metaIt.read()
|
||||
if not mb then
|
||||
return nil, merr
|
||||
end
|
||||
metaData = mb
|
||||
end
|
||||
local given: string? = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil
|
||||
local g: string = given or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path))
|
||||
if used[g] then
|
||||
g = Md5.of(buffer.fromstring(path .. "\0" .. g))
|
||||
end
|
||||
used[g] = true
|
||||
metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true))
|
||||
table.insert(list, { name = g .. "/", dir = true, mtime = mtime })
|
||||
if data then
|
||||
table.insert(list, { name = g .. "/asset", data = data, mtime = mtime })
|
||||
end
|
||||
table.insert(list, { name = g .. "/asset.meta", data = metaData, mtime = mtime })
|
||||
table.insert(list, { name = g .. "/pathname", data = buffer.fromstring(path), mtime = mtime })
|
||||
if type(e.preview) == "function" then
|
||||
local ok, pb = pcall(e.preview)
|
||||
if ok and type(pb) == "buffer" then
|
||||
table.insert(list, { name = g .. "/preview.png", data = pb, mtime = mtime })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local tar, terr = Tar.write(list, { format = "ustar" })
|
||||
if not tar then
|
||||
return nil, terr
|
||||
end
|
||||
return Deflate.gzip(tar, { level = o.level or 6 })
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
function UnityPackage.new(): any
|
||||
local a = Archive.new("unitypackage", encode)
|
||||
a.meta.source = { format = "unitypackage" }
|
||||
return a
|
||||
end
|
||||
|
||||
return UnityPackage
|
||||
@@ -0,0 +1,268 @@
|
||||
--!strict
|
||||
-- archive/vswap: Wolfenstein 3D / Spear of Destiny page files (VSWAP.WL1 / .WL6 / .SOD / .SDM: u16 chunks, sprite
|
||||
-- start, sound start; u32 offsets, u16 lengths; ModdingWiki "VSWAP Format", no code taken), read only. Pages load as
|
||||
-- entries walls/NNN, sprites/NNN, sounds/NNN and soundinfo; Vswap.image turns walls (64 x 64 column-major) and
|
||||
-- sprites (t_compshape posts) into Images through a palette passed in (the game's palette is not redistributable),
|
||||
-- Vswap.sound the digitized sounds into Audio (u8 PCM, 7042 Hz). Not supported: writing, Blake Stone / Corridor 7.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Archive = require("@rosetta/containers/Archive")
|
||||
local Pixels = require("@rosetta/codecs/image/Pixels")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Vswap = {
|
||||
name = "vswap",
|
||||
category = "archive",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm", "vswap" },
|
||||
mime = { "application/x-wolf3d-vswap" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = false, images = true, sounds = true },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = { maxChunks: number? } -- default 65535
|
||||
export type ImageOptions = {
|
||||
palette: (buffer | string)?, -- 768 bytes RGB (6-bit VGA values are scaled up when no byte is above 63); default grey
|
||||
sixBit: boolean?, -- force the 6-bit reading of the palette
|
||||
}
|
||||
export type Page = { kind: "wall" | "sprite" | "sound" | "soundinfo", index: number, offset: number, size: number }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local readu8, readu16, readi16, writeu32 = buffer.readu8, buffer.readu16, buffer.readi16, buffer.writeu32
|
||||
local SAMPLE_RATE = 7042 -- the digitized sounds' rate (wolf4sdl ORIGSAMPLERATE)
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
local function header(r: Bytes.Reader): (number?, number, number)
|
||||
if r:remaining() < 6 then
|
||||
return nil, 0, 0
|
||||
end
|
||||
local n, ss, so = readu16(r.buf, r.base), readu16(r.buf, r.base + 2), readu16(r.buf, r.base + 4)
|
||||
if n == 0 or ss > so or so > n or 6 + n * 6 > r:remaining() then
|
||||
return nil, 0, 0
|
||||
end
|
||||
return n, ss, so
|
||||
end
|
||||
|
||||
function Vswap.sniff(r: Bytes.Reader): number
|
||||
local n = header(r)
|
||||
if not n then
|
||||
return 0
|
||||
end
|
||||
local size = r.limit - r.base
|
||||
local b = r.buf
|
||||
local last = 6 + n * 6
|
||||
local nonzero = 0
|
||||
for i = 0, n - 1 do
|
||||
local o = buffer.readu32(b, r.base + 6 + i * 4)
|
||||
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
|
||||
if o ~= 0 then
|
||||
if o < last or o + l > size then
|
||||
return 0
|
||||
end
|
||||
last = o
|
||||
nonzero += 1
|
||||
end
|
||||
end
|
||||
return if nonzero > 0 then 0.6 else 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
function Vswap.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
if r:remaining() < 6 then
|
||||
return nil, Err.new(Err.TRUNCATED, "header", 0)
|
||||
end
|
||||
local n, ss, so = header(r)
|
||||
if not n then
|
||||
return nil, Err.new(if 6 + readu16(r.buf, r.base) * 6 > r:remaining() then Err.TRUNCATED else Err.CORRUPT, "bad page directory", 0)
|
||||
end
|
||||
if n > (opts and opts.maxChunks or 65535) then
|
||||
return nil, Err.new(Err.LIMIT, "too many pages: " .. n)
|
||||
end
|
||||
local size = r.limit - r.base
|
||||
local b = r.buf
|
||||
local a = Archive.new("vswap")
|
||||
local pages: { Page } = {}
|
||||
local counts: { [string]: number } = { wall = 0, sprite = 0, sound = 0 }
|
||||
for i = 0, n - 1 do
|
||||
local o = buffer.readu32(b, r.base + 6 + i * 4)
|
||||
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
|
||||
if o == 0 then
|
||||
l = 0 -- a sparse page (Spear of Destiny)
|
||||
elseif o + l > size then
|
||||
return nil, Err.new(Err.TRUNCATED, "page " .. i .. " past the end", 6 + i * 4)
|
||||
end
|
||||
local kind: string, idx: number = "sound", i - so
|
||||
if i < ss then
|
||||
kind, idx = "wall", i
|
||||
elseif i < so then
|
||||
kind, idx = "sprite", i - ss
|
||||
elseif i == n - 1 and so < n then
|
||||
kind, idx = "soundinfo", 0
|
||||
end
|
||||
local name = if kind == "soundinfo" then "soundinfo" else kind .. "s/" .. string.format("%03d", idx)
|
||||
if kind ~= "soundinfo" then
|
||||
counts[kind] += 1
|
||||
end
|
||||
table.insert(pages, { kind = kind :: any, index = idx, offset = o, size = l })
|
||||
Archive.put(a, { name = name, size = l, dir = false, method = "store", page = i, kind = kind, load = Archive.slice(b, r.base + o, l) })
|
||||
end
|
||||
a.meta.source = { format = "vswap", chunks = n, spriteStart = ss, soundStart = so, walls = counts.wall, sprites = counts.sprite, soundPages = counts.sound }
|
||||
a.meta.vswap = { pages = pages, buf = b, base = r.base, spriteStart = ss, soundStart = so }
|
||||
return a, nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
local function info(a: any): any
|
||||
return type(a) == "table" and type(a.meta) == "table" and a.meta.vswap or nil
|
||||
end
|
||||
|
||||
local function palette(opts: ImageOptions?): (buffer, boolean)
|
||||
local p = opts and opts.palette
|
||||
if p == nil then
|
||||
local g = buffer.create(768)
|
||||
for i = 0, 255 do
|
||||
buffer.fill(g, i * 3, i, 3)
|
||||
end
|
||||
return Pixels.palette(g, 0, 256), false
|
||||
end
|
||||
local src = if type(p) == "string" then buffer.fromstring(p) else p
|
||||
local n = math.min(buffer.len(src), 768)
|
||||
local six = opts and opts.sixBit
|
||||
if six == nil then
|
||||
six = true
|
||||
for i = 0, n - 1 do
|
||||
if readu8(src, i) > 63 then
|
||||
six = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if six then
|
||||
local s = buffer.create(768)
|
||||
for i = 0, n - 1 do
|
||||
local v = bit32.band(readu8(src, i), 63)
|
||||
buffer.writeu8(s, i, bit32.bor(bit32.lshift(v, 2), bit32.rshift(v, 4)))
|
||||
end
|
||||
src = s
|
||||
end
|
||||
return Pixels.palette(src, 0, n // 3), true
|
||||
end
|
||||
|
||||
function Vswap.pages(a: any): { Page }?
|
||||
local v = info(a)
|
||||
return v and v.pages
|
||||
end
|
||||
|
||||
function Vswap.image(a: any, kind: "wall" | "sprite", index: number, opts: ImageOptions?): (Types.Image?, Err.Err?)
|
||||
local v = info(a)
|
||||
if not v then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded VSWAP archive")
|
||||
end
|
||||
local page: Page? = nil
|
||||
for _, p in v.pages do
|
||||
if p.kind == kind and p.index == index then
|
||||
page = p
|
||||
break
|
||||
end
|
||||
end
|
||||
if not page then
|
||||
return nil, Err.new(Err.ARG, "no " .. tostring(kind) .. " " .. tostring(index))
|
||||
end
|
||||
local pal, given = palette(opts)
|
||||
local b, at, n = v.buf, v.base + page.offset, page.size
|
||||
local img = Types.Image.new(64, 64)
|
||||
local px = img.pixels
|
||||
if kind == "wall" then
|
||||
if n < 4096 then
|
||||
return nil, Err.new(Err.CORRUPT, "wall page shorter than 4096 bytes", page.offset)
|
||||
end
|
||||
for x = 0, 63 do
|
||||
for y = 0, 63 do
|
||||
writeu32(px, (y * 64 + x) * 4, buffer.readu32(pal, readu8(b, at + x * 64 + y) * 4))
|
||||
end
|
||||
end
|
||||
else
|
||||
if n < 4 then
|
||||
return nil, Err.new(Err.CORRUPT, "sprite page too short", page.offset)
|
||||
end
|
||||
local left, right = readu16(b, at), readu16(b, at + 2)
|
||||
if right < left or right > 63 or 4 + (right - left + 1) * 2 > n then
|
||||
return nil, Err.new(Err.CORRUPT, "bad sprite columns", page.offset)
|
||||
end
|
||||
for x = left, right do
|
||||
local p = readu16(b, at + 4 + (x - left) * 2)
|
||||
for _ = 1, 64 do
|
||||
if p + 2 > n then
|
||||
return nil, Err.new(Err.CORRUPT, "sprite post past the page", page.offset + p)
|
||||
end
|
||||
local endy = readu16(b, at + p) // 2
|
||||
if endy == 0 then
|
||||
break
|
||||
end
|
||||
if p + 6 > n then
|
||||
return nil, Err.new(Err.CORRUPT, "sprite post past the page", page.offset + p)
|
||||
end
|
||||
local src, starty = readi16(b, at + p + 2), readu16(b, at + p + 4) // 2
|
||||
if endy > 64 or starty > endy or src + starty < 0 or src + endy > n then
|
||||
return nil, Err.new(Err.CORRUPT, "bad sprite post", page.offset + p)
|
||||
end
|
||||
for y = starty, endy - 1 do
|
||||
writeu32(px, (y * 64 + x) * 4, buffer.readu32(pal, readu8(b, at + src + y) * 4))
|
||||
end
|
||||
p += 6
|
||||
end
|
||||
end
|
||||
end
|
||||
img.meta.source = { format = "vswap", kind = kind, index = index, palette = given }
|
||||
return img, nil
|
||||
end
|
||||
|
||||
function Vswap.sounds(a: any): number
|
||||
local v = info(a)
|
||||
if not v then
|
||||
return 0
|
||||
end
|
||||
local last = v.pages[#v.pages]
|
||||
return if last and last.kind == "soundinfo" then last.size // 4 else 0
|
||||
end
|
||||
|
||||
function Vswap.sound(a: any, index: number): (Types.Audio?, Err.Err?)
|
||||
local v = info(a)
|
||||
if not v then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded VSWAP archive")
|
||||
end
|
||||
local si = v.pages[#v.pages]
|
||||
if not si or si.kind ~= "soundinfo" or index < 1 or index > si.size // 4 or index % 1 ~= 0 then
|
||||
return nil, Err.new(Err.ARG, "no sound " .. tostring(index))
|
||||
end
|
||||
local b = v.buf
|
||||
local start = readu16(b, v.base + si.offset + (index - 1) * 4)
|
||||
local len = readu16(b, v.base + si.offset + (index - 1) * 4 + 2)
|
||||
local au = Types.Audio.new(SAMPLE_RATE, 1, len)
|
||||
local s = au.samples
|
||||
local got = 0
|
||||
local p = v.soundStart + start + 1
|
||||
while got < len do
|
||||
local page = v.pages[p]
|
||||
if not page or page.kind ~= "sound" then
|
||||
return nil, Err.new(Err.CORRUPT, "sound " .. index .. " runs past the sound pages")
|
||||
end
|
||||
local take = math.min(page.size, len - got)
|
||||
local at = v.base + page.offset
|
||||
for i = 0, take - 1 do
|
||||
buffer.writef32(s, (got + i) * 4, (readu8(b, at + i) - 128) / 128)
|
||||
end
|
||||
got += take
|
||||
p += 1
|
||||
if page.size == 0 then
|
||||
return nil, Err.new(Err.CORRUPT, "empty sound page in sound " .. index)
|
||||
end
|
||||
end
|
||||
au.meta.source = { format = "vswap", sound = index, startPage = start, bytes = len, encoding = "u8" }
|
||||
return au, nil
|
||||
end
|
||||
|
||||
return Vswap
|
||||
@@ -1,7 +1,7 @@
|
||||
--!strict
|
||||
-- archive/wad: Doom-engine WADs (IWAD / PWAD; Unofficial Doom Specs, w_wad.c / r_data.c; no code taken), plus lumps,
|
||||
-- palettes, pictures, wall textures and maps. Entry names: "<map>/<lump>", repeats "<name>~<n>". Not supported: UDMF
|
||||
-- geometry (lumps listed), Strife's TEXTURE variant, big-endian (Jaguar) WADs, compressed Jaguar lumps.
|
||||
-- palettes, pictures, wall textures and maps (binary and UDMF TEXTMAP). Entry names: "<map>/<lump>", repeats
|
||||
-- "<name>~<n>". Not supported: Strife's TEXTURE variant, big-endian (Jaguar) WADs, compressed Jaguar lumps.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -10,7 +10,7 @@ local Types = require("@rosetta/Types")
|
||||
local Archive = require("@rosetta/containers/Archive")
|
||||
local Pixels = require("@rosetta/codecs/image/Pixels")
|
||||
local Picture = require("@rosetta/archive/wad/Picture")
|
||||
local Map = require("@rosetta/archive/wad/Map")
|
||||
local Map = require("@rosetta/codecs/model/DoomMap")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Wad = {
|
||||
@@ -18,7 +18,7 @@ local Wad = {
|
||||
category = "archive",
|
||||
extensions = { "wad" },
|
||||
mime = { "application/x-doom" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/Polygon" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = true, images = true, maps = true, variants = { "iwad", "pwad" } },
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ export type Lump = {
|
||||
export type MapOptions = {
|
||||
textures: boolean?, -- default true
|
||||
palette: number?, -- default 0
|
||||
maxBlocks: number?, -- UDMF, default 2^22
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -377,7 +378,7 @@ function Wad.maps(a: any): { string }
|
||||
return out
|
||||
end
|
||||
|
||||
function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
|
||||
function Wad.mapData(a: any, name: string, opts: MapOptions?): (Map.MapData?, Err.Err?)
|
||||
local w = info(a)
|
||||
if not w then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded WAD archive")
|
||||
@@ -392,10 +393,13 @@ function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
|
||||
if not next(lumps) then
|
||||
return nil, Err.new(Err.ARG, "no map named " .. tostring(name))
|
||||
end
|
||||
if lumps.TEXTMAP then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "UDMF (TEXTMAP) maps")
|
||||
local m, msg
|
||||
local tm = lumps.TEXTMAP
|
||||
if tm then
|
||||
m, msg = Map.udmf(buffer.readstring(tm.buf, tm.at, tm.size), opts and opts.maxBlocks)
|
||||
else
|
||||
m, msg = Map.parse(lumps, lumps.BEHAVIOR ~= nil)
|
||||
end
|
||||
local m, msg = Map.parse(lumps, lumps.BEHAVIOR ~= nil)
|
||||
if not m then
|
||||
return nil, Err.from(msg)
|
||||
end
|
||||
@@ -403,7 +407,7 @@ function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
|
||||
end
|
||||
|
||||
function Wad.map(a: any, name: string, opts: MapOptions?): (Types.Scene?, Err.Err?)
|
||||
local m, err = Wad.mapData(a, name)
|
||||
local m, err = Wad.mapData(a, name, opts)
|
||||
if not m then
|
||||
return nil, err
|
||||
end
|
||||
@@ -441,7 +445,7 @@ function Wad.map(a: any, name: string, opts: MapOptions?): (Types.Scene?, Err.Er
|
||||
image = if images then image else nil,
|
||||
}
|
||||
local scene = Map.scene(m, tex, string.upper(name))
|
||||
scene.meta.source = { format = "wad", map = string.upper(name), mapFormat = m.format, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
|
||||
scene.meta.source = { format = "wad", map = string.upper(name), mapFormat = m.format, namespace = m.namespace, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
|
||||
return scene, nil
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
--!strict
|
||||
-- archive/wad2: Quake WAD2 and Half-Life WAD3 texture / graphics WADs (wad.h of the Quake source, the GoldSrc WAD3
|
||||
-- layout; no code taken), read and write. Lumps by name (repeats "<name>~<n>"); Wad2.image decodes miptex, qpic,
|
||||
-- conchars, palette and GoldSrc font lumps through codecs/image/Miptex (Quake 1 needs a palette: the WAD's own
|
||||
-- "palette" lump, opts.palette or gfx/palette.lmp through files / resolve; else grey). Not supported: compressed lumps.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Input = require("@rosetta/core/Input")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Archive = require("@rosetta/containers/Archive")
|
||||
local Pixels = require("@rosetta/codecs/image/Pixels")
|
||||
local Miptex = require("@rosetta/codecs/image/Miptex")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Wad2 = {
|
||||
name = "wad2",
|
||||
category = "archive",
|
||||
extensions = { "wad" },
|
||||
mime = { "application/x-quake-wad" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/image/Miptex" },
|
||||
caps = { decode = true, encode = true, images = true, variants = { "wad2", "wad3" } },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = { maxEntries: number? } -- default 1e6
|
||||
export type EncodeOptions = { variant: ("wad2" | "wad3")? } -- default: the source's, else wad3 when a lump is type 0x43
|
||||
export type ImageOptions = {
|
||||
palette: (buffer | string)?, -- 768 bytes (Quake 1)
|
||||
mip: number?, -- miptex level 0..3, default 0
|
||||
keyed: boolean?, -- index 255 transparent; default: qpics, conchars and '{' textures
|
||||
resolve: ((uri: string) -> (buffer | string)?)?,
|
||||
files: { [string]: buffer | string }?,
|
||||
}
|
||||
export type AddOptions = {
|
||||
kind: ("miptex" | "qpic")?, -- default "miptex"
|
||||
palette: (buffer | string)?, -- 768 bytes; required for WAD2 lumps, made by median cut for WAD3 without it
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local T = Miptex.TYPES
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function Wad2.sniff(r: Bytes.Reader): number
|
||||
if r:remaining() < 12 then
|
||||
return 0
|
||||
end
|
||||
local m = r:peek(4)
|
||||
return if m == "WAD2" or m == "WAD3" then 0.9 else 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
local function encode(archive: any, opts: any?): (buffer?, Err.Err?)
|
||||
return Wad2.encode(archive, opts)
|
||||
end
|
||||
|
||||
function Wad2.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
local size = r.limit - r.base
|
||||
local lumps, msg, magic = Miptex.wad(r.buf, r.base, size, opts and opts.maxEntries)
|
||||
if not lumps then
|
||||
return nil, Err.from(msg, 0)
|
||||
end
|
||||
local a = Archive.new("wad2", encode)
|
||||
local seen: { [string]: number } = {}
|
||||
for _, l in lumps do
|
||||
if l.compression ~= 0 then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "compressed lump " .. l.name)
|
||||
end
|
||||
local entry = l.name
|
||||
local k = seen[string.lower(entry)]
|
||||
if k then
|
||||
seen[string.lower(entry)] = k + 1
|
||||
entry = entry .. "~" .. (k + 1)
|
||||
else
|
||||
seen[string.lower(entry)] = 1
|
||||
end
|
||||
Archive.put(a, { name = entry, size = l.disksize, dir = false, method = "store", type = l.type, lump = l.name, load = Archive.slice(r.buf, r.base + l.offset, l.disksize) })
|
||||
end
|
||||
a.meta.source = { format = "wad2", variant = string.lower(magic :: string), lumps = #lumps }
|
||||
a.meta.wad2 = { buf = r.buf, base = r.base, lumps = lumps, goldsrc = magic == "WAD3" }
|
||||
return a, nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
local function guessType(name: string, data: buffer, goldsrc: boolean): number
|
||||
local n = buffer.len(data)
|
||||
if string.lower(name) == "palette" and n == 768 then
|
||||
return T.palette
|
||||
end
|
||||
if n >= 40 then
|
||||
local w, h = buffer.readu32(data, 16), buffer.readu32(data, 20)
|
||||
if w > 0 and h > 0 and w < 65536 and h < 65536 and buffer.readu32(data, 24) == 40 then
|
||||
return if goldsrc then 0x43 else T.miptex
|
||||
end
|
||||
end
|
||||
if n >= 8 then
|
||||
local w, h = buffer.readu32(data, 0), buffer.readu32(data, 4)
|
||||
if w > 0 and h > 0 and 8 + w * h <= n then
|
||||
return T.qpic
|
||||
end
|
||||
end
|
||||
return T.miptex
|
||||
end
|
||||
|
||||
function Wad2.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local items, err = Archive.collect(archive)
|
||||
if not items then
|
||||
return nil, err
|
||||
end
|
||||
local src = type(archive) == "table" and type(archive.meta) == "table" and archive.meta.source
|
||||
local variant = opts and opts.variant or (if type(src) == "table" and src.format == "wad2" then src.variant else nil)
|
||||
if not variant then
|
||||
variant = "wad2"
|
||||
for _, it in items do
|
||||
if (it.entry :: any).type == 0x43 then
|
||||
variant = "wad3"
|
||||
end
|
||||
end
|
||||
end
|
||||
if variant ~= "wad2" and variant ~= "wad3" then
|
||||
return nil, Err.new(Err.ARG, "variant must be wad2 or wad3")
|
||||
end
|
||||
local list: { { name: string, data: buffer, type: number } } = {}
|
||||
for _, it in items do
|
||||
if not it.entry.dir then
|
||||
local e: any = it.entry
|
||||
local name = e.lump or string.gsub(string.match(e.name, "([^/\\]*)$") or e.name, "~%d+$", "")
|
||||
if #name == 0 or #name > 15 then
|
||||
return nil, Err.new(Err.ARG, "lump name must be 1..15 bytes: " .. e.name)
|
||||
end
|
||||
local typ = if type(e.type) == "number" then e.type else guessType(name, it.data, variant == "wad3")
|
||||
table.insert(list, { name = name, data = it.data, type = typ })
|
||||
end
|
||||
end
|
||||
local w = Bytes.writer()
|
||||
w:string(if variant == "wad3" then "WAD3" else "WAD2")
|
||||
w:u32le(#list)
|
||||
w:u32le(0)
|
||||
local offs: { number } = {}
|
||||
for i, l in list do
|
||||
offs[i] = w:tell()
|
||||
w:bytes(l.data)
|
||||
w:fill(0, (4 - buffer.len(l.data) % 4) % 4)
|
||||
end
|
||||
local dir = w:tell()
|
||||
for i, l in list do
|
||||
w:u32le(offs[i])
|
||||
w:u32le(buffer.len(l.data))
|
||||
w:u32le(buffer.len(l.data))
|
||||
w:u8(l.type)
|
||||
w:u8(0)
|
||||
w:u16le(0)
|
||||
w:string(l.name)
|
||||
w:fill(0, 16 - #l.name)
|
||||
end
|
||||
w:setU32le(8, dir)
|
||||
return w:finish(), nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
local function info(a: any): any
|
||||
return type(a) == "table" and type(a.meta) == "table" and a.meta.wad2 or nil
|
||||
end
|
||||
|
||||
function Wad2.new(variant: ("wad2" | "wad3")?): any
|
||||
local a = Archive.new("wad2", encode)
|
||||
a.meta.source = { format = "wad2", variant = variant or "wad2" }
|
||||
return a
|
||||
end
|
||||
|
||||
function Wad2.lumps(a: any): { Miptex.Lump }?
|
||||
local w = info(a)
|
||||
return w and w.lumps
|
||||
end
|
||||
|
||||
-- the WAD's own "palette" lump (gfx.wad) as a 1024-byte rgba8 palette
|
||||
function Wad2.palette(a: any): buffer?
|
||||
local w = info(a)
|
||||
local l = w and Miptex.find(w.lumps, "palette")
|
||||
if l and l.disksize >= 768 then
|
||||
return Pixels.palette(w.buf, w.base + l.offset, 256)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function Wad2.image(a: any, name: string, opts: ImageOptions?): (Types.Image?, Err.Err?)
|
||||
local w = info(a)
|
||||
if not w then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded WAD2 / WAD3 archive")
|
||||
end
|
||||
local l = Miptex.find(w.lumps, tostring(name))
|
||||
if not l then
|
||||
return nil, Err.new(Err.ARG, "no lump named " .. tostring(name))
|
||||
end
|
||||
local b, at, size = w.buf, w.base + l.offset, l.disksize
|
||||
local pal: buffer? = nil
|
||||
if not w.goldsrc then
|
||||
local raw = if opts and opts.palette then Bytes.toBuffer(opts.palette) else nil
|
||||
if raw and buffer.len(raw) >= 768 then
|
||||
pal = Pixels.palette(raw, 0, 256)
|
||||
else
|
||||
pal = Wad2.palette(a)
|
||||
if not pal then
|
||||
local lmp = Input.sibling(opts, "gfx/palette.lmp")
|
||||
pal = if lmp and buffer.len(lmp) >= 768 then Pixels.palette(lmp, 0, 256) else nil
|
||||
end
|
||||
end
|
||||
end
|
||||
local keyed: boolean? = if opts then opts.keyed else nil
|
||||
local img: Types.Image?, msg: string?
|
||||
local kind: string
|
||||
if l.type == T.palette and size >= 768 then
|
||||
kind = "palette"
|
||||
local out = Types.Image.new(16, 16)
|
||||
buffer.copy(out.pixels, 0, Pixels.palette(b, at, 256), 0, 1024)
|
||||
img = out
|
||||
elseif string.lower(l.name) == "conchars" and size == 128 * 128 then
|
||||
-- gfx.wad's console font: raw 128 x 128 pixels, no header, index 0 transparent
|
||||
kind = "conchars"
|
||||
local out = Types.Image.new(128, 128)
|
||||
Pixels.indexed(b, at, 128, 8, out.pixels, 128, 128, true, Pixels.keyed(pal or Pixels.grey(), if keyed == false then -1 else 0))
|
||||
img = out
|
||||
elseif l.type == T.qpic then
|
||||
kind = "qpic"
|
||||
img, msg = Miptex.qpic(b, at, size, { palette = pal, goldsrc = w.goldsrc, keyed = keyed } :: any)
|
||||
elseif l.type == T.font and w.goldsrc and size >= 16 + 1024 then
|
||||
-- GoldSrc qfont_t: width (256), height, rowcount, rowheight, charinfo[256] (u16 offset, u16 width), pixels, palette
|
||||
kind = "font"
|
||||
local fw, fh = buffer.readu32(b, at), buffer.readu32(b, at + 4)
|
||||
local p = 16 + 1024 + fw * fh
|
||||
if fw == 0 or fh == 0 or fw * fh > 2 ^ 24 or p + 2 > size then
|
||||
return nil, Err.new(Err.CORRUPT, "bad font lump " .. l.name, l.offset)
|
||||
end
|
||||
local n = buffer.readu16(b, at + p)
|
||||
local fpal = if n > 0 and n <= 256 and p + 2 + n * 3 <= size then Pixels.palette(b, at + p + 2, n) else Pixels.grey()
|
||||
local out = Types.Image.new(fw, fh)
|
||||
Pixels.indexed(b, at + 16 + 1024, fw, 8, out.pixels, fw, fh, true, if keyed == false then fpal else Pixels.keyed(fpal, 255))
|
||||
local glyphs = {}
|
||||
for c = 0, 255 do
|
||||
glyphs[c + 1] = { offset = buffer.readu16(b, at + 16 + c * 4), width = buffer.readu16(b, at + 18 + c * 4) }
|
||||
end
|
||||
out.meta.font = { rows = buffer.readu32(b, at + 8), rowHeight = buffer.readu32(b, at + 12), glyphs = glyphs }
|
||||
img = out
|
||||
else
|
||||
kind = "miptex"
|
||||
img, msg = Miptex.decode(b, at, size, { palette = pal, goldsrc = w.goldsrc, mip = if opts then opts.mip else nil, keyed = keyed } :: any)
|
||||
end
|
||||
if not img then
|
||||
return nil, Err.from(msg, l.offset)
|
||||
end
|
||||
img.meta.source = { format = "wad2", kind = kind, lump = l.name, type = l.type, palette = w.goldsrc or pal ~= nil }
|
||||
return img, nil
|
||||
end
|
||||
|
||||
-- adds an rgba8 image as a miptex (sizes multiples of 16) or qpic lump; WAD3 lumps carry their own palette
|
||||
function Wad2.addImage(a: any, name: string, img: Types.Image, opts: AddOptions?): (boolean, Err.Err?)
|
||||
if type(img) ~= "table" or img.format ~= "rgba8" then
|
||||
return false, Err.new(Err.ARG, "expected an rgba8 Image")
|
||||
end
|
||||
local src = type(a) == "table" and type(a.meta) == "table" and a.meta.source
|
||||
local goldsrc = type(src) == "table" and src.variant == "wad3"
|
||||
local raw = opts and opts.palette and Bytes.toBuffer(opts.palette)
|
||||
local pal = if raw and buffer.len(raw) >= 768 then Pixels.palette(raw, 0, 256) else nil
|
||||
local kind = opts and opts.kind or "miptex"
|
||||
local data, msg
|
||||
if kind == "qpic" then
|
||||
data, msg = Miptex.encodeQpic(img, pal, goldsrc)
|
||||
else
|
||||
data, msg = Miptex.encode(img, name, pal, goldsrc)
|
||||
end
|
||||
if not data then
|
||||
return false, Err.new(Err.ARG, msg or "cannot encode")
|
||||
end
|
||||
Archive.put(a, { name = name, size = buffer.len(data), dir = false, method = "store", lump = name, data = data,
|
||||
type = if kind == "qpic" then T.qpic elseif goldsrc then 0x43 else T.miptex })
|
||||
return true, nil
|
||||
end
|
||||
|
||||
return Wad2
|
||||
@@ -1,7 +1,9 @@
|
||||
--!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.
|
||||
-- channels, every rate), HE-AAC / HE-AACv2 (SBR / PS found in the stream: ADTS cannot signal them; opts.sbr = false
|
||||
-- keeps the AAC-LC core), CRC-protected headers, a leading ID3v2 tag, resync, seeking by frame. Not supported: writing,
|
||||
-- ADIF, LATM.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -24,6 +26,7 @@ local AacFormat = {
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
maxFrames: number?, -- default 2^22
|
||||
sbr: boolean?, -- false: decode only the AAC-LC core of HE-AAC (half rate, faster); default true
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -149,14 +152,18 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
return nil, Err.new(Err.UNSUPPORTED, "ADTS with a program config element (channel configuration 0)")
|
||||
end
|
||||
local channels = ({ 1, 2, 3, 4, 5, 6, 8 })[h.channelConfig] :: number
|
||||
local dec, derr = Aac.decoder({ sfIndex = h.sfIndex, channels = channels, channelConfig = h.channelConfig })
|
||||
local dec, derr = Aac.decoder({ sfIndex = h.sfIndex, channels = channels, channelConfig = h.channelConfig }, { sbr = o.sbr })
|
||||
if not dec then
|
||||
return nil, derr
|
||||
end
|
||||
local d = dec :: Aac.Decoder
|
||||
local sr = d.sampleRate
|
||||
if Aac.probeFrames(d, r.buf, offs, sizes) then
|
||||
d:reset()
|
||||
end
|
||||
local sr, fl = d.sampleRate, d.frameLength
|
||||
channels = d.channels
|
||||
local nframes = #offs
|
||||
local total = nframes * 1024
|
||||
local total = nframes * fl
|
||||
local bytes = 0
|
||||
for _, s in sizes do
|
||||
bytes += s
|
||||
@@ -173,11 +180,11 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
tags = tags,
|
||||
codec = "aac",
|
||||
}
|
||||
-- 1024 samples per ADTS frame; one frame of pre-roll for the overlap
|
||||
-- 1024 (2048 with SBR) samples per ADTS frame; pre-roll for the overlap (and the SBR filterbanks / time deltas)
|
||||
return Stream.packets(out, {
|
||||
count = nframes,
|
||||
start = function(i: number): number
|
||||
return (i - 1) * 1024
|
||||
return (i - 1) * fl
|
||||
end,
|
||||
decode = function(i: number): (number?, Err.Err?)
|
||||
return d:decode(buf, offs[i], sizes[i])
|
||||
@@ -188,7 +195,7 @@ function AacFormat.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?,
|
||||
reset = function()
|
||||
d:reset()
|
||||
end,
|
||||
preroll = 1,
|
||||
preroll = if d.sbrOutput then 3 else 1,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -397,6 +398,10 @@ local function source(r: Bytes.Reader, p: Parsed): (Source?, Err.Err?)
|
||||
if not dec then
|
||||
return nil, err
|
||||
end
|
||||
-- HE-AAC: SBR output only when the description is at the SBR rate (else the AAC-LC core)
|
||||
if dec.sbrOutput and dec.sampleRate ~= d.rate then
|
||||
dec = Aac.decoder(asc :: buffer, { sbr = false })
|
||||
end
|
||||
local ad = dec :: Aac.Decoder
|
||||
return {
|
||||
channels = ad.channels,
|
||||
|
||||
@@ -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,7 +1,8 @@
|
||||
--!strict
|
||||
-- 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.
|
||||
--!optimize 2
|
||||
-- audio/m4a: MPEG-4 audio (M4A / M4B / MP4 / MOV audio tracks) via containers/IsoBmff. Supports: AAC-LC, HE-AAC /
|
||||
-- HE-AACv2 (explicit or implicit SBR / PS; opts.sbr = false keeps the AAC-LC 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.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -28,6 +29,7 @@ export type DecodeOptions = {
|
||||
track: number?, -- the track id to play (default: the first AAC / ALAC track)
|
||||
gapless: boolean?, -- apply the edit list (default true)
|
||||
maxSamples: number?, -- default 2^25
|
||||
sbr: boolean?, -- false: decode only the AAC-LC core of HE-AAC (half rate, faster); default true
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
bitDepth: number?, -- 16 (default), 20 or 24
|
||||
@@ -62,9 +64,10 @@ type PacketDecoder = {
|
||||
pcm: { number },
|
||||
decode: (buf: buffer, off: number, len: number) -> (number?, Err.Err?),
|
||||
reset: () -> (),
|
||||
sbr: boolean?,
|
||||
}
|
||||
|
||||
local function packetDecoder(t: IsoBmff.Track): (PacketDecoder?, Err.Err?)
|
||||
local function packetDecoder(t: IsoBmff.Track, buf: buffer, sbr: boolean?): (PacketDecoder?, Err.Err?)
|
||||
if not t.config then
|
||||
return nil, Err.new(Err.CORRUPT, "track " .. t.id .. " (" .. t.codec .. ") has no codec configuration")
|
||||
end
|
||||
@@ -96,11 +99,14 @@ local function packetDecoder(t: IsoBmff.Track): (PacketDecoder?, Err.Err?)
|
||||
}
|
||||
return pd, nil
|
||||
elseif t.codec == "aac" then
|
||||
local dec, err = Aac.decoder(t.config :: buffer)
|
||||
local dec, err = Aac.decoder(t.config :: buffer, { sbr = sbr })
|
||||
if not dec then
|
||||
return nil, err
|
||||
end
|
||||
local d = dec :: Aac.Decoder
|
||||
if Aac.probeFrames(d, buf, t.offsets, t.sizes) then
|
||||
d:reset()
|
||||
end
|
||||
local pd: PacketDecoder = {
|
||||
channels = d.channels,
|
||||
sampleRate = d.sampleRate,
|
||||
@@ -112,6 +118,7 @@ local function packetDecoder(t: IsoBmff.Track): (PacketDecoder?, Err.Err?)
|
||||
reset = function()
|
||||
d:reset()
|
||||
end,
|
||||
sbr = d.sbrOutput,
|
||||
}
|
||||
return pd, nil
|
||||
end
|
||||
@@ -145,7 +152,7 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
|
||||
return nil, Err.new(Err.CORRUPT, "no audio track")
|
||||
end
|
||||
local t = track :: IsoBmff.Track
|
||||
local pd, perr = packetDecoder(t)
|
||||
local pd, perr = packetDecoder(t, r.buf, o.sbr)
|
||||
if not pd then
|
||||
return nil, perr
|
||||
end
|
||||
@@ -170,9 +177,11 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
|
||||
for w in string.gmatch(smpb, "%x+") do
|
||||
table.insert(f, tonumber(w, 16) :: number)
|
||||
end
|
||||
if #f >= 4 and f[2] and f[4] and f[4] > 0 and f[2] + f[4] <= total then
|
||||
skip = f[2]
|
||||
total = f[2] + f[4]
|
||||
-- in media ticks (the core rate of HE-AAC, as ffmpeg reads it)
|
||||
local pre, len = math.floor((f[2] or 0) * tickScale + 0.5), math.floor((f[4] or 0) * tickScale + 0.5)
|
||||
if #f >= 4 and len > 0 and pre + len <= total then
|
||||
skip = pre
|
||||
total = pre + len
|
||||
end
|
||||
end
|
||||
local frames = math.max(0, total - skip)
|
||||
@@ -209,7 +218,7 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
|
||||
reset = p.reset,
|
||||
skip = skip,
|
||||
stop = total,
|
||||
preroll = if t.codec == "aac" then 1 else 0,
|
||||
preroll = if p.sbr then 3 elseif t.codec == "aac" then 1 else 0,
|
||||
cumulative = true,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -50,15 +50,19 @@ function Stream.new(b: buffer, idx: any, tags: { [string]: string }, id3: any):
|
||||
local total = idx.outTotal
|
||||
if idx.vbrTag > 0 then
|
||||
delay = idx.delay
|
||||
local detected = spf * idx.tagFrames
|
||||
if detected >= delay then
|
||||
detected -= delay
|
||||
end
|
||||
if idx.padding > 0 and detected >= idx.padding then
|
||||
detected -= idx.padding
|
||||
end
|
||||
total = max(0, total - delay)
|
||||
total = min(total, detected)
|
||||
-- (a frame count of 0: written by an encoder that couldn't seek back to fill it in, e.g. ffmpeg writing to a
|
||||
-- pipe; ffmpeg ignores it too. The frames found in the file are the length.)
|
||||
if idx.tagFrames > 0 then
|
||||
local detected = spf * idx.tagFrames
|
||||
if detected >= delay then
|
||||
detected -= delay
|
||||
end
|
||||
if idx.padding > 0 and detected >= idx.padding then
|
||||
detected -= idx.padding
|
||||
end
|
||||
total = min(total, detected)
|
||||
end
|
||||
end
|
||||
delay = min(delay, idx.outTotal)
|
||||
local self = setmetatable({
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
-- Written from the standard; no third-party code. PNS uses FFmpeg's LCG so the noise matches it.
|
||||
local Mdct = require("@rosetta/codecs/audio/Mdct")
|
||||
local Tables = require("@rosetta/codecs/audio/Aac/Tables")
|
||||
local Sbr = require("@rosetta/codecs/audio/Aac/Sbr")
|
||||
|
||||
local readu32, byteswap, lshift, rshift, band = buffer.readu32, bit32.byteswap, bit32.lshift, bit32.rshift, bit32.band
|
||||
local floor, sqrt, abs = math.floor, math.sqrt, math.abs
|
||||
@@ -94,6 +95,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)
|
||||
@@ -136,6 +151,15 @@ export type State = {
|
||||
extensions: number,
|
||||
sbr: boolean,
|
||||
map: { number }?,
|
||||
-- SBR output (codecs/audio/Aac/Sbr): sbrRate = the output rate when on, psOut = a mono stream output as stereo
|
||||
sbrOn: boolean,
|
||||
probe: boolean, -- parse only (SBR / PS detection): no output
|
||||
sbrRate: number,
|
||||
psOut: boolean,
|
||||
sbrElems: { any },
|
||||
elemKind: { number },
|
||||
elemFirst: { number },
|
||||
core: { { number } },
|
||||
}
|
||||
|
||||
local function newChannel(): Channel
|
||||
@@ -421,7 +445,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 +456,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 +683,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
|
||||
@@ -714,6 +740,50 @@ local function filterbank(st: State, c: Channel, out: { number }, stride: number
|
||||
c.prevShape = shape
|
||||
end
|
||||
|
||||
local function sbrElement(st: State, i: number, nch: number): any
|
||||
local e = st.sbrElems[i]
|
||||
if not e or e.nch ~= nch then
|
||||
e = Sbr.element(nch, st.sbrRate, st.psOut and nch == 1)
|
||||
st.sbrElems[i] = e
|
||||
end
|
||||
return e
|
||||
end
|
||||
|
||||
local OFFS = { 0, 0 }
|
||||
local CORE2 = { {}, {} }
|
||||
|
||||
-- every element through SBR at the doubled rate (2048 samples per channel); the PS output of a mono element is stereo
|
||||
local function sbrOutput(st: State, order: { Channel }, nElem: number): number
|
||||
local n = #order
|
||||
local ps = st.psOut and n == 1
|
||||
local stride = if ps then 2 else n
|
||||
local map = st.map
|
||||
local core = st.core
|
||||
for i, c in order do
|
||||
local t = core[i]
|
||||
if not t then
|
||||
t = table.create(1024, 0)
|
||||
core[i] = t
|
||||
end
|
||||
filterbank(st, c, t, 1, 1)
|
||||
end
|
||||
for ei = 1, nElem do
|
||||
local first = st.elemFirst[ei]
|
||||
local nch = if st.elemKind[ei] == 1 then 2 else 1
|
||||
local e = sbrElement(st, ei, nch)
|
||||
for j = 1, nch do
|
||||
local idx = first + j - 1
|
||||
OFFS[j] = if map and map[idx] then map[idx] else idx
|
||||
CORE2[j] = core[idx]
|
||||
end
|
||||
if ps then
|
||||
OFFS[2] = 2
|
||||
end
|
||||
Sbr.process(e, CORE2, st.pcm, stride, OFFS)
|
||||
end
|
||||
return stride
|
||||
end
|
||||
|
||||
function Decode.frame(st: State, buf: buffer, off: number, len: number): (number?, string?)
|
||||
if buffer.len(B) < len + 16 then
|
||||
B = buffer.create(len + 256)
|
||||
@@ -725,6 +795,8 @@ function Decode.frame(st: State, buf: buffer, off: number, len: number): (number
|
||||
local nextCh = 1
|
||||
local order: { Channel } = {}
|
||||
local lastElement = -1
|
||||
local nElem = 0
|
||||
local elemKind, elemFirst = st.elemKind, st.elemFirst
|
||||
while true do
|
||||
if BP + 3 > BL then
|
||||
break -- tolerate a missing END
|
||||
@@ -746,6 +818,8 @@ function Decode.frame(st: State, buf: buffer, off: number, len: number): (number
|
||||
end
|
||||
applyTns(st, c)
|
||||
table.insert(order, c)
|
||||
nElem += 1
|
||||
elemKind[nElem], elemFirst[nElem] = id, #order
|
||||
nextCh += 1
|
||||
lastElement = id
|
||||
elseif id == 1 then -- CPE
|
||||
@@ -802,6 +876,8 @@ function Decode.frame(st: State, buf: buffer, off: number, len: number): (number
|
||||
applyTns(st, r)
|
||||
table.insert(order, l)
|
||||
table.insert(order, r)
|
||||
nElem += 1
|
||||
elemKind[nElem], elemFirst[nElem] = id, #order - 1
|
||||
nextCh += 2
|
||||
lastElement = id
|
||||
elseif id == 2 then
|
||||
@@ -829,6 +905,9 @@ function Decode.frame(st: State, buf: buffer, off: number, len: number): (number
|
||||
local kind = getBits(4)
|
||||
if kind == 13 or kind == 14 then -- EXT_SBR_DATA / EXT_SBR_DATA_CRC
|
||||
st.sbr = true
|
||||
if st.sbrOn and nElem > 0 and lastElement ~= 3 then
|
||||
Sbr.extension(sbrElement(st, nElem, if lastElement == 1 then 2 else 1), B, start + 4, count * 8 - 4, kind == 14)
|
||||
end
|
||||
end
|
||||
st.extensions += 1
|
||||
local hook = st.onExtension
|
||||
@@ -849,6 +928,12 @@ function Decode.frame(st: State, buf: buffer, off: number, len: number): (number
|
||||
if n == 0 then
|
||||
return 0, nil
|
||||
end
|
||||
if st.probe then
|
||||
return n, nil
|
||||
end
|
||||
if st.sbrOn then
|
||||
return sbrOutput(st, order, nElem), nil
|
||||
end
|
||||
local pcm = st.pcm
|
||||
local map = st.map
|
||||
for i, c in order do
|
||||
@@ -864,7 +949,7 @@ function Decode.state(sfIndex: number): State
|
||||
channels = 0,
|
||||
frameLength = 1024,
|
||||
ch = {},
|
||||
pcm = table.create(1024 * 8, 0),
|
||||
pcm = table.create(2048 * 8, 0),
|
||||
random = 0x1f2e3d4c,
|
||||
time = table.create(2048, 0),
|
||||
frame = table.create(2048, 0),
|
||||
@@ -873,6 +958,14 @@ function Decode.state(sfIndex: number): State
|
||||
extensions = 0,
|
||||
sbr = false,
|
||||
map = nil,
|
||||
sbrOn = false,
|
||||
probe = false,
|
||||
sbrRate = 0,
|
||||
psOut = false,
|
||||
sbrElems = {},
|
||||
elemKind = {},
|
||||
elemFirst = {},
|
||||
core = {},
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,588 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/Ps: baseline Parametric Stereo (ISO/IEC 14496-3 8.6.4, syntax 8.3): ps_data with IID / ICC (10,
|
||||
-- 20 or 34 bands, mapped to 20), the 10/20-band hybrid analysis filterbank, the all-pass / delay decorrelator with
|
||||
-- transient attenuation, and mixing procedures Ra / Rb. IPD / OPD (the ps_extension) are skipped, as baseline PS
|
||||
-- allows. Ported from syom 0.8.1 src/engine/ps_*.rs (MIT, licenses/syom-LICENSE.txt).
|
||||
local SbrTables = require("@rosetta/codecs/audio/Aac/SbrTables")
|
||||
local SbrBits = require("@rosetta/codecs/audio/Aac/SbrBits")
|
||||
|
||||
local cos, sin, sqrt, pi, acos, atan = math.cos, math.sin, math.sqrt, math.pi, math.acos, math.atan
|
||||
local bits, huff, codebook = SbrBits.bits, SbrBits.huff, SbrBits.codebook
|
||||
|
||||
local Ps = {}
|
||||
|
||||
local IID_DF = codebook(SbrTables.IID_DF)
|
||||
local IID_DT = codebook(SbrTables.IID_DT)
|
||||
local IID_FINE_DF = codebook(SbrTables.IID_FINE_DF)
|
||||
local IID_FINE_DT = codebook(SbrTables.IID_FINE_DT)
|
||||
local ICC_DF = codebook(SbrTables.ICC_DF)
|
||||
local ICC_DT = codebook(SbrTables.ICC_DT)
|
||||
|
||||
local NR_PAR = { 10, 20, 34, 10, 20, 34 }
|
||||
local NUM_ENV = { 0, 1, 2, 4, 1, 2, 3, 4 }
|
||||
|
||||
-- Table 8.25 / 8.26: IID steps (dB) and ICC values
|
||||
local IID_COARSE = { -25, -18, -14, -10, -7, -4, -2, 0, 2, 4, 7, 10, 14, 18, 25 }
|
||||
local IID_FINE = { -50, -45, -40, -35, -30, -25, -22, -19, -16, -13, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 13, 16, 19, 22,
|
||||
25, 30, 35, 40, 45, 50 }
|
||||
local ICC_RHO = { 1.0, 0.937, 0.84118, 0.60092, 0.36764, 0.0, -0.589, -1.0 }
|
||||
for i, v in IID_COARSE do
|
||||
IID_COARSE[i] = 10 ^ (v / 20)
|
||||
end
|
||||
for i, v in IID_FINE do
|
||||
IID_FINE[i] = 10 ^ (v / 20)
|
||||
end
|
||||
|
||||
-- 34 -> 20 parameter bands (8.6.4.6.1): { i, j, wi, wj } weights over 34-band indexes (0-based)
|
||||
local MAP34 = {
|
||||
{ 0, 1, 2, 1 }, { 1, 2, 1, 2 }, { 3, 4, 2, 1 }, { 4, 5, 1, 2 }, { 6, 7, 1, 1 }, { 8, 9, 1, 1 }, { 10, 10, 1, 0 },
|
||||
{ 11, 11, 1, 0 }, { 12, 13, 1, 1 }, { 14, 15, 1, 1 }, { 16, 16, 1, 0 }, { 17, 17, 1, 0 }, { 18, 18, 1, 0 },
|
||||
{ 19, 19, 1, 0 }, { 20, 21, 1, 1 }, { 22, 23, 1, 1 }, { 24, 25, 1, 1 }, { 26, 27, 1, 1 }, { 28, 29, 1, 1 },
|
||||
{ 32, 33, 1, 1 },
|
||||
}
|
||||
|
||||
-- Table 8.48: parameter band of each of the 71 hybrid bands (20-band configuration)
|
||||
local B_K = { 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17 }
|
||||
for _ = 1, 12 do
|
||||
table.insert(B_K, 18)
|
||||
end
|
||||
while #B_K < 71 do
|
||||
table.insert(B_K, 19)
|
||||
end
|
||||
|
||||
-- 8.6.4.3 hybrid prototype filters (13 taps)
|
||||
local G0 = { 0.00746082949812, 0.02270420949825, 0.04546865930473, 0.07266113929591, 0.09885108575264, 0.11793710567217,
|
||||
0.125, 0.11793710567217, 0.09885108575264, 0.07266113929591, 0.04546865930473, 0.02270420949825, 0.00746082949812 }
|
||||
local G12 = { 0.0, 0.01899487526049, 0.0, -0.07293139167538, 0.0, 0.30596630545168, 0.5, 0.30596630545168, 0.0,
|
||||
-0.07293139167538, 0.0, 0.01899487526049, 0.0 }
|
||||
-- band 0, type A, Q = 8: A0C / A0S[q * 6 + m'] = g[m] cos / sin(2 pi / 8 (q + 1/2) (m - 6)) for m = m' - 1 = 0 .. 5
|
||||
local A0C, A0S = table.create(4 * 6, 0), table.create(4 * 6, 0)
|
||||
for q = 0, 3 do
|
||||
for m = 0, 5 do
|
||||
local a = 2 * pi / 8 * (q + 0.5) * (m - 6)
|
||||
A0C[q * 6 + m + 1] = G0[m + 1] * cos(a)
|
||||
A0S[q * 6 + m + 1] = G0[m + 1] * sin(a)
|
||||
end
|
||||
end
|
||||
|
||||
-- 8.6.4.5 decorrelator constants (20-band configuration)
|
||||
local AP_A = { 0.65143905753106, 0.56471812200776, 0.48954165955695 }
|
||||
local Q_FRACT = { 0.43, 0.75, 0.347 }
|
||||
local F_CENTER = { -3 / 8, -1 / 8, 1 / 8, 3 / 8, 5 / 8, 7 / 8, 5 / 4, 7 / 4, 9 / 4, 11 / 4 }
|
||||
local NR_AP = 30
|
||||
local PHI_R, PHI_I = table.create(NR_AP, 0), table.create(NR_AP, 0)
|
||||
local QF_R, QF_I = table.create(NR_AP * 3, 0), table.create(NR_AP * 3, 0)
|
||||
local G_DECAY = table.create(NR_AP, 0)
|
||||
local CO = table.create(NR_AP * 3, 0)
|
||||
for k = 0, NR_AP - 1 do
|
||||
local f = if k < 10 then F_CENTER[k + 1] else k + 0.5 - 7
|
||||
PHI_R[k + 1], PHI_I[k + 1] = cos(-pi * 0.39 * f), sin(-pi * 0.39 * f)
|
||||
for m = 0, 2 do
|
||||
QF_R[k * 3 + m + 1], QF_I[k * 3 + m + 1] = cos(-pi * Q_FRACT[m + 1] * f), sin(-pi * Q_FRACT[m + 1] * f)
|
||||
end
|
||||
G_DECAY[k + 1] = if k > 10 then math.max(0, 1 - 0.05 * (k - 10)) else 1
|
||||
for m = 0, 2 do
|
||||
CO[k * 3 + m + 1] = AP_A[m + 1] * G_DECAY[k + 1]
|
||||
end
|
||||
end
|
||||
local PEAK_DECAY, A_SMOOTH, GAMMA = 0.76592833836465, 0.25, 1.5
|
||||
|
||||
function Ps.state(): any
|
||||
return {
|
||||
haveConfig = false,
|
||||
enableIid = false,
|
||||
iidMode = 0,
|
||||
enableIcc = false,
|
||||
iccMode = 0,
|
||||
enableExt = false,
|
||||
iidPrev = table.create(34, 0),
|
||||
iidPrevN = 0,
|
||||
iccPrev = table.create(34, 0),
|
||||
iccPrevN = 0,
|
||||
hist = table.create(3 * 6 * 2, 0), -- hybrid input history: [(p * 6 + j) * 2 + 1 / 2]
|
||||
apIn = table.create(NR_AP * 4, 0), -- z^-2 delay: in[n-1], in[n-2] (re, im)
|
||||
apW = table.create(NR_AP * 3 * 5 * 2, 0), -- all-pass links: [k * 30 + (m * 5 + pos) * 2 + 1 / 2]
|
||||
apCnt = 0,
|
||||
dl = table.create(41 * 14 * 2, 0), -- plain delays of hybrid bands 30 .. 70
|
||||
dlCnt = 0,
|
||||
peak = table.create(20, 0),
|
||||
smooth = table.create(20, 0),
|
||||
smoothDiff = table.create(20, 0),
|
||||
hPrev = table.create(20 * 4, 0),
|
||||
prevHadPs = false,
|
||||
nbPrev = 71,
|
||||
-- frame parameters
|
||||
nEnv = 0,
|
||||
border = table.create(5, 0),
|
||||
iid = table.create(4 * 20, 0),
|
||||
icc = table.create(4 * 20, 0),
|
||||
-- hybrid rows [(n * 71 + k) + 1], decorrelated rows
|
||||
sr = table.create(32 * 71, 0),
|
||||
si = table.create(32 * 71, 0),
|
||||
dr = table.create(32 * 71, 0),
|
||||
di = table.create(32 * 71, 0),
|
||||
hs = table.create(32 * 20 * 4, 0),
|
||||
}
|
||||
end
|
||||
|
||||
local TMP = table.create(34, 0)
|
||||
|
||||
-- integer division truncating toward zero (the 8.6.4.6.1 mapping averages)
|
||||
local function tdiv(a: number, b: number): number
|
||||
local q = a / b
|
||||
return if q >= 0 then math.floor(q) else -math.floor(-q)
|
||||
end
|
||||
|
||||
-- one parameter kind: nEnv rows into out[(e - 1) * 20 + b] (mapped to 20 bands)
|
||||
local function readKind(st: any, nEnv: number, nr: number, fine: boolean, iid: boolean, out: { number }): boolean
|
||||
local prev = if iid then st.iidPrev else st.iccPrev
|
||||
local prevN = if iid then st.iidPrevN else st.iccPrevN
|
||||
local lo, hi = 0, 7
|
||||
if iid then
|
||||
lo = if fine then -15 else -7
|
||||
hi = -lo
|
||||
end
|
||||
for e = 1, nEnv do
|
||||
local dt = bits(1) == 1
|
||||
local bk
|
||||
if iid then
|
||||
bk = if fine then (if dt then IID_FINE_DT else IID_FINE_DF) else (if dt then IID_DT else IID_DF)
|
||||
else
|
||||
bk = if dt then ICC_DT else ICC_DF
|
||||
end
|
||||
local acc = 0
|
||||
for b = 1, nr do
|
||||
local d = huff(bk)
|
||||
if not d then
|
||||
return false
|
||||
end
|
||||
local v
|
||||
if dt then
|
||||
v = (if prevN == nr then prev[b] else 0) + d
|
||||
else
|
||||
acc += d
|
||||
v = acc
|
||||
end
|
||||
if v < lo or v > hi then
|
||||
return false
|
||||
end
|
||||
TMP[b] = v
|
||||
end
|
||||
for b = 1, nr do
|
||||
prev[b] = TMP[b]
|
||||
end
|
||||
prevN = nr
|
||||
local base = (e - 1) * 20
|
||||
if nr == 20 then
|
||||
for b = 1, 20 do
|
||||
out[base + b] = TMP[b]
|
||||
end
|
||||
elseif nr == 10 then
|
||||
for b = 1, 20 do
|
||||
out[base + b] = TMP[(b - 1) // 2 + 1]
|
||||
end
|
||||
else
|
||||
for b = 1, 20 do
|
||||
local mp = MAP34[b]
|
||||
local v = 0
|
||||
if b == 19 then
|
||||
v = tdiv(TMP[29] + TMP[30] + TMP[31] + TMP[32], 4)
|
||||
else
|
||||
v = tdiv(TMP[mp[1] + 1] * mp[3] + TMP[mp[2] + 1] * mp[4], mp[3] + mp[4])
|
||||
end
|
||||
out[base + b] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
if iid then
|
||||
st.iidPrevN = prevN
|
||||
else
|
||||
st.iccPrevN = prevN
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- ps_data (8.3 Table 8.1) at bit position pos; false when undecodable
|
||||
function Ps.parse(st: any, buf: buffer, pos: number, count: number): boolean
|
||||
SbrBits.start(buf, pos, count)
|
||||
if bits(1) == 1 then
|
||||
st.enableIid = bits(1) == 1
|
||||
st.iidMode = if st.enableIid then bits(3) else 0
|
||||
st.enableIcc = bits(1) == 1
|
||||
st.iccMode = if st.enableIcc then bits(3) else 0
|
||||
st.enableExt = bits(1) == 1
|
||||
if st.iidMode > 5 or st.iccMode > 5 then
|
||||
st.haveConfig = false
|
||||
return false
|
||||
end
|
||||
st.haveConfig = true
|
||||
end
|
||||
if not st.haveConfig then
|
||||
return false
|
||||
end
|
||||
local class = bits(1)
|
||||
local nEnv = NUM_ENV[class * 4 + bits(2) + 1]
|
||||
st.nEnv = nEnv
|
||||
for e = 1, nEnv do
|
||||
st.border[e] = if class == 1 then math.min(bits(5), 31) else (32 * e) // nEnv - 1
|
||||
end
|
||||
local iid, icc = st.iid, st.icc
|
||||
if st.enableIid then
|
||||
if not readKind(st, nEnv, NR_PAR[st.iidMode + 1], st.iidMode >= 3, true, iid) then
|
||||
return false
|
||||
end
|
||||
else
|
||||
st.iidPrevN = 0
|
||||
for i = 1, 4 * 20 do
|
||||
iid[i] = 0
|
||||
end
|
||||
end
|
||||
if st.enableIcc then
|
||||
if not readKind(st, nEnv, NR_PAR[st.iccMode + 1], false, false, icc) then
|
||||
return false
|
||||
end
|
||||
else
|
||||
st.iccPrevN = 0
|
||||
for i = 1, 4 * 20 do
|
||||
icc[i] = 0
|
||||
end
|
||||
end
|
||||
if st.enableExt then
|
||||
local cnt = bits(4)
|
||||
if cnt == 15 then
|
||||
cnt += bits(8)
|
||||
end
|
||||
SbrBits.skip(cnt * 8)
|
||||
end
|
||||
return not SbrBits.over()
|
||||
end
|
||||
|
||||
-- 8.6.4.6.2 mixing matrix for one envelope's parameters (Ra, or Rb for icc modes 3 .. 5)
|
||||
local function mixMatrix(st: any, e: number, out: { number })
|
||||
local fine = st.iidMode >= 3
|
||||
local rb = st.iccMode >= 3
|
||||
local base = (e - 1) * 20
|
||||
for b = 1, 20 do
|
||||
local ii = st.iid[base + b]
|
||||
local c = if fine then IID_FINE[ii + 16] else IID_COARSE[ii + 8]
|
||||
local rho = ICC_RHO[st.icc[base + b] + 1]
|
||||
local h11, h12, h21, h22
|
||||
if rb then
|
||||
rho = math.max(rho, 0.05)
|
||||
local alpha
|
||||
if math.abs(c - 1) < 1e-12 then
|
||||
alpha = pi / 4
|
||||
else
|
||||
alpha = 0.5 * atan(2 * c * rho / (c * c - 1))
|
||||
end
|
||||
if alpha < 0 then
|
||||
alpha += pi / 2
|
||||
end
|
||||
local cc = c + 1 / c
|
||||
local mu = 1 + (4 * rho * rho - 4) / (cc * cc)
|
||||
local gamma = atan(sqrt(math.max((1 - mu) / (1 + mu), 0)))
|
||||
local s2 = sqrt(2)
|
||||
h11 = s2 * cos(alpha) * cos(gamma)
|
||||
h12 = s2 * sin(alpha) * cos(gamma)
|
||||
h21 = -s2 * sin(alpha) * sin(gamma)
|
||||
h22 = s2 * cos(alpha) * sin(gamma)
|
||||
else
|
||||
local den = sqrt(1 + c * c)
|
||||
local c1 = sqrt(2) / den
|
||||
local c2 = sqrt(2) * c / den
|
||||
local alpha = 0.5 * acos(math.clamp(rho, -1, 1))
|
||||
local beta = alpha * (c1 - c2) / sqrt(2)
|
||||
h11 = cos(alpha + beta) * c2
|
||||
h12 = cos(beta - alpha) * c1
|
||||
h21 = sin(alpha + beta) * c2
|
||||
h22 = sin(beta - alpha) * c1
|
||||
end
|
||||
local o = (b - 1) * 4
|
||||
out[o + 1], out[o + 2], out[o + 3], out[o + 4] = h11, h12, h21, h22
|
||||
end
|
||||
end
|
||||
|
||||
local H_TO = table.create(80, 0)
|
||||
local H_FROM = table.create(80, 0)
|
||||
|
||||
-- per-slot matrices hs[(n * 20 + b) * 4 + c] interpolated between envelope borders
|
||||
local function fillMatrices(st: any)
|
||||
local hs, hPrev = st.hs, st.hPrev
|
||||
local nEnv = st.nEnv
|
||||
for i = 1, 80 do
|
||||
H_FROM[i] = hPrev[i]
|
||||
end
|
||||
local nFrom = -1
|
||||
for e = 1, nEnv do
|
||||
local ne = st.border[e]
|
||||
mixMatrix(st, e, H_TO)
|
||||
local den = math.max(ne - nFrom, 1)
|
||||
for n = nFrom + 1, math.min(ne, 31) do
|
||||
local t = (n - nFrom) / den
|
||||
local o = n * 80
|
||||
for i = 1, 80 do
|
||||
local f = H_FROM[i]
|
||||
hs[o + i] = f + (H_TO[i] - f) * t
|
||||
end
|
||||
end
|
||||
for i = 1, 80 do
|
||||
H_FROM[i] = H_TO[i]
|
||||
end
|
||||
if ne > nFrom then
|
||||
nFrom = ne
|
||||
end
|
||||
end
|
||||
for n = nFrom + 1, 31 do
|
||||
local o = n * 80
|
||||
for i = 1, 80 do
|
||||
hs[o + i] = H_FROM[i]
|
||||
end
|
||||
end
|
||||
for i = 1, 80 do
|
||||
hPrev[i] = H_FROM[i]
|
||||
end
|
||||
end
|
||||
|
||||
-- 8.6.4.3 hybrid analysis: QMF bands 0 .. 2 of slots 0 .. 37 (6 look-ahead) -> hybrid bands 0 .. 9; bands 3 .. 63
|
||||
-- pass through as hybrid bands 10 .. 70
|
||||
local BR = table.create(44, 0)
|
||||
local BI = table.create(44, 0)
|
||||
local function hybrid(st: any, xr: { number }, xi: { number }, nb: number)
|
||||
local sr, si, hist = st.sr, st.si, st.hist
|
||||
for n = 0, 31 do
|
||||
local o, x = n * 71, n * 64
|
||||
for k = 0, 9 do
|
||||
sr[o + k + 1], si[o + k + 1] = 0, 0
|
||||
end
|
||||
for k = 3, nb - 8 do
|
||||
sr[o + k + 8], si[o + k + 8] = xr[x + k + 1], xi[x + k + 1]
|
||||
end
|
||||
end
|
||||
for p = 0, 2 do
|
||||
for j = 0, 5 do
|
||||
BR[j + 1], BI[j + 1] = hist[(p * 6 + j) * 2 + 1], hist[(p * 6 + j) * 2 + 2]
|
||||
end
|
||||
for j = 0, 37 do
|
||||
BR[j + 7], BI[j + 7] = xr[j * 64 + p + 1], xi[j * 64 + p + 1]
|
||||
end
|
||||
if p == 0 then
|
||||
-- type A, Q = 8, symmetric g: y_q = A_q + i B_q, y_(7-q) = A_q - i B_q with A_q = sum_m g[m] cos(t (m - 6))
|
||||
-- (x[m] + x[12 - m]), B_q = sum_m g[m] sin(t (m - 6)) (x[m] - x[12 - m]), t = 2 pi / 8 (q + 1/2)
|
||||
for n = 0, 31 do
|
||||
local o = n * 71
|
||||
local cr, ci = BR[n + 7] * G0[7], BI[n + 7] * G0[7]
|
||||
for q = 0, 3 do
|
||||
local ar, ai, br, bi = cr, ci, 0, 0
|
||||
local hb = q * 6
|
||||
for m = 1, 6 do
|
||||
-- buf[n + 12 - m'] with m' = m - 1 (the newer tap) and its mirror buf[n + m']
|
||||
local xr, xi = BR[n + 14 - m], BI[n + 14 - m]
|
||||
local yr, yi = BR[n + m], BI[n + m]
|
||||
local c, sn = A0C[hb + m], A0S[hb + m]
|
||||
ar += c * (xr + yr)
|
||||
ai += c * (xi + yi)
|
||||
br += sn * (xr - yr)
|
||||
bi += sn * (xi - yi)
|
||||
end
|
||||
-- y_q = A + i B, y_(7-q) = A - i B
|
||||
local q0r, q0i, q1r, q1i = ar - bi, ai + br, ar + bi, ai - br
|
||||
if q == 0 then
|
||||
sr[o + 3], si[o + 3] = q0r, q0i
|
||||
sr[o + 2], si[o + 2] = q1r, q1i
|
||||
elseif q == 1 then
|
||||
sr[o + 4], si[o + 4] = q0r, q0i
|
||||
sr[o + 1], si[o + 1] = q1r, q1i
|
||||
elseif q == 2 then
|
||||
sr[o + 5], si[o + 5] = q0r + q1r, q0i + q1i
|
||||
else
|
||||
sr[o + 6], si[o + 6] = q0r + q1r, q0i + q1i
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- type B, Q = 2: q0 = g * x (low pass), q1 = g * (-1)^(m - 6) x (high pass)
|
||||
local lowTo = if p == 1 then 8 else 9
|
||||
local highTo = if p == 1 then 7 else 10
|
||||
for n = 0, 31 do
|
||||
local er, ei = BR[n + 7] * 0.5, BI[n + 7] * 0.5
|
||||
local orr, oi = 0, 0
|
||||
for m = 1, 11, 2 do
|
||||
local g = G12[m + 1]
|
||||
orr += g * BR[n + 13 - m]
|
||||
oi += g * BI[n + 13 - m]
|
||||
end
|
||||
local o = n * 71
|
||||
sr[o + lowTo], si[o + lowTo] = er + orr, ei + oi
|
||||
sr[o + highTo], si[o + highTo] = er - orr, ei - oi
|
||||
end
|
||||
end
|
||||
for j = 0, 5 do
|
||||
hist[(p * 6 + j) * 2 + 1], hist[(p * 6 + j) * 2 + 2] = xr[(26 + j) * 64 + p + 1], xi[(26 + j) * 64 + p + 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local PW = table.create(20, 0)
|
||||
local GR = table.create(20, 0)
|
||||
|
||||
-- 8.6.4.5 decorrelation of the hybrid rows
|
||||
local function decorrelate(st: any, nb: number)
|
||||
local sr, si, dr, di = st.sr, st.si, st.dr, st.di
|
||||
local peak, smooth, sdiff = st.peak, st.smooth, st.smoothDiff
|
||||
local apIn, apW, dl = st.apIn, st.apW, st.dl
|
||||
local nAp = math.min(NR_AP, nb)
|
||||
for n = 0, 31 do
|
||||
local o = n * 71
|
||||
for i = 1, 20 do
|
||||
PW[i] = 0
|
||||
end
|
||||
for k = 1, nb do
|
||||
local r, im = sr[o + k], si[o + k]
|
||||
local b = B_K[k] + 1
|
||||
PW[b] += r * r + im * im
|
||||
end
|
||||
for i = 1, 20 do
|
||||
local p = PW[i]
|
||||
local pk = PEAK_DECAY * peak[i]
|
||||
if pk < p then
|
||||
pk = p
|
||||
end
|
||||
peak[i] = pk
|
||||
local sm = smooth[i] + A_SMOOTH * (p - smooth[i])
|
||||
local sd = sdiff[i] + A_SMOOTH * (pk - p - sdiff[i])
|
||||
smooth[i], sdiff[i] = sm, sd
|
||||
GR[i] = if GAMMA * sd > sm then sm / (GAMMA * sd) else 1
|
||||
end
|
||||
-- the all-pass links' ring positions (delays 3, 4, 5) and the plain delay's (14) are shared by every band
|
||||
local cnt = st.apCnt
|
||||
local w0, w1, w2 = (cnt % 3) * 2, (5 + cnt % 4) * 2, (10 + cnt % 5) * 2
|
||||
st.apCnt = (cnt + 1) % 60
|
||||
for k = 0, nAp - 1 do
|
||||
local a4 = k * 4
|
||||
local ur, ui = apIn[a4 + 3], apIn[a4 + 4]
|
||||
apIn[a4 + 3], apIn[a4 + 4] = apIn[a4 + 1], apIn[a4 + 2]
|
||||
apIn[a4 + 1], apIn[a4 + 2] = sr[o + k + 1], si[o + k + 1]
|
||||
local pr, pi2 = PHI_R[k + 1], PHI_I[k + 1]
|
||||
ur, ui = pr * ur - pi2 * ui, pr * ui + pi2 * ur
|
||||
local qb, wb = k * 3, k * 30
|
||||
-- link m: w[n] = u[n] + a g Q w[n - d], v[n] = Q w[n - d] - a g w[n]
|
||||
local coef, qr, qim = CO[qb + 1], QF_R[qb + 1], QF_I[qb + 1]
|
||||
local w = wb + w0
|
||||
local wr, wi = apW[w + 1], apW[w + 2]
|
||||
local tr, ti = qr * wr - qim * wi, qr * wi + qim * wr
|
||||
local nr, ni = ur + tr * coef, ui + ti * coef
|
||||
ur, ui = tr - nr * coef, ti - ni * coef
|
||||
apW[w + 1], apW[w + 2] = nr, ni
|
||||
coef, qr, qim = CO[qb + 2], QF_R[qb + 2], QF_I[qb + 2]
|
||||
w = wb + w1
|
||||
wr, wi = apW[w + 1], apW[w + 2]
|
||||
tr, ti = qr * wr - qim * wi, qr * wi + qim * wr
|
||||
nr, ni = ur + tr * coef, ui + ti * coef
|
||||
ur, ui = tr - nr * coef, ti - ni * coef
|
||||
apW[w + 1], apW[w + 2] = nr, ni
|
||||
coef, qr, qim = CO[qb + 3], QF_R[qb + 3], QF_I[qb + 3]
|
||||
w = wb + w2
|
||||
wr, wi = apW[w + 1], apW[w + 2]
|
||||
tr, ti = qr * wr - qim * wi, qr * wi + qim * wr
|
||||
nr, ni = ur + tr * coef, ui + ti * coef
|
||||
ur, ui = tr - nr * coef, ti - ni * coef
|
||||
apW[w + 1], apW[w + 2] = nr, ni
|
||||
local gr = GR[B_K[k + 1] + 1]
|
||||
dr[o + k + 1], di[o + k + 1] = ur * gr, ui * gr
|
||||
end
|
||||
local dc = st.dlCnt
|
||||
st.dlCnt = (dc + 1) % 14
|
||||
for k = NR_AP, nb - 1 do
|
||||
local w = (k - NR_AP) * 28 + (if k < 42 then dc * 2 else 0)
|
||||
local vr, vi = dl[w + 1], dl[w + 2]
|
||||
dl[w + 1], dl[w + 2] = sr[o + k + 1], si[o + k + 1]
|
||||
local gr = GR[B_K[k + 1] + 1]
|
||||
dr[o + k + 1], di[o + k + 1] = vr * gr, vi * gr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function clear(t: { number })
|
||||
for i = 1, #t do
|
||||
t[i] = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- one frame: X (38 slots x 64 bands, [n * 64 + k + 1], silent from QMF band top) -> L / R QMF slots (32 x 64)
|
||||
function Ps.process(st: any, had: boolean, top: number, xr: { number }, xi: { number }, lr: { number }, li: { number }, rr: { number }, ri: { number })
|
||||
if not st.prevHadPs then
|
||||
clear(st.apIn)
|
||||
clear(st.apW)
|
||||
clear(st.dl)
|
||||
end
|
||||
if not had then
|
||||
st.nEnv = 0
|
||||
end
|
||||
-- hybrid bands above the SBR range (QMF band top and up) are silent: skipped, their delay lines cleared
|
||||
local nb = math.clamp(top + 7, 10, 71)
|
||||
if nb < st.nbPrev then
|
||||
for k = nb, st.nbPrev - 1 do
|
||||
if k < NR_AP then
|
||||
for i = k * 4 + 1, k * 4 + 4 do
|
||||
st.apIn[i] = 0
|
||||
end
|
||||
for i = k * 30 + 1, k * 30 + 30 do
|
||||
st.apW[i] = 0
|
||||
end
|
||||
else
|
||||
local d = k - NR_AP
|
||||
for i = d * 28 + 1, d * 28 + 28 do
|
||||
st.dl[i] = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
st.nbPrev = nb
|
||||
fillMatrices(st)
|
||||
hybrid(st, xr, xi, nb)
|
||||
decorrelate(st, nb)
|
||||
local sr, si, dr, di, hs = st.sr, st.si, st.dr, st.di, st.hs
|
||||
for n = 0, 31 do
|
||||
local o, x, hb = n * 71, n * 64, n * 80
|
||||
local l0r, l0i, r0r, r0i = 0, 0, 0, 0
|
||||
local l1r, l1i, r1r, r1i = 0, 0, 0, 0
|
||||
local l2r, l2i, r2r, r2i = 0, 0, 0, 0
|
||||
for k = nb - 6, 64 do
|
||||
lr[x + k], li[x + k], rr[x + k], ri[x + k] = 0, 0, 0, 0
|
||||
end
|
||||
for k = 1, nb do
|
||||
local h = hb + B_K[k] * 4
|
||||
local h11, h12, h21, h22 = hs[h + 1], hs[h + 2], hs[h + 3], hs[h + 4]
|
||||
local s_r, s_i, d_r, d_i = sr[o + k], si[o + k], dr[o + k], di[o + k]
|
||||
local Lr, Li = h11 * s_r + h21 * d_r, h11 * s_i + h21 * d_i
|
||||
local Rr, Ri = h12 * s_r + h22 * d_r, h12 * s_i + h22 * d_i
|
||||
if k <= 6 then
|
||||
l0r += Lr
|
||||
l0i += Li
|
||||
r0r += Rr
|
||||
r0i += Ri
|
||||
elseif k <= 8 then
|
||||
l1r += Lr
|
||||
l1i += Li
|
||||
r1r += Rr
|
||||
r1i += Ri
|
||||
elseif k <= 10 then
|
||||
l2r += Lr
|
||||
l2i += Li
|
||||
r2r += Rr
|
||||
r2i += Ri
|
||||
else
|
||||
lr[x + k - 7], li[x + k - 7] = Lr, Li
|
||||
rr[x + k - 7], ri[x + k - 7] = Rr, Ri
|
||||
end
|
||||
end
|
||||
lr[x + 1], li[x + 1], rr[x + 1], ri[x + 1] = l0r, l0i, r0r, r0i
|
||||
lr[x + 2], li[x + 2], rr[x + 2], ri[x + 2] = l1r, l1i, r1r, r1i
|
||||
lr[x + 3], li[x + 3], rr[x + 3], ri[x + 3] = l2r, l2i, r2r, r2i
|
||||
end
|
||||
st.prevHadPs = had
|
||||
end
|
||||
|
||||
return Ps
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,117 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/SbrBits: the MSB-first bit cursor and Huffman decoding shared by the SBR and PS payload parsers
|
||||
-- (ISO/IEC 14496-3 4.6.18 / 8.6.4; codebooks of codecs/audio/Aac/SbrTables). One payload at a time, over the core
|
||||
-- decoder's zero-padded frame copy.
|
||||
local readu32, byteswap, lshift, rshift, band = buffer.readu32, bit32.byteswap, bit32.lshift, bit32.rshift, bit32.band
|
||||
|
||||
local SbrBits = {}
|
||||
|
||||
local RB: buffer = buffer.create(16)
|
||||
local RP = 0
|
||||
local RE = 0
|
||||
local ROVER = false
|
||||
|
||||
-- the buffer must hold 4 readable bytes past (pos + count) / 8
|
||||
function SbrBits.start(buf: buffer, pos: number, count: number)
|
||||
local n = buffer.len(buf)
|
||||
if pos < 0 or count < 0 or (pos + count + 7) // 8 + 4 > n then
|
||||
RB, RP, RE, ROVER = buf, 0, 0, true
|
||||
return
|
||||
end
|
||||
RB, RP, RE, ROVER = buf, pos, pos + count, false
|
||||
end
|
||||
|
||||
-- n = 1 .. 25
|
||||
local function bits(n: number): number
|
||||
local p = RP
|
||||
RP = p + n
|
||||
if RP > RE then
|
||||
ROVER = true
|
||||
RP = RE
|
||||
return 0
|
||||
end
|
||||
return rshift(lshift(byteswap(readu32(RB, rshift(p, 3))), band(p, 7)), 32 - n)
|
||||
end
|
||||
SbrBits.bits = bits
|
||||
|
||||
function SbrBits.skip(n: number)
|
||||
RP += n
|
||||
if RP > RE then
|
||||
ROVER = true
|
||||
RP = RE
|
||||
end
|
||||
end
|
||||
|
||||
function SbrBits.pos(): number
|
||||
return RP
|
||||
end
|
||||
|
||||
function SbrBits.over(): boolean
|
||||
return ROVER
|
||||
end
|
||||
|
||||
-- codebook from { lav, lengths, codes }: { lav, peek[2^8] = sym * 32 + len (0: longer), long[len * 2^20 + code] =
|
||||
-- sym, maxLen } (sym 1-based; value = sym - 1 - lav)
|
||||
local PEEK = 8
|
||||
function SbrBits.codebook(t: { any }): { any }
|
||||
local lav, lens, codes = t[1], t[2], t[3]
|
||||
local peek = table.create(2 ^ PEEK, 0)
|
||||
local long: { [number]: number } = {}
|
||||
local maxLen = 0
|
||||
for s = 1, #lens do
|
||||
local l, c = lens[s], codes[s]
|
||||
if l > maxLen then
|
||||
maxLen = l
|
||||
end
|
||||
if l <= PEEK then
|
||||
local span = 2 ^ (PEEK - l)
|
||||
for k = 0, span - 1 do
|
||||
peek[c * span + k + 1] = s * 32 + l
|
||||
end
|
||||
else
|
||||
long[l * 1048576 + c] = s
|
||||
end
|
||||
end
|
||||
return { lav, peek, long, maxLen }
|
||||
end
|
||||
|
||||
-- the decoded value, or nil on an invalid code / the end of the payload
|
||||
function SbrBits.huff(bk: { any }): number?
|
||||
local p = RP
|
||||
local left = RE - p
|
||||
if left <= 0 then
|
||||
ROVER = true
|
||||
return nil
|
||||
end
|
||||
local w
|
||||
if left >= PEEK then
|
||||
w = rshift(lshift(byteswap(readu32(RB, rshift(p, 3))), band(p, 7)), 32 - PEEK)
|
||||
else
|
||||
w = lshift(rshift(lshift(byteswap(readu32(RB, rshift(p, 3))), band(p, 7)), 32 - left), PEEK - left)
|
||||
end
|
||||
local e = bk[2][w + 1]
|
||||
if e > 0 then
|
||||
local l = band(e, 31)
|
||||
if l > left then
|
||||
ROVER = true
|
||||
RP = RE
|
||||
return nil
|
||||
end
|
||||
RP = p + l
|
||||
return rshift(e, 5) - 1 - bk[1]
|
||||
end
|
||||
local long = bk[3]
|
||||
local code = bits(PEEK)
|
||||
for l = PEEK + 1, bk[4] do
|
||||
code = code * 2 + bits(1)
|
||||
local s = long[l * 1048576 + code]
|
||||
if s then
|
||||
return s - 1 - bk[1]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return SbrBits
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,490 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/SbrHf: SBR HF generation (4.6.18.6: chirp factors, covariance prediction, patching) and HF
|
||||
-- adjustment (4.6.18.7: mapping, current energies, gains, limiter, boost, noise floor, sinusoids, smoothing).
|
||||
-- Ported from syom 0.8.1 src/engine/sbr_hf_gen.rs, sbr_env_adjust.rs (MIT, licenses/syom-LICENSE.txt).
|
||||
local SbrTables = require("@rosetta/codecs/audio/Aac/SbrTables")
|
||||
|
||||
local sqrt, min = math.sqrt, math.min
|
||||
|
||||
local SbrHf = {}
|
||||
|
||||
local NOISE_R, NOISE_I = table.create(512, 0), table.create(512, 0)
|
||||
for i = 0, 511 do
|
||||
NOISE_R[i + 1], NOISE_I[i + 1] = SbrTables.NOISE[2 * i + 1], SbrTables.NOISE[2 * i + 2]
|
||||
end
|
||||
local LIM_GAIN = { 0.70795, 1.0, 1.41254, 1e10 }
|
||||
local H_SMOOTH = { 0.33333333333333, 0.30150283239582, 0.21816949906249, 0.11516383427084, 0.03183050093751 }
|
||||
local EPS0 = 1e-12
|
||||
local MAX_BOOST = 1.584893192
|
||||
-- 4.6.18.6.2 Table 4.183: newBw from (previous, current) bs_invf_mode
|
||||
local NEW_BW = { 0, 0.6, 0.9, 0.98, 0.6, 0.75, 0.9, 0.98, 0, 0.75, 0.9, 0.98, 0, 0.75, 0.9, 0.98 }
|
||||
|
||||
-- per-channel HF state
|
||||
function SbrHf.state(): any
|
||||
return {
|
||||
Yr = table.create(40 * 64, 0), -- X_high / Y[col * 64 + k + 1], col = slot + tHFAdj
|
||||
Yi = table.create(40 * 64, 0),
|
||||
Pr = table.create(40 * 64, 0), -- the previous frame's Y
|
||||
Pi = table.create(40 * 64, 0),
|
||||
bw = table.create(5, 0),
|
||||
prevBw = table.create(5, 0),
|
||||
prevInvf = table.create(5, 0),
|
||||
tEPrev = 16,
|
||||
kxPrev = 32,
|
||||
mPrev = 0,
|
||||
-- envelope adjuster
|
||||
gTail = table.create(4 * 64, 0),
|
||||
qTail = table.create(4 * 64, 0),
|
||||
tailM = -1,
|
||||
indexNoise = 0,
|
||||
indexSine = 0,
|
||||
sPrev = table.create(64, 0),
|
||||
sPrevKx = 0,
|
||||
lAPrev = -1,
|
||||
lEPrev = 0,
|
||||
started = false,
|
||||
}
|
||||
end
|
||||
|
||||
local alpha0r = table.create(32, 0)
|
||||
local alpha0i = table.create(32, 0)
|
||||
local alpha1r = table.create(32, 0)
|
||||
local alpha1i = table.create(32, 0)
|
||||
local alphaDone = table.create(32, 0)
|
||||
local alphaFrame = 0
|
||||
|
||||
-- 4.6.18.6.2 covariance method for source subband p (0-based), cached per frame
|
||||
local function prediction(xr: { number }, xi: { number }, p: number)
|
||||
local i = p + 1
|
||||
if alphaDone[i] == alphaFrame then
|
||||
return
|
||||
end
|
||||
alphaDone[i] = alphaFrame
|
||||
local p01r, p01i, p02r, p02i, p11, p12r, p12i, p22 = 0, 0, 0, 0, 0, 0, 0, 0
|
||||
local x2r, x2i = xr[i], xi[i]
|
||||
local x1r, x1i = xr[32 + i], xi[32 + i]
|
||||
for col = 2, 39 do
|
||||
local q = col * 32 + i
|
||||
local x0r, x0i = xr[q], xi[q]
|
||||
p01r += x0r * x1r + x0i * x1i
|
||||
p01i += x0i * x1r - x0r * x1i
|
||||
p02r += x0r * x2r + x0i * x2i
|
||||
p02i += x0i * x2r - x0r * x2i
|
||||
p11 += x1r * x1r + x1i * x1i
|
||||
p12r += x1r * x2r + x1i * x2i
|
||||
p12i += x1i * x2r - x1r * x2i
|
||||
p22 += x2r * x2r + x2i * x2i
|
||||
x2r, x2i = x1r, x1i
|
||||
x1r, x1i = x0r, x0i
|
||||
end
|
||||
local a1r, a1i, a0r, a0i = 0, 0, 0, 0
|
||||
local d = p22 * p11 - (p12r * p12r + p12i * p12i) / (1 + 1e-6)
|
||||
if d ~= 0 then
|
||||
-- (phi01 * phi12 - phi02 * phi11) / d
|
||||
a1r = (p01r * p12r - p01i * p12i - p02r * p11) / d
|
||||
a1i = (p01r * p12i + p01i * p12r - p02i * p11) / d
|
||||
end
|
||||
if p11 ~= 0 then
|
||||
-- -(phi01 + alpha1 * conj(phi12)) / phi11
|
||||
a0r = -(p01r + a1r * p12r + a1i * p12i) / p11
|
||||
a0i = -(p01i + a1i * p12r - a1r * p12i) / p11
|
||||
end
|
||||
if a0r * a0r + a0i * a0i >= 16 or a1r * a1r + a1i * a1i >= 16 then
|
||||
a0r, a0i, a1r, a1i = 0, 0, 0, 0
|
||||
end
|
||||
alpha0r[i], alpha0i[i], alpha1r[i], alpha1i[i] = a0r, a0i, a1r, a1i
|
||||
end
|
||||
|
||||
-- 4.6.18.6: X_high for the frame's envelope span; chirp factors from the invf modes
|
||||
function SbrHf.generate(e: any, c: any, h: any, xr: { number }, xi: { number })
|
||||
local yr, yi = h.Yr, h.Yi
|
||||
for i = 1, 40 * 64 do
|
||||
yr[i], yi[i] = 0, 0
|
||||
end
|
||||
local nQ = e.nQ
|
||||
local bw, prevBw, prevInvf, invf = h.bw, h.prevBw, h.prevInvf, c.invf
|
||||
for i = 1, nQ do
|
||||
local nb = NEW_BW[(prevInvf[i] or 0) * 4 + (invf[i] or 0) + 1] or 0
|
||||
local t = if nb < prevBw[i] then 0.75 * nb + 0.25 * prevBw[i] else 0.90625 * nb + 0.09375 * prevBw[i]
|
||||
bw[i] = if t < 0.015625 then 0 else t
|
||||
end
|
||||
alphaFrame += 1
|
||||
local c0 = 2 * c.tE[1] + 2
|
||||
local c1 = 2 * c.tE[c.nEnv + 1] + 2 - 1
|
||||
local kx, mapQ = e.kx, e.mapQ
|
||||
local k = kx
|
||||
for pi, num in e.patchNum do
|
||||
local start = e.patchStart[pi]
|
||||
for x = 0, num - 1 do
|
||||
local p = start + x
|
||||
prediction(xr, xi, p)
|
||||
local i = p + 1
|
||||
local b = bw[(mapQ[k - kx + 1] or 0) + 1] or 0
|
||||
local b2 = b * b
|
||||
local a0r, a0i = alpha0r[i] * b, alpha0i[i] * b
|
||||
local a1r, a1i = alpha1r[i] * b2, alpha1i[i] * b2
|
||||
local q = c0 * 32 + i
|
||||
local o = c0 * 64 + k + 1
|
||||
local m1r, m1i = xr[q - 32], xi[q - 32]
|
||||
local m2r, m2i = xr[q - 64], xi[q - 64]
|
||||
for _ = c0, c1 do
|
||||
local x0r, x0i = xr[q], xi[q]
|
||||
yr[o] = x0r + a0r * m1r - a0i * m1i + a1r * m2r - a1i * m2i
|
||||
yi[o] = x0i + a0r * m1i + a0i * m1r + a1r * m2i + a1i * m2r
|
||||
m2r, m2i = m1r, m1i
|
||||
m1r, m1i = x0r, x0i
|
||||
q += 32
|
||||
o += 64
|
||||
end
|
||||
k += 1
|
||||
end
|
||||
end
|
||||
for i = 1, nQ do
|
||||
prevBw[i] = bw[i]
|
||||
prevInvf[i] = invf[i]
|
||||
end
|
||||
end
|
||||
|
||||
-- per-envelope scratch: [ (l - 1) * 64 + m ]
|
||||
local E_MAP = table.create(5 * 64, 0)
|
||||
local Q_MAP = table.create(5 * 64, 0)
|
||||
local S_IDX = table.create(5 * 64, 0)
|
||||
local S_MAP = table.create(5 * 64, 0)
|
||||
local E_CURR = table.create(5 * 64, 0)
|
||||
local G_B = table.create(5 * 64, 0)
|
||||
local Q_B = table.create(5 * 64, 0)
|
||||
local S_B = table.create(5 * 64, 0)
|
||||
local QM = table.create(64, 0)
|
||||
local SM = table.create(64, 0)
|
||||
local GG = table.create(64, 0)
|
||||
local GMAX = table.create(64, 0)
|
||||
local QLIM = table.create(64, 0)
|
||||
local GLIM = table.create(64, 0)
|
||||
local G_T = table.create(44 * 64, 0)
|
||||
local Q_T = table.create(44 * 64, 0)
|
||||
local ENV_OF = table.create(40, 0)
|
||||
local Q_Z = table.create(5 * 64, 0)
|
||||
local SINES = table.create(5, 0)
|
||||
|
||||
-- 4.6.18.7.2 mapping of E_orig / Q_orig / sinusoids onto the subbands of each envelope
|
||||
local function mapping(e: any, c: any, h: any): number
|
||||
local kx, M = e.kx, e.M
|
||||
local nEnv = c.nEnv
|
||||
local mapH, mapL, mapQ = e.mapH, e.mapL, e.mapQ
|
||||
local eOrig, qOrig, tE, tQ = c.eOrig, c.qOrig, c.tE, c.tQ
|
||||
local fHigh = e.fHigh
|
||||
for l = 1, nEnv do
|
||||
local base = (l - 1) * 64
|
||||
local map = if c.freqRes[l] == 1 then mapH else mapL
|
||||
local nq = if c.nNoise > 1 and tE[l] >= tQ[2] then 1 else 0
|
||||
for m = 1, M do
|
||||
E_MAP[base + m] = eOrig[base + map[m] + 1]
|
||||
Q_MAP[base + m] = qOrig[nq * 8 + mapQ[m] + 1]
|
||||
S_IDX[base + m] = 0
|
||||
S_MAP[base + m] = 0
|
||||
end
|
||||
if c.hasHarm then
|
||||
for i = 1, e.nHigh do
|
||||
if c.harm[i] == 1 then
|
||||
local mid = (fHigh[i + 1] + fHigh[i]) // 2
|
||||
local mr = mid - kx
|
||||
if mr >= 0 and mr < M then
|
||||
local pr = mid - h.sPrevKx
|
||||
local prevOn = pr >= 0 and pr < 64 and h.sPrev[pr + 1] == 1
|
||||
if l - 1 >= c.lA or prevOn then
|
||||
S_IDX[base + mr + 1] = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local f = if c.freqRes[l] == 1 then fHigh else e.fLow
|
||||
for i = 1, #f - 1 do
|
||||
local lo, hi = f[i] - kx, f[i + 1] - kx
|
||||
local any = false
|
||||
for j = lo, hi - 1 do
|
||||
if S_IDX[base + j + 1] == 1 then
|
||||
any = true
|
||||
end
|
||||
end
|
||||
if any then
|
||||
for j = lo, hi - 1 do
|
||||
S_MAP[base + j + 1] = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return nEnv
|
||||
end
|
||||
|
||||
-- 4.6.18.7.3 current envelope energies E_curr
|
||||
local function energies(e: any, c: any, hdr: any, yr: { number }, yi: { number })
|
||||
local kx, M = e.kx, e.M
|
||||
for l = 1, c.nEnv do
|
||||
local base = (l - 1) * 64
|
||||
local lo = 2 * c.tE[l] + 2
|
||||
local hi = 2 * c.tE[l + 1] + 2
|
||||
local inv = 1 / (hi - lo)
|
||||
if hdr.interpolFreq then
|
||||
for m = 1, M do
|
||||
local s = 0
|
||||
local o = lo * 64 + kx + m
|
||||
for _ = lo, hi - 1 do
|
||||
local r, i = yr[o], yi[o]
|
||||
s += r * r + i * i
|
||||
o += 64
|
||||
end
|
||||
E_CURR[base + m] = s * inv
|
||||
end
|
||||
else
|
||||
local f = if c.freqRes[l] == 1 then e.fHigh else e.fLow
|
||||
for p = 1, #f - 1 do
|
||||
local kl, kh = f[p], f[p + 1] - 1
|
||||
local s = 0
|
||||
for j = kl, kh do
|
||||
local o = lo * 64 + j + 1
|
||||
for _ = lo, hi - 1 do
|
||||
local r, i = yr[o], yi[o]
|
||||
s += r * r + i * i
|
||||
o += 64
|
||||
end
|
||||
end
|
||||
local avg = s * inv / (kh - kl + 1)
|
||||
for j = kl, kh do
|
||||
E_CURR[base + j - kx + 1] = avg
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 4.6.18.7.4 / 4.6.18.7.5 gains, limiter and boost per envelope
|
||||
local function gains(e: any, c: any, hdr: any, lAPrev: number)
|
||||
local kx, M = e.kx, e.M
|
||||
local fLim = e.fLim
|
||||
local limGain = LIM_GAIN[hdr.limiterGains + 1] or 1
|
||||
for l = 1, c.nEnv do
|
||||
local base = (l - 1) * 64
|
||||
local li = l - 1
|
||||
local trans = li == c.lA or li == lAPrev
|
||||
local deltaL = if trans then 0 else 1
|
||||
for m = 1, M do
|
||||
local i = base + m
|
||||
local eo, q = E_MAP[i], Q_MAP[i]
|
||||
local ec = E_CURR[i]
|
||||
QM[m] = sqrt(eo * q / (1 + q))
|
||||
SM[m] = if S_IDX[i] == 1 then sqrt(eo / (1 + q)) else 0
|
||||
if S_MAP[i] == 1 then
|
||||
GG[m] = sqrt(eo / (1 + ec) * (q / (1 + q)))
|
||||
else
|
||||
GG[m] = sqrt(eo / ((1 + ec) * (1 + deltaL * q)))
|
||||
end
|
||||
end
|
||||
for b = 1, #fLim - 1 do
|
||||
local lo = math.max(fLim[b] - kx, 0)
|
||||
local hi = min(math.max(fLim[b + 1] - kx, 0), M)
|
||||
local num, den = EPS0, EPS0
|
||||
for m = lo + 1, hi do
|
||||
num += E_MAP[base + m]
|
||||
den += E_CURR[base + m]
|
||||
end
|
||||
local gmax = min(sqrt(num / den) * limGain, 1e5)
|
||||
for m = lo + 1, hi do
|
||||
GMAX[m] = gmax
|
||||
end
|
||||
end
|
||||
for m = 1, M do
|
||||
local g, gm, qm = GG[m], GMAX[m], QM[m]
|
||||
QLIM[m] = if g > 0 then min(qm, qm * gm / g) else qm
|
||||
GLIM[m] = min(g, gm)
|
||||
end
|
||||
for b = 1, #fLim - 1 do
|
||||
local lo = math.max(fLim[b] - kx, 0)
|
||||
local hi = min(math.max(fLim[b + 1] - kx, 0), M)
|
||||
local num, den = EPS0, EPS0
|
||||
for m = lo + 1, hi do
|
||||
num += E_MAP[base + m]
|
||||
local sm, gl = SM[m], GLIM[m]
|
||||
den += E_CURR[base + m] * gl * gl + sm * sm
|
||||
if not (sm ~= 0 or trans) then
|
||||
den += QLIM[m] * QLIM[m]
|
||||
end
|
||||
end
|
||||
local boost = min(sqrt(num / den), MAX_BOOST)
|
||||
for m = lo + 1, hi do
|
||||
G_B[base + m] = GLIM[m] * boost
|
||||
Q_B[base + m] = QLIM[m] * boost
|
||||
S_B[base + m] = SM[m] * boost
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 4.6.18.7.6 assembly of Y over the frame's envelope span
|
||||
local function assemble(e: any, c: any, hdr: any, h: any, lAPrev: number, yr: { number }, yi: { number })
|
||||
local kx, M = e.kx, e.M
|
||||
local nEnv = c.nEnv
|
||||
local tE = c.tE
|
||||
local i0, iEnd = 2 * tE[1], 2 * tE[nEnv + 1]
|
||||
local nCols = iEnd - i0
|
||||
local hSl = if hdr.smoothingMode then 0 else 4
|
||||
for col = 0, nCols - 1 do
|
||||
local t = i0 + col
|
||||
local l = nEnv
|
||||
for x = 1, nEnv do
|
||||
if t >= 2 * tE[x] and t < 2 * tE[x + 1] then
|
||||
l = x
|
||||
break
|
||||
end
|
||||
end
|
||||
ENV_OF[col + 1] = l
|
||||
end
|
||||
if hSl > 0 then
|
||||
local tail = h.tailM == M
|
||||
for j = 0, hSl - 1 do
|
||||
local d = j * 64
|
||||
for m = 1, M do
|
||||
G_T[d + m] = if tail then h.gTail[d + m] else G_B[m]
|
||||
Q_T[d + m] = if tail then h.qTail[d + m] else Q_B[m]
|
||||
end
|
||||
end
|
||||
for col = 0, nCols - 1 do
|
||||
local d = (col + hSl) * 64
|
||||
local s = (ENV_OF[col + 1] - 1) * 64
|
||||
for m = 1, M do
|
||||
G_T[d + m] = G_B[s + m]
|
||||
Q_T[d + m] = Q_B[s + m]
|
||||
end
|
||||
end
|
||||
end
|
||||
local indexNoise, indexSine = h.indexNoise, h.indexSine
|
||||
local fSine = indexSine
|
||||
-- the noise level is 0 where a sinusoid is added; per envelope: any sinusoid
|
||||
for l = 1, nEnv do
|
||||
local base = (l - 1) * 64
|
||||
local any = 0
|
||||
for m = 1, M do
|
||||
if S_B[base + m] ~= 0 then
|
||||
Q_Z[base + m] = 0
|
||||
else
|
||||
Q_Z[base + m] = Q_B[base + m]
|
||||
end
|
||||
any += S_IDX[base + m]
|
||||
end
|
||||
SINES[l] = any
|
||||
end
|
||||
for col = 0, nCols - 1 do
|
||||
local l = ENV_OF[col + 1]
|
||||
local li = l - 1
|
||||
local base = (l - 1) * 64
|
||||
local trans = li == c.lA or li == lAPrev
|
||||
fSine = (indexSine + col) % 4
|
||||
local o = (i0 + col + 2) * 64 + kx
|
||||
local ni = (indexNoise + col * M) % 512
|
||||
if hSl ~= 0 and not trans then
|
||||
local d = (col + hSl) * 64
|
||||
for m = 1, M do
|
||||
local gf, qf = 0, 0
|
||||
for j = 0, hSl do
|
||||
gf += G_T[d - j * 64 + m] * H_SMOOTH[j + 1]
|
||||
qf += Q_T[d - j * 64 + m] * H_SMOOTH[j + 1]
|
||||
end
|
||||
if S_B[base + m] ~= 0 then
|
||||
qf = 0
|
||||
end
|
||||
ni += 1
|
||||
if ni >= 512 then
|
||||
ni = 0
|
||||
end
|
||||
yr[o + m] = yr[o + m] * gf + qf * NOISE_R[ni + 1]
|
||||
yi[o + m] = yi[o + m] * gf + qf * NOISE_I[ni + 1]
|
||||
end
|
||||
elseif trans then
|
||||
local gsrc, gb = G_B, base
|
||||
if hSl ~= 0 then
|
||||
gsrc, gb = G_T, (col + hSl) * 64
|
||||
end
|
||||
for m = 1, M do
|
||||
local gf = gsrc[gb + m]
|
||||
yr[o + m] *= gf
|
||||
yi[o + m] *= gf
|
||||
end
|
||||
else
|
||||
for m = 1, M do
|
||||
local gf, qf = G_B[base + m], Q_Z[base + m]
|
||||
ni += 1
|
||||
if ni >= 512 then
|
||||
ni = 0
|
||||
end
|
||||
yr[o + m] = yr[o + m] * gf + qf * NOISE_R[ni + 1]
|
||||
yi[o + m] = yi[o + m] * gf + qf * NOISE_I[ni + 1]
|
||||
end
|
||||
end
|
||||
if SINES[l] > 0 then
|
||||
local sinRe = if fSine == 0 then 1 elseif fSine == 2 then -1 else 0
|
||||
local sinIm = if fSine == 1 then 1 elseif fSine == 3 then -1 else 0
|
||||
for m = 1, M do
|
||||
if S_IDX[base + m] == 1 then
|
||||
local sb = S_B[base + m]
|
||||
yr[o + m] += sb * sinRe
|
||||
if (m - 1 + kx) % 2 == 1 then
|
||||
yi[o + m] -= sb * sinIm
|
||||
else
|
||||
yi[o + m] += sb * sinIm
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local fNoise = (indexNoise + nCols * M) % 512
|
||||
if nCols > 0 then
|
||||
h.indexNoise = fNoise
|
||||
h.indexSine = (fSine + 1) % 4
|
||||
end
|
||||
if hSl > 0 then
|
||||
for j = 0, hSl - 1 do
|
||||
local s = (nCols + j) * 64
|
||||
local d = j * 64
|
||||
for m = 1, M do
|
||||
h.gTail[d + m] = G_T[s + m]
|
||||
h.qTail[d + m] = Q_T[s + m]
|
||||
end
|
||||
end
|
||||
h.tailM = M
|
||||
else
|
||||
h.tailM = -1
|
||||
end
|
||||
end
|
||||
|
||||
-- 4.6.18.7: adjust X_high (h.Yr / h.Yi) in place into Y
|
||||
function SbrHf.adjust(e: any, c: any, hdr: any, h: any)
|
||||
if e.reset or not h.started then
|
||||
h.indexNoise, h.indexSine = 0, 0
|
||||
h.tailM = -1
|
||||
h.lAPrev, h.lEPrev = -1, 0
|
||||
h.sPrevKx = 0
|
||||
table.clear(h.sPrev)
|
||||
for i = 1, 64 do
|
||||
h.sPrev[i] = 0
|
||||
end
|
||||
h.started = true
|
||||
end
|
||||
local lAPrev = if h.lAPrev == h.lEPrev then 0 else -1
|
||||
mapping(e, c, h)
|
||||
local yr, yi = h.Yr, h.Yi
|
||||
energies(e, c, hdr, yr, yi)
|
||||
gains(e, c, hdr, lAPrev)
|
||||
assemble(e, c, hdr, h, lAPrev, yr, yi)
|
||||
local lb = (c.nEnv - 1) * 64
|
||||
local sp = h.sPrev
|
||||
for m = 1, 64 do
|
||||
sp[m] = if m <= e.M then S_IDX[lb + m] else 0
|
||||
end
|
||||
h.sPrevKx = e.kx
|
||||
h.lAPrev = c.lA
|
||||
h.lEPrev = c.nEnv
|
||||
end
|
||||
|
||||
return SbrHf
|
||||
@@ -0,0 +1,115 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/SbrQmf: the SBR 32-band complex analysis and 64-band synthesis QMF banks (ISO/IEC 14496-3
|
||||
-- 4.6.18.4.1 / 4.6.18.4.2), through DCT-IV factorisations of the modulation (codecs/audio/Aac/SbrDct). Written from
|
||||
-- the standard; the window is codecs/audio/Aac/SbrTables.QMF_WINDOW.
|
||||
-- analysis: W(k) = 2 e^(-i 3 pi (k + 1/2) / 128) (DCT4_32(u(m) - u(63 - m)) + i DST4_32(u(m) + u(63 - m)))(k)
|
||||
-- synthesis: v(n) = -(DCT4_64(Re X) - DST4_64(Im X))(n) / 64, v(127 - n) = (DCT4_64(Re X) + DST4_64(Im X))(n) / 64
|
||||
local SbrDct = require("@rosetta/codecs/audio/Aac/SbrDct")
|
||||
local SbrTables = require("@rosetta/codecs/audio/Aac/SbrTables")
|
||||
|
||||
local SbrQmf = {}
|
||||
|
||||
local C = SbrTables.QMF_WINDOW
|
||||
local dct32, ana32, dct64, syn64 = SbrDct.dct32, SbrDct.ana32, SbrDct.dct64, SbrDct.syn64
|
||||
|
||||
-- the core decoder's samples are scaled by 1 / 32768; the SBR energies assume 16-bit sample values
|
||||
local IN_SCALE = 32768
|
||||
|
||||
-- analysis taps per output n: CA[n] = { c[2n + 128j] * IN_SCALE, j = 0 .. 4 }
|
||||
local CA: { { number } } = {}
|
||||
for n = 0, 63 do
|
||||
local w = table.create(5, 0)
|
||||
for j = 0, 4 do
|
||||
w[j + 1] = C[2 * n + 128 * j + 1] * IN_SCALE
|
||||
end
|
||||
CA[n + 1] = w
|
||||
end
|
||||
-- synthesis taps per output k: CS[k] = { c[64i + k], i = 0 .. 9 }
|
||||
local CS: { { number } } = {}
|
||||
for k = 1, 64 do
|
||||
local w = table.create(10, 0)
|
||||
for i = 0, 9 do
|
||||
w[i + 1] = C[64 * i + k]
|
||||
end
|
||||
CS[k] = w
|
||||
end
|
||||
|
||||
local A = table.create(32, 0)
|
||||
local B = table.create(32, 0)
|
||||
local CR = table.create(64, 0)
|
||||
|
||||
-- per-channel filterbank state
|
||||
function SbrQmf.state(): any
|
||||
return {
|
||||
qa = table.create(320 + 1024, 0), -- analysis input: 320 history samples, then the frame
|
||||
qs = table.create(41 * 128, 0), -- synthesis v blocks: 9 history blocks, then 32 for the frame
|
||||
XLr = table.create(40 * 32, 0), -- X_low[col * 32 + k + 1], col 0..7 = the previous frame's 32..39
|
||||
XLi = table.create(40 * 32, 0),
|
||||
}
|
||||
end
|
||||
|
||||
-- 32 analysis slots of one frame: 1024 core samples from inp[io + i * is] -> X_low columns 8 .. 39
|
||||
function SbrQmf.analysis(s: any, inp: { number }, io: number, is: number)
|
||||
local x: { number } = s.qa
|
||||
local p = io
|
||||
for i = 321, 1344 do
|
||||
x[i] = inp[p]
|
||||
p += is
|
||||
end
|
||||
local xr: { number }, xi: { number } = s.XLr, s.XLi
|
||||
table.move(xr, 1025, 1280, 1)
|
||||
table.move(xi, 1025, 1280, 1)
|
||||
local a, b, cr = A, B, CR
|
||||
for l = 0, 31 do
|
||||
local t = 353 + 32 * l
|
||||
for m = 1, 32 do
|
||||
local q, w = t - m, CA[m]
|
||||
local u0 = x[q] * w[1] + x[q - 64] * w[2] + x[q - 128] * w[3] + x[q - 192] * w[4] + x[q - 256] * w[5]
|
||||
q, w = t - 65 + m, CA[65 - m]
|
||||
local u1 = x[q] * w[1] + x[q - 64] * w[2] + x[q - 128] * w[3] + x[q - 192] * w[4] + x[q - 256] * w[5]
|
||||
a[m] = u0 - u1
|
||||
b[m] = u0 + u1
|
||||
end
|
||||
dct32(a, 0, cr)
|
||||
ana32(b, 0, cr, xr, xi, (8 + l) * 32)
|
||||
end
|
||||
table.move(x, 1025, 1344, 1)
|
||||
end
|
||||
|
||||
-- one synthesis slot: 64 complex subbands (xr / xi at [xo + k], k = 1 .. 64) -> 64 samples at out[o + j * os]
|
||||
function SbrQmf.synthesis(s: any, slot: number, xr: { number }, xi: { number }, xo: number, out: { number }, o: number, os: number)
|
||||
local v: { number } = s.qs
|
||||
local base = (9 + slot) * 128
|
||||
dct64(xr, xo, CR)
|
||||
syn64(xi, xo, CR, v, base)
|
||||
-- out(k) = sum_i v_(newest - 2i)[k] c[128i + k] + v_(newest - 2i - 1)[64 + k] c[128i + 64 + k]
|
||||
local p = o
|
||||
for k = 1, 64 do
|
||||
local q = base + k
|
||||
local w = CS[k]
|
||||
out[p] = v[q] * w[1] + v[q - 64] * w[2] + v[q - 256] * w[3] + v[q - 320] * w[4] + v[q - 512] * w[5]
|
||||
+ v[q - 576] * w[6] + v[q - 768] * w[7] + v[q - 832] * w[8] + v[q - 1024] * w[9] + v[q - 1088] * w[10]
|
||||
p += os
|
||||
end
|
||||
end
|
||||
|
||||
function SbrQmf.endFrame(s: any)
|
||||
local v: { number } = s.qs
|
||||
table.move(v, 32 * 128 + 1, 41 * 128, 1)
|
||||
end
|
||||
|
||||
function SbrQmf.reset(s: any)
|
||||
for i = 1, 1344 do
|
||||
s.qa[i] = 0
|
||||
end
|
||||
for i = 1, 41 * 128 do
|
||||
s.qs[i] = 0
|
||||
end
|
||||
for i = 1, 1280 do
|
||||
s.XLr[i], s.XLi[i] = 0, 0
|
||||
end
|
||||
end
|
||||
|
||||
return SbrQmf
|
||||
@@ -0,0 +1,411 @@
|
||||
--!strict
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac/SbrTables: SBR / PS constant tables (ISO/IEC 14496-3 4.A.6.1, 4.A.6.4, 8.A).
|
||||
-- Numbers from syom 0.8.1 src/engine (MIT, licenses/syom-LICENSE.txt), transcribed there from the standard.
|
||||
local SbrTables = {}
|
||||
|
||||
-- Table 4.A.89: c[i], the 640-tap QMF prototype window
|
||||
SbrTables.QMF_WINDOW = {
|
||||
0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, -0.0004875227, -0.0004893791, -0.0005040714, -0.0005226564,
|
||||
-0.0005466565, -0.0005677802, -0.0005870930, -0.0006132747, -0.0006312493, -0.0006540333, -0.0006777690, -0.0006941614,
|
||||
-0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598, -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869,
|
||||
-0.0007803664, -0.0007801449, -0.0007757977, -0.0007630793, -0.0007530001, -0.0007319357, -0.0007215391, -0.0006917937,
|
||||
-0.0006650415, -0.0006341594, -0.0005946118, -0.0005564576, -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175,
|
||||
-0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, 0.0000134949, 0.0001094383, 0.0002043017, 0.0002949531,
|
||||
0.0004026540, 0.0005107388, 0.0006239376, 0.0007458025, 0.0008608443, 0.0009885988, 0.0011250155, 0.0012577884,
|
||||
0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265, 0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616,
|
||||
0.0026201758, 0.0027870464, 0.0029469447, 0.0031125420, 0.0032739613, 0.0034418874, 0.0036008268, 0.0037603922,
|
||||
0.0039207432, 0.0040819753, 0.0042264269, 0.0043730719, 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603,
|
||||
0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, 0.0054196775, 0.0054876040, 0.0055475714, 0.0055938023,
|
||||
0.0056220643, 0.0056455196, 0.0056389199, 0.0056266114, 0.0055917128, 0.0055404363, 0.0054753783, 0.0053838975,
|
||||
0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469, 0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408,
|
||||
0.0035401246, 0.0032091885, 0.0028446757, 0.0024508540, 0.0020274176, 0.0015784682, 0.0010902329, 0.0005832264,
|
||||
0.0000276045, -0.0005464280, -0.0011568135, -0.0018039472, -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596,
|
||||
-0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, -0.0091325329, -0.0101150215, -0.0111315548, -0.0121849995,
|
||||
0.0132718220, 0.0143904666, 0.0155405553, 0.0167324712, 0.0179433381, 0.0191872431, 0.0204531793, 0.0217467550,
|
||||
0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429, 0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081,
|
||||
0.0344620948, 0.0359697560, 0.0374812850, 0.0390053679, 0.0405349170, 0.0420649094, 0.0436097542, 0.0451488405,
|
||||
0.0466843027, 0.0482165720, 0.0497385755, 0.0512556155, 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450,
|
||||
0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, 0.0639715898, 0.0652247106, 0.0664367512, 0.0676075985,
|
||||
0.0687043828, 0.0697630244, 0.0707628710, 0.0717002673, 0.0725682583, 0.0733620255, 0.0741003642, 0.0747452558,
|
||||
0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170, 0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924,
|
||||
0.0765050718, 0.0761748321, 0.0757305756, 0.0751576255, 0.0744664394, 0.0736406005, 0.0726774642, 0.0715826364,
|
||||
0.0703533073, 0.0689664013, 0.0674525021, 0.0657690668, 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691,
|
||||
0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, 0.0434768782, 0.0401458278, 0.0366418116, 0.0329583930,
|
||||
0.0290824006, 0.0250307561, 0.0207997072, 0.0163701258, 0.0117623832, 0.0069636862, 0.0019765601, -0.0032086896,
|
||||
-0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288, -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176,
|
||||
-0.0583705326, -0.0654409853, -0.0726943300, -0.0801372934, -0.0877547536, -0.0955533352, -0.1035329531, -0.1116826931,
|
||||
-0.1200077984, -0.1285002850, -0.1371551761, -0.1459766491, -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548,
|
||||
-0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, -0.2320690870, -0.2423016884, -0.2526480309, -0.2631053299,
|
||||
-0.2736634040, -0.2843214189, -0.2950716717, -0.3059098575, -0.3168278913, -0.3278113727, -0.3388722693, -0.3499914122,
|
||||
0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761, 0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754,
|
||||
0.4515996535, 0.4629308085, 0.4742453214, 0.4855253091, 0.4967708254, 0.5079817500, 0.5191234970, 0.5302240895,
|
||||
0.5412553448, 0.5522051258, 0.5630789140, 0.5738524131, 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932,
|
||||
0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, 0.6655139880, 0.6749663190, 0.6842353293, 0.6933282376,
|
||||
0.7022388719, 0.7109410426, 0.7194462634, 0.7277448900, 0.7358211758, 0.7436827863, 0.7513137456, 0.7587080760,
|
||||
0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120, 0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004,
|
||||
0.8138191270, 0.8185776004, 0.8230419890, 0.8272275347, 0.8311038457, 0.8346937361, 0.8379717337, 0.8409541392,
|
||||
0.8436238281, 0.8459818469, 0.8480315777, 0.8497805198, 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573,
|
||||
0.8537385600, 0.8535720573, 0.8531020949, 0.8523047035, 0.8511971524, 0.8497805198, 0.8480315777, 0.8459818469,
|
||||
0.8436238281, 0.8409541392, 0.8379717337, 0.8346937361, 0.8311038457, 0.8272275347, 0.8230419890, 0.8185776004,
|
||||
0.8138191270, 0.8087695004, 0.8034485751, 0.7978466413, 0.7919735841, 0.7858353120, 0.7794287519, 0.7727780881,
|
||||
0.7658674865, 0.7587080760, 0.7513137456, 0.7436827863, 0.7358211758, 0.7277448900, 0.7194462634, 0.7109410426,
|
||||
0.7022388719, 0.6933282376, 0.6842353293, 0.6749663190, 0.6655139880, 0.6559016302, 0.6461269695, 0.6361980107,
|
||||
0.6261242695, 0.6159109932, 0.6055783538, 0.5951123086, 0.5845403235, 0.5738524131, 0.5630789140, 0.5522051258,
|
||||
0.5412553448, 0.5302240895, 0.5191234970, 0.5079817500, 0.4967708254, 0.4855253091, 0.4742453214, 0.4629308085,
|
||||
0.4515996535, 0.4402553754, 0.4289119920, 0.4175696896, 0.4062317676, 0.3949211761, 0.3836350013, 0.3723795546,
|
||||
-0.3611589903, -0.3499914122, -0.3388722693, -0.3278113727, -0.3168278913, -0.3059098575, -0.2950716717, -0.2843214189,
|
||||
-0.2736634040, -0.2631053299, -0.2526480309, -0.2423016884, -0.2320690870, -0.2219652696, -0.2119735853, -0.2021250176,
|
||||
-0.1923966745, -0.1828172548, -0.1733808172, -0.1640958855, -0.1549607071, -0.1459766491, -0.1371551761, -0.1285002850,
|
||||
-0.1200077984, -0.1116826931, -0.1035329531, -0.0955533352, -0.0877547536, -0.0801372934, -0.0726943300, -0.0654409853,
|
||||
-0.0583705326, -0.0514804176, -0.0447806821, -0.0382776572, -0.0319531274, -0.0258227288, -0.0198834129, -0.0141288827,
|
||||
-0.0085711749, -0.0032086896, 0.0019765601, 0.0069636862, 0.0117623832, 0.0163701258, 0.0207997072, 0.0250307561,
|
||||
0.0290824006, 0.0329583930, 0.0366418116, 0.0401458278, 0.0434768782, 0.0466303305, 0.0495978676, 0.0524093821,
|
||||
0.0550460034, 0.0575152691, 0.0598166570, 0.0619602779, 0.0639444805, 0.0657690668, 0.0674525021, 0.0689664013,
|
||||
0.0703533073, 0.0715826364, 0.0726774642, 0.0736406005, 0.0744664394, 0.0751576255, 0.0757305756, 0.0761748321,
|
||||
0.0765050718, 0.0767204924, 0.0768230011, 0.0768173975, 0.0767093490, 0.0764992170, 0.0761992479, 0.0758008358,
|
||||
0.0753137336, 0.0747452558, 0.0741003642, 0.0733620255, 0.0725682583, 0.0717002673, 0.0707628710, 0.0697630244,
|
||||
0.0687043828, 0.0676075985, 0.0664367512, 0.0652247106, 0.0639715898, 0.0626857808, 0.0613455171, 0.0599837480,
|
||||
0.0585915683, 0.0571616450, 0.0557173648, 0.0542452768, 0.0527630746, 0.0512556155, 0.0497385755, 0.0482165720,
|
||||
0.0466843027, 0.0451488405, 0.0436097542, 0.0420649094, 0.0405349170, 0.0390053679, 0.0374812850, 0.0359697560,
|
||||
0.0344620948, 0.0329754081, 0.0315017608, 0.0300502657, 0.0286072173, 0.0271859429, 0.0257875847, 0.0244160992,
|
||||
0.0230680169, 0.0217467550, 0.0204531793, 0.0191872431, 0.0179433381, 0.0167324712, 0.0155405553, 0.0143904666,
|
||||
-0.0132718220, -0.0121849995, -0.0111315548, -0.0101150215, -0.0091325329, -0.0081798233, -0.0072615816, -0.0063792293,
|
||||
-0.0055337211, -0.0047222596, -0.0039401124, -0.0031933778, -0.0024826723, -0.0018039472, -0.0011568135, -0.0005464280,
|
||||
0.0000276045, 0.0005832264, 0.0010902329, 0.0015784682, 0.0020274176, 0.0024508540, 0.0028446757, 0.0032091885,
|
||||
0.0035401246, 0.0038456408, 0.0041251642, 0.0043801861, 0.0046039530, 0.0048109469, 0.0049839687, 0.0051382275,
|
||||
0.0052715758, 0.0053838975, 0.0054753783, 0.0055404363, 0.0055917128, 0.0056266114, 0.0056389199, 0.0056455196,
|
||||
0.0056220643, 0.0055938023, 0.0055475714, 0.0054876040, 0.0054196775, 0.0053471681, 0.0052461166, 0.0051407353,
|
||||
0.0050393022, 0.0049137603, 0.0047932560, 0.0046606460, 0.0045209852, 0.0043730719, 0.0042264269, 0.0040819753,
|
||||
0.0039207432, 0.0037603922, 0.0036008268, 0.0034418874, 0.0032739613, 0.0031125420, 0.0029469447, 0.0027870464,
|
||||
0.0026201758, 0.0024625616, 0.0023017254, 0.0021461583, 0.0019841140, 0.0018348265, 0.0016868083, 0.0015443219,
|
||||
0.0013902494, 0.0012577884, 0.0011250155, 0.0009885988, 0.0008608443, 0.0007458025, 0.0006239376, 0.0005107388,
|
||||
0.0004026540, 0.0002949531, 0.0002043017, 0.0001094383, 0.0000134949, -0.0000617334, -0.0001446380, -0.0002098337,
|
||||
-0.0002896981, -0.0003501175, -0.0004095121, -0.0004606325, -0.0005145572, -0.0005564576, -0.0005946118, -0.0006341594,
|
||||
-0.0006650415, -0.0006917937, -0.0007215391, -0.0007319357, -0.0007530001, -0.0007630793, -0.0007757977, -0.0007801449,
|
||||
-0.0007803664, -0.0007779869, -0.0007834332, -0.0007724848, -0.0007681371, -0.0007490598, -0.0007440941, -0.0007255043,
|
||||
-0.0007157736, -0.0006941614, -0.0006777690, -0.0006540333, -0.0006312493, -0.0006132747, -0.0005870930, -0.0005677802,
|
||||
-0.0005466565, -0.0005226564, -0.0005040714, -0.0004893791, -0.0004875227, -0.0004947518, -0.0005617692, -0.000552528,
|
||||
}
|
||||
|
||||
-- Table 4.A.88: V[k], the SBR noise table (re, im interleaved)
|
||||
SbrTables.NOISE = {
|
||||
-0.99948153278296, -0.59483417516607, 0.97113454393991, -0.67528515225647, 0.14130051758487, -0.95090983575689, -0.47005496701697, -0.37340549728647,
|
||||
0.80705063769351, 0.29653668284408, -0.38981478896926, 0.89572605717087, -0.01053049862020, -0.66959058036166, -0.91266367957293, -0.11522938140034,
|
||||
0.54840422910309, 0.75221367176302, 0.40009252867955, -0.98929400334421, -0.99867974711855, -0.88147068645358, -0.95531076805040, 0.90908757154593,
|
||||
-0.45725933317144, -0.56716323646760, -0.72929675029275, -0.98008272727324, 0.75622801399036, 0.20950329995549, 0.07069442601050, -0.78247898470706,
|
||||
0.74496252926055, -0.91169004445807, -0.96440182703856, -0.94739918296622, 0.30424629369539, -0.49438267012479, 0.66565033746925, 0.64652935542491,
|
||||
0.91697008020594, 0.17514097332009, -0.70774918760427, 0.52548653416543, -0.70051415345560, -0.45340028808763, -0.99496513054797, -0.90071908066973,
|
||||
0.98164490790123, -0.77463155528697, -0.54671580548181, -0.02570928536004, -0.01689629065389, 0.00287506445732, -0.86110349531986, 0.42548583726477,
|
||||
-0.98892980586032, -0.87881132267556, 0.51756627678691, 0.66926784710139, -0.99635026409640, -0.58107730574765, -0.99969370862163, 0.98369989360250,
|
||||
0.55266258627194, 0.59449057465591, 0.34581177741673, 0.94879421061866, 0.62664209577999, -0.74402970906471, -0.77149701404973, -0.33883658042801,
|
||||
-0.91592244254432, 0.03687901376713, -0.76285492357887, -0.91371867919124, 0.79788337195331, -0.93180971199849, 0.54473080610200, -0.11919206037186,
|
||||
-0.85639281671058, 0.42429854760451, -0.92882402971423, 0.27871809078609, -0.11708371046774, -0.99800843444966, 0.21356749817493, -0.90716295627033,
|
||||
-0.76191692573909, 0.99768118356265, 0.98111043100884, -0.95854459734407, -0.85913269895572, 0.95766566168880, -0.93307242253692, 0.49431757696466,
|
||||
0.30485754879632, -0.70540034357529, 0.85289650925190, 0.46766131791044, 0.91328082618125, -0.99839597361769, -0.05890199924154, 0.70741827819497,
|
||||
0.28398686150148, 0.34633555702188, 0.95258164539612, -0.54893416026939, -0.78566324168507, -0.75568541079691, -0.95789495447877, -0.20423194696966,
|
||||
0.82411158711197, 0.96654618432562, -0.65185446735885, -0.88734990773289, -0.93643603134666, 0.99870790442385, 0.91427159529618, -0.98290505544444,
|
||||
-0.70395684036886, 0.58796798221039, 0.00563771969365, 0.61768196727244, 0.89065051931895, 0.52783352697585, -0.68683707712762, 0.80806944710339,
|
||||
0.72165342518718, -0.69259857349564, -0.62928247730667, 0.13627037407335, 0.29938434065514, -0.46051329682246, -0.91781958879280, -0.74012716684186,
|
||||
0.99298717043688, 0.40816610075661, 0.82368298622748, -0.74036047190173, -0.98512833386833, -0.99972330709594, -0.95915368242257, -0.99237800466040,
|
||||
-0.21411126572790, -0.93424819052545, -0.68821476106884, -0.26892306315457, 0.91851997982317, 0.09358228901785, -0.96062769559127, 0.36099095133739,
|
||||
0.51646184922287, -0.71373332873917, 0.61130721139669, 0.46950141175917, 0.47336129371299, -0.27333178296162, 0.90998308703519, 0.96715662938132,
|
||||
0.44844799194357, 0.99211574628306, 0.66614891079092, 0.96590176169121, 0.74922239129237, -0.89879858826087, -0.99571588506485, 0.52785521494349,
|
||||
0.97401082477563, -0.16855870075190, 0.72683747733879, -0.48060774432251, 0.95432193457128, 0.68849603408441, -0.72962208425191, -0.76608443420917,
|
||||
-0.85359479233537, 0.88738125901579, -0.81412430338535, -0.97480768049637, -0.87930772356786, 0.74748307690436, -0.71573331064977, -0.98570608178923,
|
||||
0.83524300028228, 0.83702537075163, -0.48086065601423, -0.98848504923531, 0.97139128574778, 0.80093621198236, 0.51992825347895, 0.80247631400510,
|
||||
-0.00848591195325, -0.76670128000486, -0.70294374303036, 0.55359910445577, -0.95894428168140, -0.43265504344783, 0.97079252950321, 0.09325857238682,
|
||||
-0.92404293670797, 0.85507704027855, -0.69506469500450, 0.98633412625459, 0.26559203620024, 0.73314307966524, 0.28038443336943, 0.14537913654427,
|
||||
-0.74138124825523, 0.99310339807762, -0.01752795995444, -0.82616635284178, -0.55126773094930, -0.98898543862153, 0.97960898850996, -0.94021446752851,
|
||||
-0.99196309146936, 0.67019017358456, -0.67684928085260, 0.12631491649378, 0.09140039465500, -0.20537731453108, -0.71658965751996, -0.97788200391224,
|
||||
0.81014640078925, 0.53722648362443, 0.40616991671205, -0.26469008598449, -0.67680188682972, 0.94502052337695, 0.86849774348749, -0.18333598647899,
|
||||
-0.99500381284851, -0.02634122068550, 0.84329189340667, 0.10406957462213, -0.09215968531446, 0.69540012101253, 0.99956173327206, -0.12358542001404,
|
||||
-0.79732779473535, -0.91582524736159, 0.96349973642406, 0.96640458041000, -0.79942778496547, 0.64323902822857, -0.11566039853896, 0.28587846253726,
|
||||
-0.39922954514662, 0.94129601616966, 0.99089197565987, -0.92062625581587, 0.28631285179909, -0.91035047143603, -0.83302725605608, -0.67330410892084,
|
||||
0.95404443402072, 0.49162765398743, -0.06449863579434, 0.03250560813135, -0.99575054486311, 0.42389784469507, -0.65501142790847, 0.82546114655624,
|
||||
-0.81254441908887, -0.51627234660629, -0.99646369485481, 0.84490533520752, 0.00287840603348, 0.64768261158166, 0.70176989408455, -0.20453028573322,
|
||||
0.96361882270190, 0.40706967140989, -0.68883758192426, 0.91338958840772, -0.34875585502238, 0.71472290693300, 0.91980081243087, 0.66507455644919,
|
||||
-0.99009048343881, 0.85868021604848, 0.68865791458395, 0.55660316809678, -0.99484402129368, -0.20052559254934, 0.94214511408023, -0.99696425367461,
|
||||
-0.67414626793544, 0.49548221180078, -0.47339353684664, -0.85904328834047, 0.14323651387360, -0.94145598222488, -0.29268293575672, 0.05759224927952,
|
||||
0.43793861458754, -0.78904969892724, -0.36345126374441, 0.64874435357162, -0.08750604656825, 0.97686944362527, -0.96495267812511, -0.53960305946511,
|
||||
0.55526940659947, 0.78891523734774, 0.73538215752630, 0.96452072373404, -0.30889773919437, -0.80664389776860, 0.03574995626194, -0.97325616900959,
|
||||
0.98720684660488, 0.48409133691962, -0.81689296271203, -0.90827703628298, 0.67866860118215, 0.81284503870856, -0.15808569732583, 0.85279555024382,
|
||||
0.80723395114371, -0.24717418514605, 0.47788757329038, -0.46333147839295, 0.96367554763201, 0.38486749303242, -0.99143875716818, -0.24945277239809,
|
||||
0.83081876925833, -0.94780851414763, -0.58753191905341, 0.01290772389163, 0.95538108220960, -0.85557052096538, -0.96490920476211, -0.64020970923102,
|
||||
-0.97327101028521, 0.12378128133110, 0.91400366022124, 0.57972471346930, -0.99925837363824, 0.71084847864067, -0.86875903507313, -0.20291699203564,
|
||||
-0.26240034795124, -0.68264554369108, -0.24664412953388, -0.87642273115183, 0.02416275806869, 0.27192914288905, 0.82068619590515, -0.85087787994476,
|
||||
0.88547373760759, -0.89636802901469, -0.18173078152226, -0.26152145156800, 0.09355476558534, 0.54845123045604, -0.54668414224090, 0.95980774020221,
|
||||
0.37050990604091, -0.59910140383171, -0.70373594262891, 0.91227665827081, -0.34600785879594, -0.99441426144200, -0.68774481731008, -0.30238837956299,
|
||||
-0.26843291251234, 0.83115668004362, 0.49072334613242, -0.45359708737775, 0.38975993093975, 0.95515358099121, -0.97757125224150, 0.05305894580606,
|
||||
-0.17325552859616, -0.92770672250494, 0.99948035025744, 0.58285545563426, -0.64946246527458, 0.68645507104960, -0.12016920576437, -0.57147322153312,
|
||||
-0.58947456517751, -0.34847132454388, -0.41815140454465, 0.16276422358861, 0.99885650204884, 0.11136095490444, -0.56649614128386, -0.90494866361587,
|
||||
0.94138021032330, 0.35281916733018, -0.75725076534641, 0.53650549640587, 0.20541973692630, -0.94435144369918, 0.99980371023351, 0.79835913565599,
|
||||
0.29078277605775, 0.35393777921520, -0.62858772103030, 0.38765693387102, 0.43440904467688, -0.98546330463232, -0.98298583762390, 0.21021524625209,
|
||||
0.19513029146934, -0.94239832251867, -0.95476662400101, 0.98364554179143, 0.93379635304810, -0.70881994583682, -0.85235410573336, -0.08342347966410,
|
||||
-0.86425093011245, -0.45795025029466, 0.38879779059045, 0.97274429344593, 0.92045124735495, -0.62433652524220, 0.89162532251878, 0.54950955570563,
|
||||
-0.36834336949252, 0.96458298020975, 0.93891760988045, -0.89968353740388, 0.99267657565094, -0.03757034316958, -0.94063471614176, 0.41332338538963,
|
||||
0.99740224117019, -0.16830494996370, -0.35899413170555, -0.46633226649613, 0.05237237274947, -0.25640361602661, 0.36703583957424, -0.38653265641875,
|
||||
0.91653180367913, -0.30587628726597, 0.69000803499316, 0.90952171386132, -0.38658751133527, 0.99501571208985, -0.29250814029851, 0.37444994344615,
|
||||
-0.60182204677608, 0.86779651036123, -0.97418588163217, 0.96468523666475, 0.88461574003963, 0.57508405276414, 0.05198933055162, 0.21269661669964,
|
||||
-0.53499621979720, 0.97241553731237, -0.49429560226497, 0.98183865291903, -0.98935142339139, -0.40249159006933, -0.98081380091130, -0.72856895534041,
|
||||
-0.27338148835532, 0.99950922447209, 0.06310802338302, -0.54539587529618, -0.20461677199539, -0.14209977628489, 0.66223843141647, 0.72528579940326,
|
||||
-0.84764345483665, 0.02372316801261, -0.89039863483811, 0.88866581484602, 0.95903308477986, 0.76744927173873, 0.73504123909879, -0.03747203173192,
|
||||
-0.31744434966056, -0.36834111883652, -0.34110827591623, 0.40211222807691, 0.47803883714199, -0.39423219786288, 0.98299195879514, 0.01989791390047,
|
||||
-0.30963073129751, -0.18076720599336, 0.99992588229018, -0.26281872094289, -0.93149731080767, -0.98313162570490, 0.99923472302773, -0.80142993767554,
|
||||
-0.26024169633417, -0.75999759855752, -0.35712514743563, 0.19298963768574, -0.99899084509530, 0.74645156992493, 0.86557171579452, 0.55593866696299,
|
||||
0.33408042438752, 0.86185953874709, 0.99010736374716, 0.04602397576623, -0.66694269691195, -0.91643611810148, 0.64016792079480, 0.15649530836856,
|
||||
0.99570534804836, 0.45844586038111, -0.63431466947340, 0.21079116459234, -0.07706847005931, -0.89581437101329, 0.98590090577724, 0.88241721133981,
|
||||
0.80099335254678, -0.36851896710853, 0.78368131392666, 0.45506999802597, 0.08707806671691, 0.80938994918745, -0.86811883080712, 0.39347308654705,
|
||||
-0.39466529740375, -0.66809432114456, 0.97875325649683, -0.72467840967746, -0.95038560288864, 0.89563219587625, 0.17005239424212, 0.54683053962658,
|
||||
-0.76910792026848, -0.96226617549298, 0.99743281016846, 0.42697157037567, 0.95437383549973, 0.97002324109952, 0.99578905365569, -0.54106826257356,
|
||||
0.28058259829990, -0.85361420634036, 0.85256524470573, -0.64567607735589, -0.50608540105128, -0.65846015480300, -0.97210735183243, -0.23095213067791,
|
||||
0.95424048234441, -0.99240147091219, -0.96926570524023, 0.73775654896574, 0.30872163214726, 0.41514960556126, -0.24523839572639, 0.63206633394807,
|
||||
-0.33813265086024, -0.38661779441897, -0.05826828420146, -0.06940774188029, -0.22898461455054, 0.97054853316316, -0.18509915019881, 0.47565762892084,
|
||||
-0.10488238045009, -0.87769947402394, -0.71886586182037, 0.78030982480538, 0.99793873738654, 0.90041310491497, 0.57563307626120, -0.91034337352097,
|
||||
0.28909646383717, 0.96307783970534, 0.42188998312520, 0.48148651230437, 0.93335049681047, -0.43537023883588, -0.97087374418267, 0.86636445711364,
|
||||
0.36722871286923, 0.65291654172961, -0.81093025665696, 0.08778370229363, -0.26240603062237, -0.92774095379098, 0.83996497984604, 0.55839849139647,
|
||||
-0.99909615720225, -0.96024605713970, 0.74649464155061, 0.12144893606462, -0.74774595569805, -0.26898062008959, 0.95781667469567, -0.79047927052628,
|
||||
0.95472308713099, -0.08588776019550, 0.48708332746299, 0.99999041579432, 0.46332038247497, 0.10964126185063, -0.76497004940162, 0.89210929242238,
|
||||
0.57397389364339, 0.35289703373760, 0.75374316974495, 0.96705214651335, -0.59174397685714, -0.89405370422752, 0.75087906691890, -0.29612672982396,
|
||||
-0.98607857336230, 0.25034911730023, -0.40761056640505, -0.90045573444695, 0.66929266740477, 0.98629493401748, -0.97463695257310, -0.00190223301301,
|
||||
0.90145509409859, 0.99781390365446, -0.87259289048043, 0.99233587353666, -0.91529461447692, -0.15698707534206, -0.03305738840705, -0.37205262859764,
|
||||
0.07223051368337, -0.88805001733626, 0.99498012188353, 0.97094358113387, -0.74904939500519, 0.99985483641521, 0.04585228574211, 0.99812337444082,
|
||||
-0.89054954257993, -0.31791913188064, -0.83782144651251, 0.97637632547466, 0.33454804933804, -0.86231516800408, -0.99707579362824, 0.93237990079441,
|
||||
-0.22827527843994, 0.18874759397997, 0.67248046289143, -0.03646211390569, -0.05146538187944, -0.92599700120679, 0.99947295749905, 0.93625229707912,
|
||||
0.66951124390363, 0.98905825623893, -0.99602956559179, -0.44654715757688, 0.82104905483590, 0.99540741724928, 0.99186510988782, 0.72023001312947,
|
||||
-0.65284592392918, 0.52186723253637, 0.93885443798188, -0.74895312615259, 0.96735248738388, 0.90891816978629, -0.22225968841114, 0.57124029781228,
|
||||
-0.44132783753414, -0.92688840659280, -0.85694974219574, 0.88844532719844, 0.91783042091762, -0.46356892383970, 0.72556974415690, -0.99899555770747,
|
||||
-0.99711581834508, 0.58211560180426, 0.77638976371966, 0.94321834873819, 0.07717324253925, 0.58638399856595, -0.56049829194163, 0.82522301569036,
|
||||
0.98398893639988, 0.39467440420569, 0.47546946844938, 0.68613044836811, 0.65675089314631, 0.18331637134880, 0.03273375457980, -0.74933109564108,
|
||||
-0.38684144784738, 0.51337349030406, -0.97346267944545, -0.96549364384098, -0.53282156061942, -0.91423265091354, 0.99817310731176, 0.61133572482148,
|
||||
-0.50254500772635, -0.88829338134294, 0.01995873238855, 0.85223515096765, 0.99930381973804, 0.94578896296649, 0.82907767600783, -0.06323442598128,
|
||||
-0.58660709669728, 0.96840773806582, -0.17573736667267, -0.48166920859485, 0.83434292401346, -0.13023450646997, 0.05946491307025, 0.20511047074866,
|
||||
0.81505484574602, -0.94685947861369, -0.44976380954860, 0.40894572671545, -0.89746474625671, 0.99846578838537, 0.39677256130792, -0.74854668609359,
|
||||
-0.07588948563079, 0.74096214084170, 0.76343198951445, 0.41746629422634, -0.74490104699626, 0.94725911744610, 0.64880119792759, 0.41336660830571,
|
||||
0.62319537462542, -0.93098313552599, 0.42215817594807, -0.07712787385208, 0.02704554141885, -0.05417518053666, 0.80001773566818, 0.91542195141039,
|
||||
-0.79351832348816, -0.36208897989136, 0.63872359151636, 0.08128252493444, 0.52890520960295, 0.60048872455592, 0.74238552914587, 0.04491915291044,
|
||||
0.99096131449250, -0.19451182854402, -0.80412329643109, -0.88513818199457, -0.64612616129736, 0.72198674804544, 0.11657770663191, -0.83662833815041,
|
||||
-0.95053182488101, -0.96939905138082, -0.62228872928622, 0.82767262846661, 0.03004475787316, -0.99738896333384, -0.97987214341034, 0.36526129686425,
|
||||
-0.99986980746200, -0.36021610299715, 0.89110648599879, -0.97894250343044, 0.10407960510582, 0.77357793811619, 0.95964737821728, -0.35435818285502,
|
||||
0.50843233159162, 0.96107691266205, 0.17006334670615, -0.76854025314829, 0.25872675063360, 0.99893303933816, -0.01115998681937, 0.98496019742444,
|
||||
-0.79598702973261, 0.97138411318894, -0.99264708948101, -0.99542822402536, -0.99829663752818, 0.01877138824311, -0.70801016548184, 0.33680685948117,
|
||||
-0.70467057786826, 0.93272777501857, 0.99846021905254, -0.98725746254433, -0.63364968534650, -0.16473594423746, -0.16258217500792, -0.95939125400802,
|
||||
-0.43645594360633, -0.94805030113284, -0.99848471702976, 0.96245166923809, -0.16796458968998, -0.98987511890470, -0.87979225745213, -0.71725725041680,
|
||||
0.44183099021786, -0.93568974498761, 0.93310180125532, -0.99913308068246, -0.93941931782002, -0.56409379640356, -0.88590003188677, 0.47624600491382,
|
||||
0.99971463703691, -0.83889954253462, -0.75376385639978, 0.00814643438625, 0.93887685615875, -0.11284528204636, 0.85126435782309, 0.52349251543547,
|
||||
0.39701421446381, 0.81779634174316, -0.37024464187437, -0.87071656222959, -0.36024828242896, 0.34655735648287, -0.93388812549209, -0.84476541096429,
|
||||
-0.65298804552119, -0.18439575450921, 0.11960319006843, 0.99899346780168, 0.94292565553160, 0.83163906518293, 0.75081145286948, -0.35533223142265,
|
||||
0.56721979748394, -0.24076836414499, 0.46857766746029, -0.30140233457198, 0.97312313923635, -0.99548191630031, -0.38299976567017, 0.98516909715427,
|
||||
0.41025800019463, 0.02116736935734, 0.09638062008048, 0.04411984381457, -0.85283249275397, 0.91475563922421, 0.88866808958124, -0.99735267083226,
|
||||
-0.48202429536989, -0.96805608884164, 0.27572582416567, 0.58634753335832, -0.65889129659168, 0.58835634138583, 0.98838086953732, 0.99994349600236,
|
||||
-0.20651349620689, 0.54593044066355, -0.62126416356920, -0.59893681700392, 0.20320105410437, -0.86879180355289, -0.97790548600584, 0.96290806999242,
|
||||
0.11112534735126, 0.21484763313301, -0.41368337314182, 0.28216837680365, 0.24133038992960, 0.51294362630238, -0.66393410674885, -0.08249679629081,
|
||||
-0.53697829178752, -0.97649903936228, -0.97224737889348, 0.22081333579837, 0.87392477144549, -0.12796173740361, 0.19050361015753, 0.01602615387195,
|
||||
-0.46353441212724, -0.95249041539006, -0.07064096339021, -0.94479803205886, -0.92444085484466, -0.10457590187436, -0.83822593578728, -0.01695043208885,
|
||||
0.75214681811150, -0.99955681042665, -0.42102998829339, 0.99720941999394, -0.72094786237696, -0.35008961934255, 0.78843311019251, 0.52851398958271,
|
||||
0.97394027897442, -0.26695944086561, 0.99206463477946, -0.57010120849429, 0.76789609461795, -0.76519356730966, -0.82002421836409, -0.73530179553767,
|
||||
0.81924990025724, 0.99698425250579, -0.26719850873357, 0.68903369776193, -0.43311260380975, 0.85321815947490, 0.99194979673836, 0.91876249766422,
|
||||
-0.80692001248487, -0.32627540663214, 0.43080003649976, -0.21919095636638, 0.67709491937357, -0.95478075822906, 0.56151770568316, -0.70693811747778,
|
||||
0.10831862810749, -0.08628837174592, 0.91229417540436, -0.65987351408410, -0.48972893932274, 0.56289246362686, -0.89033658689697, -0.71656563987082,
|
||||
0.65269447475094, 0.65916004833932, 0.67439478141121, -0.81684380846796, -0.47770832416973, -0.16789556203025, -0.99715979260878, -0.93565784007648,
|
||||
-0.90889593602546, 0.62034397054380, -0.06618622548177, -0.23812217221359, 0.99430266919728, 0.18812555317553, 0.97686402381843, -0.28664534366620,
|
||||
0.94813650221268, -0.97506640027128, -0.95434497492853, -0.79607978501983, -0.49104783137150, 0.32895214359663, 0.99881175120751, 0.88993983831354,
|
||||
0.50449166760303, -0.85995072408434, 0.47162891065108, -0.18680204049569, -0.62081581361840, 0.75000676218956, -0.43867015250812, 0.99998069244322,
|
||||
0.98630563232075, -0.53578899600662, -0.61510362277374, -0.89515019899997, -0.03841517601843, -0.69888815681179, -0.30102157304644, -0.07667808922205,
|
||||
0.41881284182683, 0.02188098922282, -0.86135454941237, 0.98947480909359, 0.67226861393788, -0.13494389011014, -0.70737398842068, -0.76547349325992,
|
||||
0.94044946687963, 0.09026201157416, -0.82386352534327, 0.08924768823676, -0.32070666698656, 0.50143421908753, 0.57593163224487, -0.98966422921509,
|
||||
-0.36326018419965, 0.07440243123228, 0.99979044674350, -0.14130287347405, -0.92366023326932, -0.97979298068180, -0.44607178518598, -0.54233252016394,
|
||||
0.44226800932956, 0.71326756742752, 0.03671907158312, 0.63606389366675, 0.52175424682195, -0.85396826735705, -0.94701139690956, -0.01826348194255,
|
||||
-0.98759606946049, 0.82288714303073, 0.87434794743625, 0.89399495655433, -0.93412041758744, 0.41374052024363, 0.96063943315511, 0.93116709541280,
|
||||
0.97534253457837, 0.86150930812689, 0.99642466504163, 0.70190043427512, -0.94705089665984, -0.29580042814306, 0.91599807087376, -0.98147830385781,
|
||||
}
|
||||
|
||||
-- Huffman codebooks (4.A.6.1 / 8.A.1): { lav, lengths, codes }; symbol index - lav = value
|
||||
SbrTables.T_ENV15 = {
|
||||
60,
|
||||
{ 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 17, 18, 16, 17, 18, 17, 16, 16, 16, 16, 15, 14, 14, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 14, 15, 16, 17, 16, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 },
|
||||
{
|
||||
262102, 262103, 262104, 262105, 262106, 262107, 524216, 524217, 524218, 524219,
|
||||
524220, 524221, 524222, 524223, 524224, 524225, 524226, 524227, 524228, 524229,
|
||||
524230, 524231, 524232, 524233, 524234, 524235, 524236, 524237, 524238, 524239,
|
||||
524240, 524241, 524242, 524243, 131046, 262100, 65520, 131049, 262101, 131047,
|
||||
65521, 65516, 65517, 65518, 32756, 16377, 16375, 8186, 8185, 4091,
|
||||
2044, 1020, 509, 253, 125, 61, 29, 13, 5, 1,
|
||||
0, 4, 12, 28, 60, 124, 252, 508, 1021, 4090,
|
||||
8184, 16374, 16376, 32757, 65519, 131048, 65522, 524244, 524245, 524246,
|
||||
524247, 524248, 524249, 524250, 524251, 524252, 524253, 524254, 524255, 524256,
|
||||
524257, 524258, 524259, 524260, 524261, 524262, 524263, 524264, 524265, 524266,
|
||||
524267, 524268, 524269, 524270, 524271, 524272, 524273, 524274, 524275, 524276,
|
||||
524277, 524278, 524279, 524280, 524281, 524282, 524283, 524284, 524285, 524286,
|
||||
524287,
|
||||
},
|
||||
}
|
||||
SbrTables.F_ENV15 = {
|
||||
60,
|
||||
{ 19, 19, 20, 20, 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 19, 20, 19, 19, 20, 18, 20, 20, 20, 19, 20, 20, 20, 19, 20, 19, 18, 19, 18, 18, 17, 18, 17, 17, 17, 16, 16, 16, 15, 15, 14, 13, 13, 12, 12, 11, 10, 9, 9, 8, 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, 6, 8, 8, 9, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 18, 20, 19, 20, 20, 20, 20, 20, 20, 19, 20, 20, 20, 20, 19, 20, 18, 20, 20, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 },
|
||||
{
|
||||
524263, 524264, 1048530, 1048531, 1048532, 1048533, 1048534, 1048535, 1048536, 524250,
|
||||
1048537, 1048538, 1048539, 1048540, 524251, 1048541, 524252, 524253, 1048542, 262116,
|
||||
1048543, 1048544, 1048545, 524254, 1048546, 1048547, 1048548, 524255, 1048549, 524256,
|
||||
262120, 524257, 262112, 262121, 131055, 262117, 131052, 131053, 131054, 65524,
|
||||
65523, 65520, 32759, 32758, 16378, 8186, 8185, 4090, 4088, 2041,
|
||||
1019, 508, 506, 251, 124, 60, 28, 12, 5, 1,
|
||||
0, 4, 13, 29, 61, 250, 252, 507, 1018, 2040,
|
||||
2042, 2043, 4089, 4091, 8184, 8187, 16376, 16377, 65521, 65522,
|
||||
131050, 131051, 262113, 262114, 262122, 262115, 262118, 262119, 262123, 1048550,
|
||||
524258, 1048551, 1048552, 1048553, 1048554, 1048555, 1048556, 524259, 1048557, 1048558,
|
||||
1048559, 1048560, 524260, 1048561, 262124, 1048562, 1048563, 524261, 524262, 1048564,
|
||||
1048565, 1048566, 1048567, 1048568, 1048569, 1048570, 1048571, 1048572, 1048573, 1048574,
|
||||
1048575,
|
||||
},
|
||||
}
|
||||
SbrTables.T_BAL15 = {
|
||||
24,
|
||||
{ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 11, 12, 15, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17 },
|
||||
{
|
||||
65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517,
|
||||
65518, 65519, 65520, 65521, 65522, 65523, 65524, 65506, 4092, 2044,
|
||||
510, 126, 30, 6, 0, 2, 14, 62, 254, 2045,
|
||||
4093, 32752, 65507, 65525, 65526, 65527, 65528, 65529, 65530, 131062,
|
||||
131063, 131064, 131065, 131066, 131067, 131068, 131069, 131070, 131071,
|
||||
},
|
||||
}
|
||||
SbrTables.F_BAL15 = {
|
||||
24,
|
||||
{ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 16, 17, 14, 11, 11, 8, 7, 4, 2, 1, 3, 5, 6, 9, 11, 12, 15, 16, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19 },
|
||||
{
|
||||
262114, 262115, 262116, 262117, 262118, 262119, 262120, 262121, 262122, 262123,
|
||||
262124, 262125, 262126, 262127, 262128, 65527, 131056, 16380, 2046, 2044,
|
||||
254, 126, 14, 2, 0, 6, 30, 62, 510, 2045,
|
||||
4094, 32762, 65526, 262129, 262130, 262131, 262132, 262133, 262134, 262135,
|
||||
262136, 262137, 262138, 262139, 262140, 262141, 262142, 524286, 524287,
|
||||
},
|
||||
}
|
||||
SbrTables.T_ENV30 = {
|
||||
31,
|
||||
{ 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 17, 16, 16, 16, 14, 14, 14, 13, 12, 11, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 14, 14, 15, 16, 17, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 },
|
||||
{
|
||||
262125, 262126, 524254, 524255, 524256, 524257, 524258, 524259, 524260, 524261,
|
||||
524262, 524263, 524264, 524265, 524266, 524267, 524268, 131060, 65527, 65529,
|
||||
65528, 16379, 16378, 16376, 8186, 4092, 2044, 254, 62, 14,
|
||||
2, 0, 6, 30, 126, 510, 2045, 8187, 16377, 16380,
|
||||
32762, 65526, 131061, 262124, 524269, 524270, 524271, 524272, 524273, 524274,
|
||||
524275, 524276, 524277, 524278, 524279, 524280, 524281, 524282, 524283, 524284,
|
||||
524285, 524286, 524287,
|
||||
},
|
||||
}
|
||||
SbrTables.F_ENV30 = {
|
||||
31,
|
||||
{ 20, 20, 20, 20, 20, 20, 20, 18, 19, 19, 19, 19, 18, 18, 20, 19, 17, 18, 17, 16, 16, 15, 14, 12, 11, 10, 9, 8, 6, 4, 2, 1, 3, 5, 8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 18, 20, 19, 19, 19, 20, 19, 19, 20, 20, 20, 20, 20, 20 },
|
||||
{
|
||||
1048560, 1048561, 1048562, 1048563, 1048564, 1048565, 1048566, 262131, 524277, 524270,
|
||||
524271, 524278, 262132, 262130, 1048567, 524272, 131061, 262128, 131060, 65527,
|
||||
65526, 32760, 16379, 4093, 2045, 1021, 509, 253, 62, 14,
|
||||
2, 0, 6, 30, 252, 508, 1020, 2044, 4092, 8188,
|
||||
16378, 32761, 32762, 65528, 65529, 131062, 131063, 262133, 262134, 262129,
|
||||
1048568, 524273, 524274, 524275, 1048569, 524279, 524276, 1048570, 1048571, 1048572,
|
||||
1048573, 1048574, 1048575,
|
||||
},
|
||||
}
|
||||
SbrTables.T_BAL30 = {
|
||||
12,
|
||||
{ 13, 13, 13, 13, 13, 13, 13, 12, 8, 7, 4, 3, 1, 2, 5, 6, 9, 13, 13, 13, 13, 13, 13, 14, 14 },
|
||||
{
|
||||
8178, 8179, 8180, 8181, 8182, 8183, 8184, 4088, 254, 126,
|
||||
14, 6, 0, 2, 30, 62, 510, 8185, 8186, 8187,
|
||||
8188, 8189, 8190, 16382, 16383,
|
||||
},
|
||||
}
|
||||
SbrTables.F_BAL30 = {
|
||||
12,
|
||||
{ 13, 13, 13, 13, 13, 14, 14, 11, 8, 7, 4, 2, 1, 3, 5, 6, 9, 12, 13, 14, 14, 14, 14, 14, 14 },
|
||||
{
|
||||
8183, 8184, 8185, 8186, 8187, 16376, 16377, 2044, 254, 126,
|
||||
14, 2, 0, 6, 30, 62, 510, 4090, 8182, 16378,
|
||||
16379, 16380, 16381, 16382, 16383,
|
||||
},
|
||||
}
|
||||
SbrTables.T_NOISE30 = {
|
||||
31,
|
||||
{ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11, 8, 6, 4, 3, 1, 2, 5, 8, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14 },
|
||||
{
|
||||
8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151,
|
||||
8152, 8153, 8154, 8155, 8156, 8157, 8158, 8159, 8160, 8161,
|
||||
8162, 8163, 8164, 8165, 8166, 8167, 2034, 253, 62, 14,
|
||||
6, 0, 2, 30, 252, 1016, 8140, 8168, 8169, 8170,
|
||||
8171, 8172, 8141, 8173, 8174, 8175, 8176, 8177, 8178, 8179,
|
||||
8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189,
|
||||
8190, 16382, 16383,
|
||||
},
|
||||
}
|
||||
SbrTables.T_NOISEBAL30 = {
|
||||
12,
|
||||
{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 2, 1, 3, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 },
|
||||
{
|
||||
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
|
||||
28, 2, 0, 6, 58, 246, 247, 248, 249, 250,
|
||||
251, 252, 253, 254, 255,
|
||||
},
|
||||
}
|
||||
SbrTables.IID_DF = {
|
||||
14,
|
||||
{ 17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18 },
|
||||
{
|
||||
131067, 131068, 131069, 131066, 65532, 32764, 8189, 1022, 510, 126,
|
||||
60, 29, 13, 5, 0, 4, 12, 28, 61, 62,
|
||||
254, 2046, 8188, 16380, 16381, 32765, 131070, 262142, 262143,
|
||||
},
|
||||
}
|
||||
SbrTables.IID_DT = {
|
||||
14,
|
||||
{ 19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20 },
|
||||
{
|
||||
524281, 524282, 524283, 1048568, 1048569, 1048570, 131069, 32766, 4094, 1022,
|
||||
254, 62, 14, 2, 0, 6, 30, 126, 510, 2046,
|
||||
8190, 16382, 131068, 524280, 1048571, 1048572, 1048573, 1048574, 1048575,
|
||||
},
|
||||
}
|
||||
SbrTables.IID_FINE_DF = {
|
||||
30,
|
||||
{ 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14, 13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18 },
|
||||
{
|
||||
130740, 130741, 130422, 130423, 130420, 130421, 130698, 130699, 130696, 65152,
|
||||
130742, 65154, 65208, 32578, 32686, 16303, 8145, 8169, 4073, 2026,
|
||||
2043, 1019, 507, 511, 124, 60, 28, 12, 0, 1,
|
||||
1, 2, 1, 13, 29, 61, 125, 252, 508, 1020,
|
||||
1012, 2027, 4074, 8170, 8150, 16336, 32687, 32579, 65209, 65155,
|
||||
130743, 65153, 130697, 130702, 130703, 130700, 130701, 130738, 130739, 130736,
|
||||
130737,
|
||||
},
|
||||
}
|
||||
SbrTables.IID_FINE_DT = {
|
||||
30,
|
||||
{ 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13, 13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2, 5, 6, 7, 8, 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 },
|
||||
{
|
||||
20180, 20181, 20174, 20175, 20172, 20182, 20184, 20294, 20320, 10008,
|
||||
10009, 10084, 10085, 10093, 10161, 5047, 5078, 2503, 2537, 2541,
|
||||
1262, 1271, 632, 313, 154, 159, 32, 17, 10, 3,
|
||||
1, 0, 11, 18, 33, 76, 155, 314, 633, 624,
|
||||
1263, 1250, 2538, 2520, 5079, 5072, 10162, 10146, 10010, 10011,
|
||||
20326, 20327, 20321, 20295, 20185, 20183, 20173, 20178, 20179, 20176,
|
||||
20177,
|
||||
},
|
||||
}
|
||||
SbrTables.ICC_DF = {
|
||||
7,
|
||||
{ 14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13 },
|
||||
{
|
||||
16383, 16382, 4094, 1022, 126, 30, 6, 0, 2, 14,
|
||||
62, 254, 510, 2046, 8190,
|
||||
},
|
||||
}
|
||||
SbrTables.ICC_DT = {
|
||||
7,
|
||||
{ 14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14 },
|
||||
{
|
||||
16382, 8190, 2046, 510, 126, 30, 6, 0, 2, 14,
|
||||
62, 254, 1022, 4094, 16383,
|
||||
},
|
||||
}
|
||||
|
||||
return SbrTables
|
||||
@@ -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,10 +1,13 @@
|
||||
--!strict
|
||||
-- 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).
|
||||
--!optimize 2
|
||||
-- codecs/audio/Aac: AAC-LC decoder (ISO/IEC 14496-3 subpart 4, ISO/IEC 13818-7): AudioSpecificConfig, ADTS, raw_data_block;
|
||||
-- HE-AAC (SBR, Aac/Sbr) and HE-AACv2 (baseline PS, Aac/Ps) at the doubled rate, signalled explicitly or found in the
|
||||
-- stream (Decoder:probe). Written from the standard. Not supported: Main prediction, LTP, SSR, coupling channels,
|
||||
-- 960-sample frames, down-sampled SBR, ER / USAC (UNSUPPORTED).
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bits = require("@rosetta/core/Bits")
|
||||
local Decode = require("@rosetta/codecs/audio/Aac/Decode")
|
||||
local Sbr = require("@rosetta/codecs/audio/Aac/Sbr")
|
||||
|
||||
local Aac = {}
|
||||
|
||||
@@ -217,17 +220,25 @@ function Aac.adts(b: buffer, o: number, limit: number): Adts?
|
||||
}
|
||||
end
|
||||
|
||||
export type DecoderOptions = {
|
||||
sbr: boolean?, -- false: decode only the AAC-LC core of HE-AAC at the core rate (faster); default true
|
||||
}
|
||||
|
||||
export type Decoder = {
|
||||
config: Config,
|
||||
channels: number,
|
||||
sampleRate: number,
|
||||
frameLength: number,
|
||||
channels: number, -- output channels (2 for a mono core with parametric stereo)
|
||||
sampleRate: number, -- output rate (twice the core rate with SBR)
|
||||
frameLength: number, -- samples per channel per frame: 1024, 2048 with SBR
|
||||
pcm: { number },
|
||||
sbr: boolean,
|
||||
sbr: boolean, -- SBR data seen in the stream
|
||||
sbrOutput: boolean, -- SBR decoding on (sampleRate is the SBR rate)
|
||||
ps: boolean, -- parametric stereo output
|
||||
onExtension: ((kind: number, element: number, buf: buffer, bitPos: number, bits: number) -> ())?,
|
||||
decode: (self: Decoder, buf: buffer, offset: number?, length: number?) -> (number?, Err.Err?),
|
||||
probe: (self: Decoder, buf: buffer, offset: number?, length: number?) -> boolean,
|
||||
reset: (self: Decoder) -> (),
|
||||
state: Decode.State,
|
||||
allowSbr: boolean,
|
||||
}
|
||||
|
||||
local function decode(self: Decoder, buf: buffer, offset: number?, length: number?): (number?, Err.Err?)
|
||||
@@ -245,16 +256,17 @@ local function decode(self: Decoder, buf: buffer, offset: number?, length: numbe
|
||||
if st.sbr then
|
||||
self.sbr = true
|
||||
end
|
||||
local fl = self.frameLength
|
||||
if chans == 0 then
|
||||
for i = 1, 1024 * self.channels do
|
||||
for i = 1, fl * self.channels do
|
||||
st.pcm[i] = 0
|
||||
end
|
||||
return 1024, nil
|
||||
return fl, nil
|
||||
end
|
||||
if chans ~= self.channels then
|
||||
return nil, Err.new(Err.CORRUPT, string.format("frame has %d channels, the configuration %d", chans, self.channels), o)
|
||||
end
|
||||
return 1024, nil
|
||||
return fl, nil
|
||||
end
|
||||
|
||||
local function reset(self: Decoder)
|
||||
@@ -264,9 +276,76 @@ local function reset(self: Decoder)
|
||||
end
|
||||
c.prevShape = 0
|
||||
end
|
||||
for _, e in self.state.sbrElems do
|
||||
Sbr.restart(e)
|
||||
end
|
||||
end
|
||||
|
||||
function Aac.decoder(asc: any): (Decoder?, Err.Err?)
|
||||
local function enableSbr(self: Decoder, rate: number, ps: boolean)
|
||||
local st = self.state
|
||||
st.sbrOn, st.sbrRate = true, rate
|
||||
st.psOut = ps and self.config.channels == 1
|
||||
st.sbrElems = {}
|
||||
self.sbrOutput = true
|
||||
self.ps = st.psOut
|
||||
self.sampleRate = rate
|
||||
self.channels = if st.psOut then 2 else self.config.channels
|
||||
self.frameLength = 2048
|
||||
end
|
||||
|
||||
-- implicit signalling (14496-3 1.6.5.3): SBR / PS data in this frame switch the output to the doubled rate (and a mono
|
||||
-- core with PS to stereo); call on the first frames before reading sampleRate / channels. true when it switched.
|
||||
local function probe(self: Decoder, buf: buffer, offset: number?, length: number?): boolean
|
||||
local cfg = self.config
|
||||
if not self.allowSbr or self.ps or (self.sbrOutput and cfg.channels ~= 1) or type(buf) ~= "buffer" then
|
||||
return false
|
||||
end
|
||||
local o = offset or 0
|
||||
local n = length or (buffer.len(buf) - o)
|
||||
if o < 0 or n < 0 or o + n > buffer.len(buf) or cfg.sampleRate * 2 > 96000 then
|
||||
return false
|
||||
end
|
||||
local scratch = Decode.state(cfg.sfIndex)
|
||||
scratch.channels = cfg.channels
|
||||
scratch.map = self.state.map
|
||||
scratch.sbrOn = true
|
||||
scratch.probe = true
|
||||
scratch.sbrRate = cfg.sampleRate * 2
|
||||
scratch.psOut = cfg.channels == 1
|
||||
local chans = Decode.frame(scratch, buf, o, n)
|
||||
if not chans or not scratch.sbr then
|
||||
return false
|
||||
end
|
||||
local ps = false
|
||||
for _, e in scratch.sbrElems do
|
||||
if e.ps and e.ps.haveConfig then
|
||||
ps = true
|
||||
end
|
||||
end
|
||||
if self.sbrOutput and not ps then
|
||||
return false
|
||||
end
|
||||
enableSbr(self, self.config.sampleRate * 2, ps)
|
||||
return true
|
||||
end
|
||||
|
||||
-- probe the first frames (offs / sizes: 1-based packet lists) then reset; true when the output format changed
|
||||
function Aac.probeFrames(d: Decoder, buf: buffer, offs: { number }, sizes: { number }, maxFrames: number?): boolean
|
||||
local changed = false
|
||||
for i = 1, math.min(#offs, maxFrames or 8) do
|
||||
if d:probe(buf, offs[i], sizes[i]) then
|
||||
changed = true
|
||||
end
|
||||
-- SBR data is in every frame of an HE-AAC stream; a PS header may come later
|
||||
if i >= 2 and not d.sbrOutput or d.ps or (d.sbrOutput and d.config.channels ~= 1) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return changed
|
||||
end
|
||||
|
||||
function Aac.decoder(asc: any, opts: DecoderOptions?): (Decoder?, Err.Err?)
|
||||
local allowSbr = not (opts and opts.sbr == false)
|
||||
local cfg: Config
|
||||
if type(asc) == "buffer" then
|
||||
local c, err = Aac.config(asc)
|
||||
@@ -300,18 +379,28 @@ function Aac.decoder(asc: any): (Decoder?, Err.Err?)
|
||||
if cfg.channelConfig >= 3 then
|
||||
st.map = CONFIG_MAP[cfg.channelConfig]
|
||||
end
|
||||
return {
|
||||
local d: Decoder = {
|
||||
config = cfg,
|
||||
channels = cfg.channels,
|
||||
sampleRate = cfg.sampleRate,
|
||||
frameLength = 1024,
|
||||
pcm = st.pcm,
|
||||
sbr = cfg.sbr,
|
||||
sbrOutput = false,
|
||||
ps = false,
|
||||
onExtension = nil,
|
||||
decode = decode,
|
||||
probe = probe,
|
||||
reset = reset,
|
||||
state = st,
|
||||
}, nil
|
||||
allowSbr = allowSbr,
|
||||
}
|
||||
-- explicit signalling; an extension rate equal to the core rate is down-sampled SBR (the core is decoded alone)
|
||||
local ext = cfg.extensionRate or cfg.sampleRate * 2
|
||||
if allowSbr and cfg.sbr and ext == cfg.sampleRate * 2 and ext <= 96000 then
|
||||
enableSbr(d, ext, cfg.ps)
|
||||
end
|
||||
return d, nil
|
||||
end
|
||||
|
||||
return Aac
|
||||
@@ -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.
|
||||
|
||||
@@ -171,7 +171,9 @@ end
|
||||
|
||||
-- mpc_compute_new_V: 32 subband samples Y[y .. y + 31] -> 64 V values at V[o .. o + 63] (the ISO 11172-3 matrixing
|
||||
-- through Byeong Gi Lee's fast DCT)
|
||||
local function newV(Y: { number }, y: number, V: { number }, o: number)
|
||||
-- (two halves: as one function, its native lowering fails register allocation and the whole function runs
|
||||
-- interpreted)
|
||||
local function newVEven(Y: { number }, y: number, V: { number }, o: number)
|
||||
local A00 = Y[y] + Y[y + 31]
|
||||
local A01 = Y[y + 1] + Y[y + 30]
|
||||
local A02 = Y[y + 2] + Y[y + 29]
|
||||
@@ -273,6 +275,12 @@ local function newV(Y: { number }, y: number, V: { number }, o: number)
|
||||
t = -(A12 + A14 + A15)
|
||||
V[o + 46] = t - A08
|
||||
V[o + 42] = t - A10 - A11
|
||||
end
|
||||
|
||||
local function newVOdd(Y: { number }, y: number, V: { number }, o: number)
|
||||
local A00, A01, A02, A03, A04, A05, A06, A07, A08, A09, A10, A11, A12, A13, A14, A15
|
||||
local B00, B01, B02, B03, B04, B05, B06, B07, B08, B09, B10, B11, B12, B13, B14, B15
|
||||
local t
|
||||
A00 = (Y[y] - Y[y + 31]) * 0.5006030202
|
||||
A01 = (Y[y + 1] - Y[y + 30]) * 0.5054709315
|
||||
A02 = (Y[y + 2] - Y[y + 29]) * 0.5154473186
|
||||
@@ -384,6 +392,11 @@ local function newV(Y: { number }, y: number, V: { number }, o: number)
|
||||
V[o + 96 - i] = V[o + i]
|
||||
end
|
||||
end
|
||||
|
||||
local function newV(Y: { number }, y: number, V: { number }, o: number)
|
||||
newVEven(Y, y, V, o)
|
||||
newVOdd(Y, y, V, o)
|
||||
end
|
||||
export type State = {
|
||||
version: number,
|
||||
maxBand: number,
|
||||
|
||||
@@ -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")
|
||||
|
||||
Loaded 100 of 388 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user