MoonBit-native WAV parser, PCM decoder, waveform analysis, validation, and audio utility toolkit.
moon add Ridge-Lab/moonwavkit@0.1.1moon check
moon test
moon run cmd/main
moon run examples/basictest "parse decode analyze wav" {
let bytes = @moonwavkit.fixture_pcm16_mono()
let parsed = @moonwavkit.parse_wav(bytes)
assert_true(parsed.ok)
let decoded = @moonwavkit.decode_pcm(bytes, parsed.wav)
assert_true(decoded.ok)
let stats = @moonwavkit.analyze_audio(decoded.float_buffer)
assert_true(stats.peak >= 0.999)
}moon run cmd/mainmoon run cmd/main -- --jsonmoon run examples/basic| 分类 | API |
|---|---|
| 解析 | parse_wav(bytes), validate_wav(bytes), validate_wav_detailed(bytes) |
| 解码 | decode_pcm(bytes, wav), parse_and_decode(bytes) |
| 统计 | analyze_audio(buffer), summarize_waveform(buffer, buckets), channel_stats(buffer) |
| PCM 工具 | apply_gain, normalize_peak, trim_silence, resample_linear, encode_float_to_pcm_bytes, build_wav_from_float |
| 元数据 | collect_info_catalog, collect_cue_timeline, describe_wav, chunk_table_to_text |
| 质量 | inspect_audio_quality, quality_profile_to_text, recommended_quality_action |
| 验收 | fixture_catalog, run_fixture_catalog, fixture_catalog_passed, support_matrix_to_text |
pub(all) struct AmplitudeHistogram {
bins : Array[AmplitudeBin]
sample_count : Int
bin_count : Int
} derive(Eq, Debug)fn BufferComparison::success(sample_count : Int, max_abs_error : Double, mean_abs_error : Double, equal_with_tolerance : Bool) -> BufferComparisonpub(all) struct BufferMixResult {
ok : Bool
mixed_frames : Int
buffer : FloatBuffer
error : WavError
} derive(Eq, Debug)pub(all) struct ByteEncodeResult {
ok : Bool
encoding : PcmEncoding
bytes : Array[Int]
error : WavError
} derive(Eq, Debug)fn ByteReader::matches_ascii(self : ByteReader, offset : Int, a : Int, b : Int, c : Int, d : Int) -> Boolpub(all) struct DecodeResult {
ok : Bool
pcm : PcmBuffer
float_buffer : FloatBuffer
error : WavError
} derive(Eq, Debug)pub(all) struct FixtureCase {
name : String
bytes : Array[Int]
expectation : FixtureExpectation
expected_error : String
} derive(Eq, Debug)fn FixtureCase::new(name : String, bytes : Array[Int], expectation : FixtureExpectation, expected_error? : String) -> FixtureCasefn FixtureCaseResult::new(name : String, passed : Bool, expectation : String, actual_error : String, frames : Int, channels : Int, sample_rate : Int) -> FixtureCaseResultpub(all) struct LoopResult {
ok : Bool
repeats : Int
source_range : FrameRange
buffer : FloatBuffer
error : WavError
} derive(Eq, Debug)fn LoopResult::success(repeats : Int, source_range : FrameRange, buffer : FloatBuffer) -> LoopResultpub(all) struct NormalizeReport {
ok : Bool
gain : Double
target_peak : Double
before_peak : Double
after_peak : Double
buffer : FloatBuffer
error : WavError
} derive(Eq, Debug)fn NormalizeReport::success(gain : Double, target_peak : Double, before_peak : Double, buffer : FloatBuffer) -> NormalizeReportpub(all) struct ParsedWav {
header : RiffHeader
format : WaveFormat
chunks : Array[WaveChunk]
info_tags : Array[InfoTag]
cue_points : Array[CuePoint]
fact_sample_count : Int
data_offset : Int
data_size : Int
source_length : Int
} derive(Eq, Debug)pub(all) struct QualityFinding {
kind : QualityFindingKind
severity : ValidationSeverity
message : String
value : Double
} derive(Eq, Debug)fn QualityFinding::new(kind : QualityFindingKind, severity : ValidationSeverity, message : String, value? : Double) -> QualityFindingpub(all) struct QualityProfile {
ok : Bool
score : Int
stats : AudioStats
crest_factor : Double
zero_crossing_rate : Double
findings : Array[QualityFinding]
} derive(Eq, Debug)pub(all) struct ResampleResult {
ok : Bool
source_sample_rate : Int
target_sample_rate : Int
source_frames : Int
target_frames : Int
buffer : FloatBuffer
error : WavError
} derive(Eq, Debug)fn ResampleResult::success(source_sample_rate : Int, target_sample_rate : Int, source_frames : Int, buffer : FloatBuffer) -> ResampleResultfn SupportEntry::new(encoding : String, bits_per_sample : Int, can_parse : Bool, can_decode : Bool, can_encode : Bool, notes : String) -> SupportEntrypub(all) struct TrimResult {
ok : Bool
start_frame : Int
end_frame : Int
removed_start_frames : Int
removed_end_frames : Int
buffer : FloatBuffer
error : WavError
} derive(Eq, Debug)fn TrimResult::success(start_frame : Int, end_frame : Int, source_frames : Int, buffer : FloatBuffer) -> TrimResultpub(all) struct ValidationIssue {
severity : ValidationSeverity
code : String
message : String
offset : Int
} derive(Eq, Debug)fn ValidationIssue::new(severity : ValidationSeverity, code : String, message : String, offset? : Int) -> ValidationIssuepub(all) struct ValidationReport {
ok : Bool
error_count : Int
warning_count : Int
info_count : Int
format : WaveFormat
info : WaveInfo
issues : Array[ValidationIssue]
chunks : Array[ChunkSummary]
} derive(Eq, Debug)pub(all) struct WaveFormat {
audio_format : Int
encoding : WaveEncoding
channels : Int
sample_rate : Int
byte_rate : Int
block_align : Int
bits_per_sample : Int
extra_size : Int
} derive(Eq, Debug)fn WaveFormat::new(audio_format : Int, channels : Int, sample_rate : Int, byte_rate : Int, block_align : Int, bits_per_sample : Int, extra_size? : Int) -> WaveFormatpub(all) struct WaveformSummary {
buckets : Array[WaveformBucket]
bucket_count : Int
source_samples : Int
} derive(Eq, Debug)fn channel_stats(buffer : FloatBuffer, silence_threshold? : Double, clip_threshold? : Double) -> Array[ChannelStats]fn compare_buffers(expected : FloatBuffer, actual : FloatBuffer, tolerance? : Double) -> BufferComparisonfn detect_silence_regions(buffer : FloatBuffer, min_run : Int, threshold? : Double) -> Array[WaveChunk]fn detect_silence_sample_regions(buffer : FloatBuffer, min_run : Int, threshold? : Double) -> Array[SampleRegion]fn find_clipping_regions(buffer : FloatBuffer, min_run? : Int, threshold? : Double) -> Array[SampleRegion]fn loop_region(buffer : FloatBuffer, start_frame : Int, frame_count : Int, repeats : Int) -> LoopResultfn mix_buffers(a : FloatBuffer, b : FloatBuffer, gain_a? : Double, gain_b? : Double) -> BufferMixResultfn slice_seconds(buffer : FloatBuffer, start_seconds : Double, duration_seconds : Double) -> FloatBufferMoonBit-native WAV parser, PCM decoder, waveform analysis, validation, and audio utility toolkit.