diff options
author | makefunstuff <[email protected]> | 2024-07-04 22:02:40 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-04 22:02:40 +0200 |
commit | b695878582fc60e4398f7c4fe486eeedd05dc5de (patch) | |
tree | 34d704e5f76e248d1261d17722a448bd228ce305 /src/brr.zig | |
parent | c3f6700f383bd1248626071e450eb6a6da08b8d4 (diff) | |
download | tinkerbunk-b695878582fc60e4398f7c4fe486eeedd05dc5de.tar.gz |
trying hard with alsa
Diffstat (limited to '')
-rw-r--r-- | src/brr.zig | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/brr.zig b/src/brr.zig index cfd6f1f..7bca832 100644 --- a/src/brr.zig +++ b/src/brr.zig @@ -4,10 +4,8 @@ const c = @cImport({ @cInclude("alsa/asoundlib.h"); }); -pub const snd_pcm_info_t = extern struct {}; -pub extern fn snd_pcm_info_malloc(pcm_info: *snd_pcm_info_t) void; -pub extern fn snd_pcm_info(pcm: *c.snd_pcm_t, pcm_info: *snd_pcm_info_t) c_int; -pub extern fn snd_pcm_info_free(pcm_info: *snd_pcm_info_t) void; +const _op_snd_pcm_info_t = opaque {}; +const snd_pcm_info_t = ?*_op_snd_pcm_info_t; pub fn brr(file: []const u8) !void { _ = c.mpg123_init(); @@ -72,13 +70,16 @@ pub fn brr(file: []const u8) !void { const frames_sent = c.snd_pcm_writei(pcm, &buffer[0], done / 4); if (frames_sent < 0) { std.log.err("Failed to write to ALSA device", .{}); - // TODO: figure out how to deal with opaque status - var pcm_info: snd_pcm_info_t = snd_pcm_info_t{}; - snd_pcm_info_malloc(&pcm_info); - _ = snd_pcm_info(pcm, &pcm_info); + var pcm_info: snd_pcm_info_t = undefined; + const alloc_result = c.snd_pcm_info_malloc(@ptrCast(&pcm_info)); + if (alloc_result == 0) { + std.log.err("Failed to allocate pcm info", .{}); + return; + } + _ = c.snd_pcm_info(pcm, @ptrCast(&pcm_info)); - defer snd_pcm_info_free(&pcm_info); - std.log.debug("pcm status is {any}", .{pcm_info}); + std.log.debug("pcm_info {?}", .{pcm_info}); + defer c.snd_pcm_info_free(@ptrCast(&pcm_info)); return; } else { std.log.info("Frames sent: {d}", .{frames_sent}); |