diff options
author | makefunstuff <[email protected]> | 2024-07-05 00:32:19 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-05 00:32:19 +0200 |
commit | de19dea8068d20051fe8400aa16c7584b4ac6193 (patch) | |
tree | 4786f61e6698f815e401371939968b79650a459b | |
parent | 07e524536fe43efed9da83a8be5024a68d2e4110 (diff) | |
download | tinkerbunk-de19dea8068d20051fe8400aa16c7584b4ac6193.tar.gz |
debug
-rw-r--r-- | src/brr.zig | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/brr.zig b/src/brr.zig index be5168b..106da09 100644 --- a/src/brr.zig +++ b/src/brr.zig @@ -55,9 +55,19 @@ pub fn brr(allocator: std.mem.Allocator, file: []const u8) !void { const buffer_ptr = @as([*c]u8, @ptrCast(&buffer[0])); while (c.mpg123_read(handle, buffer_ptr, buffer_size, &done) == c.MPG123_OK) { - const frames = @divExact(@as(c_ulong, @intCast(done)), @as(c_ulong, @intCast(channels * 2))); + std.log.info("Read {} bytes from MP3 file", .{done}); + const frames = done / 4; std.log.debug("Starting sending", .{}); const write_state = c.snd_pcm_writei(pcm, buffer_ptr, @as(c_ulong, frames)); + if (write_state < 0) { + if (write_state == -c.EPIPE) { // Buffer underrun + _ = c.snd_pcm_prepare(pcm); + } else { + break; + } + } else if (write_state != frames) { + std.log.warn("Short write, expected {} frames but wrote {}\n", .{ frames, write_state }); + } std.log.info("Written pcm frames {}", .{write_state}); } _ = c.mpg123_delete(handle); |