// Positional audio example with HRTF // Copyright (C) 2021, 2023, 2025 Nguyễn Gia Phong // // This file is part of zeal. // // Zeal is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Zeal is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with zeal. If not, see . const std = @import("std"); const allocator = std.heap.c_allocator; const args = std.process.argsWithAllocator; const print = std.debug.print; const sleep = std.time.sleep; const zeal = @import("zeal"); const Device = zeal.Device; const Context = zeal.Context; const Audio = zeal.Audio; const Buffer = zeal.Buffer; const Source = zeal.Source; pub fn main() !void { const device = try Device.init(null); defer device.deinit() catch unreachable; const context = try Context.init(device, .{ .hrtf = .true }); if (try device.get(.hrtf)) print("HRTF enabled!\n", .{}) else print("HRTF not enabled!\n", .{}); defer context.deinit() catch unreachable; var argv = try args(allocator); defer argv.deinit(); _ = argv.next().?; const audio = try Audio.read(allocator, argv.next().?); defer audio.free(); try context.makeCurrent(); const buffer = try Buffer.init(audio); defer buffer.deinit() catch unreachable; const source = try Source.init(); defer source.deinit() catch unreachable; try source.setSpatialize(true); try source.bind(buffer); try source.play(); defer print("\n", .{}); while (try source.isPlaying()) { const offset = try source.getSecOffset(); try source.setPosition(.{ @sin(offset), 0, @cos(offset) }); print("\r{d:.1} s", .{ try source.getSecOffset() }); sleep(10_000_000); } }