Something went wrong. Try again.
Sample-rate conversion for audio in Zig: any rate to any other, as a stream
Something went wrong. Try again.
zig-resample build.zig
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
const std = @import("std");
pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const docs_port = b.option(u16, "docs-port", "Port for `zig build docs-serve` (default 8000)") orelse 8000;
const mod = b.addModule("resample", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, });
const test_step = b.step("test", "Run the tests"); const check_step = b.step("check", "Compile everything without running it");
const mod_tests = b.addTest(.{ .root_module = mod }); test_step.dependOn(&b.addRunArtifact(mod_tests).step); check_step.dependOn(&mod_tests.step);
// The fuzz target: whatever rates, channels and samples it is handed. // Its seeds are written out in tests/fuzz.zig itself. const fuzz_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("tests/fuzz.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "resample", .module = mod }}, }), }); test_step.dependOn(&b.addRunArtifact(fuzz_tests).step); check_step.dependOn(&fuzz_tests.step);
// A step of its own for `zig build fuzz --fuzz`, which takes over the // terminal and runs until stopped, so `zig build test` must not reach // it. On Zig 0.16.0 it finds no coverage; tools/fuzz.zig says more. b.step("fuzz", "The fuzz target: add --fuzz to fuzz it").dependOn(&b.addRunArtifact(fuzz_tests).step);
// The loop that drives the same target without Zig's fuzzer. Optimized, // since a fuzzer's whole job is how many inputs it gets through, and // ReleaseSafe keeps every check that makes a failure a failure; Debug, // with -Dfuzz-optimize=Debug, for a stack trace to read when running one // finding again. const fuzz_optimize = b.option(std.builtin.OptimizeMode, "fuzz-optimize", "How to build `fuzz-run` (default ReleaseSafe)") orelse .ReleaseSafe; const fuzz_run = b.addExecutable(.{ .name = "zig-resample-fuzz", .root_module = b.createModule(.{ .root_source_file = b.path("tools/fuzz.zig"), .target = b.graph.host, .optimize = fuzz_optimize, .imports = &.{.{ .name = "fuzz_targets", .module = b.createModule(.{ .root_source_file = b.path("tests/fuzz.zig"), .target = b.graph.host, .optimize = fuzz_optimize, .imports = &.{.{ .name = "resample", .module = b.createModule(.{ .root_source_file = b.path("src/root.zig"), .target = b.graph.host, .optimize = fuzz_optimize, }) }}, }) }}, }), }); const run_fuzz = b.addRunArtifact(fuzz_run); run_fuzz.stdio = .inherit; if (b.args) |a| run_fuzz.addArgs(a); b.step("fuzz-run", "Fuzz the target with a loop of our own").dependOn(&run_fuzz.step); check_step.dependOn(&fuzz_run.step);
// The documentation is a side effect of compiling, so the module is built // as a library purely to get at it. const library = b.addLibrary(.{ .name = "resample", .root_module = mod }); const install_docs = b.addInstallDirectory(.{ .source_dir = library.getEmittedDocs(), .install_dir = .prefix, .install_subdir = "docs", }); b.step("docs", "Build the API documentation into zig-out/docs").dependOn(&install_docs.step);
const docs_server = b.addExecutable(.{ .name = "docs-server", .root_module = b.createModule(.{ .root_source_file = b.path("tools/docs_server.zig"), // Always the machine running the build, never whatever -Dtarget // the library is being built for. .target = b.graph.host, .optimize = .Debug, }), }); const run_docs_server = b.addRunArtifact(docs_server); run_docs_server.step.dependOn(&install_docs.step); run_docs_server.addArg(b.getInstallPath(.prefix, "docs")); run_docs_server.addArg(b.fmt("{d}", .{docs_port})); // It runs until interrupted, so its output has to reach the terminal // rather than being captured by the build runner. run_docs_server.stdio = .inherit; b.step("docs-serve", "Serve the API documentation over HTTP").dependOn(&run_docs_server.step);
// The docs server has a test of its own, and nothing else builds it. test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = docs_server.root_module })).step); check_step.dependOn(&docs_server.step);}