Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysaudio: runtime alignment error when converting samples on Windows #1152

Open
paoda opened this issue Jan 28, 2024 · 4 comments
Open

sysaudio: runtime alignment error when converting samples on Windows #1152

paoda opened this issue Jan 28, 2024 · 4 comments
Labels
bug Something isn't working sysaudio
Milestone

Comments

@paoda
Copy link

paoda commented Jan 28, 2024

Hello!, when running the sine.zig example on Windows 10 Build 19045, I receive the following output

 ~\AppData\Local\Temp\sine                                                                                                                                                                           | 11:07:40
➜ zig build run
info: Took 6.984ms to initialize the context...
info: Took 23.701ms to refresh the context...
info: Took 88.8us to get the default playback device...
info: Took 8.264ms to create a player...
info: Took 142.9us to start the player...
info: Took 390us to set the volume...
info: player created & entering i/o loop...
( paused = false, volume = 0.8500000238418579 )
> thread 6136 panic: incorrect alignment
C:\Users\paoda\AppData\Local\zig\p\12206c2ca0378bbc54721553e8167c037325e95e2791379fbe0e245a34334679dc90\src\main.zig:346:70: 0x3694a9 in convertTo__anon_5803 (sine.exe.obj)
            f32 => conv.floatToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
                                                                     ^
C:\Users\paoda\AppData\Local\Temp\sine\src\main.zig:64:27: 0x361cd2 in writeCallback (sine.exe.obj)
        sysaudio.convertTo(
                          ^
C:\Users\paoda\AppData\Local\zig\p\12206c2ca0378bbc54721553e8167c037325e95e2791379fbe0e245a34334679dc90\src\wasapi.zig:807:31: 0x3c0700 in writeThread (sine.exe.obj)
                player.writeFn(
                              ^
C:\Users\paoda\.local\bin\zigup\zig\0.12.0-dev.2063+804cee3b9\files\lib\std\Thread.zig:411:13: 0x3a85cc in callFn__anon_8675 (sine.exe.obj)
            @call(.auto, f, args);
            ^
C:\Users\paoda\.local\bin\zigup\zig\0.12.0-dev.2063+804cee3b9\files\lib\std\Thread.zig:523:30: 0x36adfe in entryFn (sine.exe.obj)
                return callFn(f, self.fn_args);
                             ^
???:?:?: 0x7ff8f6dd7343 in ??? (KERNEL32.DLL)
???:?:?: 0x7ff8f8c426b0 in ??? (ntdll.dll)
run
└─ run sine failure
error: the following command exited with error code 3:
C:\Users\paoda\AppData\Local\Temp\sine\zig-out\bin\sine.exe
Build Summary: 3/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run sine failure
error: the following build command failed with exit code 1:
C:\Users\paoda\AppData\Local\Temp\sine\zig-cache\o\f168a5c3d0ff462674b014b722c5598d\build.exe C:\Users\paoda\.local\bin\zigup\zig\0.12.0-dev.2063+804cee3b9\files\zig.exe C:\Users\paoda\AppData\Local\Temp\sine C:\Users\paoda\AppData\Local\Temp\sine\zig-cache C:\Users\paoda\AppData\Local\zig --seed 0x406be11d run

Of note is that if I ignore this, and run the build in ReleaseFast I get the following output (VOLUME WARNING!!!!!)

out.mp4
@paoda paoda added bug Something isn't working needs-triage Issues that need triaging labels Jan 28, 2024
@alichraghi
Copy link
Contributor

alichraghi commented Jan 28, 2024

comptime {
    @compileLog(@sizeOf(i24));
    @compileLog(@alignOf(i24));
}
Compile Log Output:
@as(comptime_int, 4)
@as(comptime_int, 4)

this is just wrong. i don't know how we can force i24 to be three bytes

EDIT: here is the issue ziglang/zig#7336 (comment)

@slimsag slimsag added sysaudio and removed needs-triage Issues that need triaging labels Jan 29, 2024
@slimsag slimsag added this to the Mach 0.4 milestone Jan 29, 2024
alichraghi added a commit to alichraghi/mach that referenced this issue Apr 13, 2024
@slimsag
Copy link
Member

slimsag commented Apr 13, 2024

@alichraghi I wonder if the i24 was inside a packed struct if it would work.

slimsag pushed a commit that referenced this issue Apr 13, 2024
@alichraghi
Copy link
Contributor

alichraghi commented Apr 13, 2024

Didn't work

comptime {
    @compileLog(@sizeOf(packed struct { x: i24 }));
    @compileLog(@alignOf(packed struct { x: i24 }));
}

///

Compile Log Output:
@as(comptime_int, 4)
@as(comptime_int, 4)

@ypsvlq
Copy link

ypsvlq commented Apr 30, 2024

a temporary workaround is to set the device's default format to 16bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sysaudio
Projects
None yet
Development

No branches or pull requests

4 participants