audio: increase soundio binding coverage for running sine-wine example
This commit is contained in:
parent
d3b7df882e
commit
0e3461e25f
6 changed files with 114 additions and 6 deletions
11
audio/soundio/ChannelLayout.zig
Normal file
11
audio/soundio/ChannelLayout.zig
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const c = @import("c.zig");
|
||||||
|
const intToError = @import("error.zig").intToError;
|
||||||
|
const Error = @import("error.zig").Error;
|
||||||
|
|
||||||
|
const ChannelLayout = @This();
|
||||||
|
|
||||||
|
handle: c.SoundIoChannelLayout,
|
||||||
|
|
||||||
|
pub fn channelCount(self: ChannelLayout) i32 {
|
||||||
|
return self.handle.channel_count;
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,19 @@
|
||||||
|
const std = @import("std");
|
||||||
const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
const OutStream = @import("OutStream.zig");
|
||||||
|
|
||||||
const SoundIoDevice = @This();
|
const Device = @This();
|
||||||
|
|
||||||
handle: *c.SoundIoDevice,
|
handle: *c.SoundIoDevice,
|
||||||
|
|
||||||
|
pub fn unref(self: Device) void {
|
||||||
|
c.soundio_device_unref(self.handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(self: Device) [:0]const u8 {
|
||||||
|
return std.mem.span(self.handle.*.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn createOutStream(self: Device) error{OutOfMemory}!OutStream {
|
||||||
|
return OutStream{ .handle = c.soundio_outstream_create(self.handle) orelse return error.OutOfMemory };
|
||||||
|
}
|
||||||
|
|
|
||||||
55
audio/soundio/OutStream.zig
Normal file
55
audio/soundio/OutStream.zig
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
const c = @import("c.zig");
|
||||||
|
const intToError = @import("error.zig").intToError;
|
||||||
|
const Error = @import("error.zig").Error;
|
||||||
|
const Format = @import("enums.zig").Format;
|
||||||
|
const ChannelLayout = @import("ChannelLayout.zig");
|
||||||
|
|
||||||
|
const OutStream = @This();
|
||||||
|
|
||||||
|
pub const WriteCallback = fn (stream: ?[*]c.SoundIoOutStream, frame_count_min: c_int, frame_count_max: c_int) callconv(.C) void;
|
||||||
|
|
||||||
|
handle: *c.SoundIoOutStream,
|
||||||
|
|
||||||
|
pub fn deinit(self: OutStream) void {
|
||||||
|
c.soundio_outstream_destroy(self.handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open(self: OutStream) Error!void {
|
||||||
|
try intToError(c.soundio_outstream_open(self.handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start(self: OutStream) Error!void {
|
||||||
|
try intToError(c.soundio_outstream_start(self.handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn beginWrite(self: OutStream, areas: [*]?[*]c.SoundIoChannelArea, frame_count: *i32) Error!void {
|
||||||
|
try intToError(c.soundio_outstream_begin_write(
|
||||||
|
self.handle,
|
||||||
|
areas,
|
||||||
|
frame_count,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn endWrite(self: OutStream) Error!void {
|
||||||
|
try intToError(c.soundio_outstream_end_write(self.handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setFormat(self: OutStream, format: Format) void {
|
||||||
|
self.handle.*.format = @enumToInt(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setWriteCallback(self: OutStream, callback: WriteCallback) void {
|
||||||
|
self.handle.*.write_callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn layout(self: OutStream) ChannelLayout {
|
||||||
|
return ChannelLayout{ .handle = self.handle.*.layout };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sampleRate(self: OutStream) i32 {
|
||||||
|
return self.handle.*.sample_rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn layoutError(self: OutStream) Error!void {
|
||||||
|
try intToError(self.handle.*.layout_error);
|
||||||
|
}
|
||||||
|
|
@ -8,8 +8,8 @@ const SoundIo = @This();
|
||||||
|
|
||||||
handle: *c.SoundIo,
|
handle: *c.SoundIo,
|
||||||
|
|
||||||
pub fn init() Error!SoundIo {
|
pub fn init() error{OutOfMemory}!SoundIo {
|
||||||
return SoundIo{ .handle = c.soundio_create() orelse return Error.OutOfMemory };
|
return SoundIo{ .handle = c.soundio_create() orelse return error.OutOfMemory };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: SoundIo) void {
|
pub fn deinit(self: SoundIo) void {
|
||||||
|
|
@ -32,6 +32,10 @@ pub fn flushEvents(self: SoundIo) void {
|
||||||
c.soundio_flush_events(self.handle);
|
c.soundio_flush_events(self.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn waitEvents(self: SoundIo) void {
|
||||||
|
c.soundio_wait_events(self.handle);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn defaultInputDeviceIndex(self: SoundIo) ?u16 {
|
pub fn defaultInputDeviceIndex(self: SoundIo) ?u16 {
|
||||||
const index = c.soundio_default_input_device_index(self.handle);
|
const index = c.soundio_default_input_device_index(self.handle);
|
||||||
return if (index < 0) null else @intCast(u16, index);
|
return if (index < 0) null else @intCast(u16, index);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
pub const c = @import("c.zig");
|
const c = @import("c.zig");
|
||||||
|
|
||||||
pub const ChannelId = enum(u7) {
|
pub const ChannelId = enum(u7) {
|
||||||
invalid = c.SoundIoChannelIdInvalid,
|
invalid = c.SoundIoChannelIdInvalid,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,28 @@
|
||||||
pub usingnamespace @import("enums.zig");
|
pub usingnamespace @import("enums.zig");
|
||||||
pub usingnamespace @import("SoundIo.zig");
|
pub const c = @import("c.zig");
|
||||||
pub usingnamespace @import("Device.zig");
|
pub const SoundIo = @import("SoundIo.zig");
|
||||||
|
pub const Device = @import("Device.zig");
|
||||||
|
pub const OutStream = @import("OutStream.zig");
|
||||||
pub const Error = @import("error.zig").Error;
|
pub const Error = @import("error.zig").Error;
|
||||||
|
|
||||||
|
test {
|
||||||
|
refAllDecls(@import("SoundIo.zig"));
|
||||||
|
refAllDecls(@import("Device.zig"));
|
||||||
|
refAllDecls(@import("OutStream.zig"));
|
||||||
|
refAllDecls(@import("ChannelLayout.zig"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn refAllDecls(comptime T: type) void {
|
||||||
|
@setEvalBranchQuota(10000);
|
||||||
|
inline for (comptime @import("std").meta.declarations(T)) |decl| {
|
||||||
|
if (decl.is_pub) {
|
||||||
|
if (@TypeOf(@field(T, decl.name)) == type) {
|
||||||
|
switch (@typeInfo(@field(T, decl.name))) {
|
||||||
|
.Struct, .Enum, .Union, .Opaque => refAllDecls(@field(T, decl.name)),
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = @field(T, decl.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue