Pure MoonBit FLAC encoding and decoding for native, JavaScript and WebAssembly GC
| Area | Coverage |
|---|---|
| PCM | 4–32 valid bits, 1–8 channels, 1–1,048,575 Hz |
| Frames | Fixed/variable blocks, 16–65,535 samples, CRC8 and CRC16 |
| Subframes | Constant, verbatim, fixed 0–4, LPC 1–32, Rice/Rice2, escape, wasted bits |
| Arithmetic | Int64 prediction and stereo reconstruction, including 33-bit side channels |
| Metadata | STREAMINFO, PADDING, APPLICATION, SEEKTABLE, VORBIS_COMMENT, CUESHEET, PICTURE; unknown 7–126 retained |
| Integrity | Frame CRCs before output; available STREAMINFO MD5 checked at stream/link end |
| Containers | Native/Ogg FLAC decode with chained links; Ogg FLAC muxing from native frames |
| Access | Whole-file and incremental decode, frame index, half-open sample cropping |
| Output | Raw PCM, WAV, WAVE_FORMAT_EXTENSIBLE and RF64 |
| Encoding | Native FLAC from 4–32-bit PCM; whole-buffer and bounded streaming APIs; effort 0–8; Ogg output |
moon add 0717lee/moonflac@0.2.1moon update
moon fmt --check
for target in native js wasm-gc; do
moon check --target "$target"
moon test --target "$target"
moon build --target "$target"
moon run examples/stream --target "$target"
moon run examples/encode --target "$target"
moon run examples/ogg --target "$target"
donemoon run cmd/moonflac --target native -- info recording.flac --json
moon run cmd/moonflac --target native -- verify recording.flac
moon run cmd/moonflac --target native -- decode recording.flac output.wav
moon run cmd/moonflac --target native -- decode recording.flac excerpt.wav --start 48000 --end 96000
moon run cmd/moonflac --target native -- encode recording.wav output.flac
moon run cmd/moonflac --target native -- encode input.pcm output.flac --raw --sample-rate 48000 --channels 6 --bits 24 --channel-mask 0x060f
moon run cmd/moonflac --target native -- ogg output.flac output.ogamoonflac ogg recording.flac recording.oga
moonflac info recording.oganode playground/build.mjs
node playground/serve.mjstype Decodertype Encoderpub(all) struct EncoderConfig {
format : PcmFormat
block_size : Int
variable_block : Bool
effort : Int
channel_mask : UInt?
metadata : Array[MetadataBlock]
non_audio : Bool
max_metadata_bytes : Int
}fn EncoderConfig::new(format : PcmFormat, block_size? : Int, variable_block? : Bool, effort? : Int, channel_mask? : UInt, metadata? : Array[MetadataBlock], non_audio? : Bool, max_metadata_bytes? : Int) -> EncoderConfigpub(all) struct EncoderSummary {
total_samples : Int64
frames : Int64
min_frame_size : Int
max_frame_size : Int
md5 : Bytes
final_header : Bytes
}pub(all) struct FrameLocation {
sample : Int64
offset : Int64
samples : Int
bytes : Int
}pub(all) struct Metadata {
info : StreamInfo
blocks : Array[MetadataBlock]
seek_points : Array[SeekPoint]
comments : VorbisComment?
cuesheet : CueSheet?
cuesheets : Array[CueSheet]
pictures : Array[Picture]
} derive(Show)type OggDemuxpub struct PcmInput {
pending : BytesView
offset : Int64
ended : Bool
failed : FlacError?
stage : Int
format : PcmFormat?
announced : Bool
mask : UInt?
width : Int
shift : Int
raw : Bool
rf64 : Bool
riff_end : Int64?
chunk_left : Int64
pad : Bool
saw_data : Bool
saw_ds64 : Bool
data_size : Int64
data_size_used : Bool
expected_samples : Int64
samples : Int64
table_left : Int
sizes : Map[UInt, Array[Int64]]
size_positions : Map[UInt, Int]
}pub(all) struct Picture {
kind : UInt
media_type : String
description : String
width : UInt
height : UInt
depth : UInt
colors : UInt
data : Bytes
} derive(Show)type RawDecoderpub(all) struct SeekIndex {
metadata : Metadata
frames : Array[FrameLocation]
total_samples : Int64
integrity : Integrity
}pub(all) struct StreamInfo {
min_block_size : Int
max_block_size : Int
min_frame_size : Int
max_frame_size : Int
sample_rate : Int
channels : Int
bits_per_sample : Int
total_samples : Int64
md5 : Bytes
} derive(Show)fn encode_ogg_pcm(samples : Array[Int], config : EncoderConfig, serial? : UInt, vendor? : String) -> Bytes raise FlacErrorfn wav_header(info : StreamInfo, samples : Int64, channel_mask? : UInt, rf64? : Bool) -> Bytes raise FlacErrorInstall
Download zipPure MoonBit FLAC encoding and decoding for native, JavaScript and WebAssembly GC