blob: 2db3d7896ce539ed3fa1156f9828be7693735c67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Positional audio example with HRTF
// Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
const std = @import("std");
const allocator = std.heap.c_allocator;
const args = std.process.args;
const print = std.debug.print;
const sleep = std.time.sleep;
const zeal = @import("zeal");
const al = zeal.al;
const alc = zeal.alc;
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, &.{ alc.HRTF, alc.TRUE });
if (try device.enabledHrtf())
print("HRTF enabled!\n", .{})
else
print("HRTF not enabled!\n", .{});
defer context.deinit() catch unreachable;
var argv = args();
allocator.free(try argv.next(allocator).?);
const path = try argv.next(allocator).?;
defer allocator.free(path);
const audio = try Audio.read(allocator, path);
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(al.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) });
sleep(10_000_000);
}
}
|