diff options
author | makefunstuff <[email protected]> | 2024-07-03 20:09:46 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-03 20:09:46 +0200 |
commit | 4c2c4da7842e6214591df43f3fa2a2c75b224a4e (patch) | |
tree | a9aed64ebdb0cc969e1addd4f6f2a30e49babb4a /src | |
parent | 1fcbe4d80efc66493fe8924892a98f9d2009ff16 (diff) | |
download | tinkerbunk-4c2c4da7842e6214591df43f3fa2a2c75b224a4e.tar.gz |
borken
Diffstat (limited to '')
-rw-r--r-- | src/brr.zig | 37 | ||||
-rw-r--r-- | src/main.zig | 6 |
2 files changed, 24 insertions, 19 deletions
diff --git a/src/brr.zig b/src/brr.zig index aad554d..3a0c94c 100644 --- a/src/brr.zig +++ b/src/brr.zig @@ -4,47 +4,48 @@ const c = @cImport({ @cInclude("alsa/asoundlib.h"); }); -pub fn brr(file: []const u8) void { +pub fn brr(file: []const u8) !void { _ = c.mpg123_init(); const handle = c.mpg123_new(null, null) orelse { std.log.warn("Failed to create mpg123 handle\n", .{}); return; }; - defer c.mpg123_delete(handle); const file_path = file.ptr; if (c.mpg123_open(handle, file_path) != 0) { - std.log.warn("Filed to open the file: {}\n", .{file_path}); + std.log.warn("Filed to open the file: {s}\n", .{file_path}); return; } - var pcm: c.snd_pcm_t = undefined; + var pcm: ?*c.snd_pcm_t = undefined; if (c.snd_pcm_open(&pcm, "default", c.SND_PCM_STREAM_PLAYBACK, 0) < 0) { std.log.warn("Failed to open ALSA device\n", .{}); return; } - defer c.snd_pcm_close(pcm); + var params: ?*c.snd_pcm_hw_params_t = null; + _ = c.snd_pcm_hw_params_malloc(¶ms); - var params: *c.snd_pcm_hw_params_t = undefined; - c.snd_pcm_hw_params_malloc(¶ms); - defer c.snd_pcm_hw_params_free(params); + _ = c.snd_pcm_hw_params(pcm, params); + _ = c.snd_pcm_hw_params_set_access(pcm, params, c.SND_PCM_FORMAT_S16_LE); + _ = c.snd_pcm_hw_params_set_channels(pcm, params, 2); + _ = c.snd_pcm_hw_params_set_rate(pcm, params, 44100, 0); - c.snd_pcm_hw_params(pcm, params); - c.snd_pcm_hw_params_set_access(pcm, params, c.SND_PCM_FORMAT_S16_LE); - c.snd_pcm_hw_params_set_channels(pcm, params, 2); - c.snd_pcm_hw_params_set_rate(pcm, params, 44100, 0); - - c.snd_pcm_hw_params(pcm, params); + _ = c.snd_pcm_hw_params(pcm, params); var buffer: [4096]u8 = undefined; while (true) { - var done: c.size_t = 0; - c.mpg123_read(handle, &buffer[0], buffer.len, &done); + var done: usize = 0; + _ = c.mpg123_read(handle, &buffer[0], buffer.len, &done); - if (done == 0) break; + if (done == 0) { + _ = c.mpg123_delete(handle); + _ = c.snd_pcm_hw_params_free(params); + _ = c.snd_pcm_close(pcm); + break; + } - c.snd_pcm_writei(pcm, &buffer[0], done / 4); + _ = c.snd_pcm_writei(pcm, &buffer[0], done / 4); } } diff --git a/src/main.zig b/src/main.zig index 498b928..e054495 100644 --- a/src/main.zig +++ b/src/main.zig @@ -59,7 +59,11 @@ pub fn main() !void { .TCP => try socket_server.start_server(), .WINDOW => try sdl_window.present_sdl_window(), // TODO: parse options for arguments - .BRR => try brr.brr(args[2]), + // TODO: fix compile errors + // .BRR => try brr.brr(args[2]), + else => { + return; + }, } } |