diff --git a/build.zig b/build.zig index d51d6665..fc665ee1 100644 --- a/build.zig +++ b/build.zig @@ -97,6 +97,13 @@ pub fn build(b: *std.Build) !void { module.addImport("mach-freetype", dep.module("mach-freetype")); module.addImport("mach-harfbuzz", dep.module("mach-harfbuzz")); } + + if (b.lazyDependency("mach_opus", .{ + .target = target, + .optimize = optimize, + })) |dep| { + module.addImport("mach-opus", dep.module("mach-opus")); + } } if (b.lazyDependency("font_assets", .{})) |dep| module.addImport("font-assets", dep.module("font-assets")); @@ -554,7 +561,6 @@ fn buildExamples( ) !void { const Dependency = enum { assets, - opus, model3d, freetype, zigimg, @@ -570,9 +576,9 @@ fn buildExamples( .{ .name = "custom-renderer", .deps = &.{} }, .{ .name = "glyphs", .deps = &.{ .freetype, .assets } }, .{ .name = "piano", .deps = &.{} }, - .{ .name = "play-opus", .deps = &.{ .opus, .assets } }, + .{ .name = "play-opus", .deps = &.{.assets} }, .{ .name = "sprite", .deps = &.{ .zigimg, .assets } }, - .{ .name = "text", .deps = &.{ .freetype, .assets } }, + .{ .name = "text", .deps = &.{.assets} }, }) |example| { if (target.result.cpu.arch == .wasm32 and !example.wasm) continue; const exe = b.addExecutable(.{ @@ -594,12 +600,6 @@ fn buildExamples( .optimize = optimize, })) |dep| exe.root_module.addImport("assets", dep.module("mach-example-assets")); }, - .opus => { - if (b.lazyDependency("mach_opus", .{ - .target = target, - .optimize = optimize, - })) |dep| exe.root_module.addImport("opus", dep.module("mach-opus")); - }, .model3d => { if (b.lazyDependency("mach_model3d", .{ .target = target, diff --git a/examples/play-opus/App.zig b/examples/play-opus/App.zig index 4374cbe5..ae9d8ff0 100644 --- a/examples/play-opus/App.zig +++ b/examples/play-opus/App.zig @@ -6,7 +6,6 @@ const builtin = @import("builtin"); const mach = @import("mach"); const assets = @import("assets"); -const Opus = @import("opus"); const gpu = mach.gpu; const math = mach.math; const sysaudio = mach.sysaudio; @@ -30,7 +29,7 @@ pub const components = .{ .is_bgm = .{ .type = void }, }; -sfx: Opus, +sfx: mach.Audio.Opus, fn init( entities: *mach.Entities.Mod, @@ -45,10 +44,10 @@ fn init( const sfx_fbs = std.io.fixedBufferStream(assets.sfx.sword1); var sound_stream = std.io.StreamSource{ .const_buffer = bgm_fbs }; - const bgm = try Opus.decodeStream(gpa.allocator(), sound_stream); + const bgm = try mach.Audio.Opus.decodeStream(gpa.allocator(), sound_stream); sound_stream = std.io.StreamSource{ .const_buffer = sfx_fbs }; - const sfx = try Opus.decodeStream(gpa.allocator(), sound_stream); + const sfx = try mach.Audio.Opus.decodeStream(gpa.allocator(), sound_stream); // Initialize module state app.init(.{ .sfx = sfx }); diff --git a/src/Audio.zig b/src/Audio.zig index a38ca1be..123f1fb9 100644 --- a/src/Audio.zig +++ b/src/Audio.zig @@ -3,6 +3,8 @@ const builtin = @import("builtin"); const mach = @import("main.zig"); const sysaudio = mach.sysaudio; +pub const Opus = @import("mach-opus"); + pub const name = .mach_audio; pub const Mod = mach.Mod(@This());