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

Open
opened 2024-01-28 17:20:33 +00:00 by paoda · 4 comments
paoda commented 2024-01-28 17:20:33 +00:00 (Migrated from github.com)

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!!!!!)

https://github.com/hexops/mach/assets/22038970/62d9c439-1b30-4424-8037-051b0a3e86a4

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!!!!!**) https://github.com/hexops/mach/assets/22038970/62d9c439-1b30-4424-8037-051b0a3e86a4
alichraghi commented 2024-01-28 17:40:12 +00:00 (Migrated from github.com)
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 https://github.com/ziglang/zig/issues/7336#issuecomment-747602260

```zig 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 https://github.com/ziglang/zig/issues/7336#issuecomment-747602260
emidoots commented 2024-04-13 14:25:08 +00:00 (Migrated from github.com)

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

@alichraghi I wonder if the i24 was inside a `packed struct` if it would work.
alichraghi commented 2024-04-13 20:16:25 +00:00 (Migrated from github.com)

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)
Didn't work ```zig 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 commented 2024-04-30 13:14:36 +00:00 (Migrated from github.com)

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

a temporary workaround is to set the device's default format to 16bit
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#1152
No description provided.