Files
audio/tests/windows_encode.zi
waozi 3a3e87311a Commit the working copy's decoder move before merging the remote
This checkout stayed at ce5837f while later work was pushed from the same
working copy: the MP3, Ogg, Vorbis and WAV decoders left for core Ziran,
Opus decoding moved into decode_opus and ogg_opus, and the tests and
native build follow. The commit records the working copy as it is so the
remote history can be merged without losing local edits.
2026-11-23 04:39:52 -03:00

39 lines
1.6 KiB
Ziran

// Full-pipeline Windows check, linked with libopus and libsamplerate:
// `encode IN.wav OUT.opus` uses the Linux CLI's voice settings (24 kbps,
// voice, wide-band cap, constrained VBR); `resample IN.wav RATE` prints the
// status so the test can assert the documented Windows sinc boundary.
#import "types"
#import "std/audio_types"
#import "pipeline"
#import "resample"
#import "std/audio_wav"
#import "std/vec"
#import "std/file"
#import "std/byte_text_linux"
#program_export
main :: (argc: s32, argv: **u8) -> s32 {
if argc != 4 { print("windows_encode encode INPUT.wav OUTPUT.opus | resample INPUT.wav 16000\n"); return Invalid }
command := TextFromCString(argv[1])
bytes: Vec(u8)
if !ReadFileInto(TextFromCString(argv[2]), *bytes) { print("input/output failed\n"); return IOFailure }
pcm: PCM
code := WavDecode(VecSlice(bytes, 0, bytes.count), MaxFrames, *pcm)
if code != OK { print("%\n", ErrorText(code)); return code }
if command == "resample" {
converted: PCM
print("%\n", ErrorText(Resample(*pcm, 16000, *converted)))
return 0
}
if command != "encode" { return Invalid }
options := DefaultOptions()
options.bitrate = 24000; options.application = .Voice; options.bandwidth = .Wide
options.vbr = true; options.constrained_vbr = true
output: Vec(u8)
code = Encode(*pcm, options, *output)
if code != OK { print("%\n", ErrorText(code)); return code }
if !WriteEntireFile(TextFromCString(argv[3]), TextFromBytes(VecSlice(output, 0, output.count))) { print("input/output failed\n"); return IOFailure }
print("wrote % bytes\n", output.count)
return 0
}