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: opus play.zig example crashes after a few seconds of playing #1160

Open
TemariVirus opened this issue Feb 16, 2024 · 1 comment
Open
Labels
bug Something isn't working sysaudio

Comments

@TemariVirus
Copy link

Expected behaviour: running zig build run-example plays time.opus on loop without error
Actual behaviour: after a few seconds of playing normally, it crashes with this error:

thread 22228 panic: integer part of floating point value out of bounds
C:\Users\user\AppData\Local\zig\p\12203f0d4afc83bae8571434ff48a459732c15c9542df13e0a97baedc73212d355a1\src\conv.zig:338:47: 0xd81dfc in floatToSignedSIMD__anon_11417 (example-play.exe.obj)
        dst[i..][0..vec_size].* = @as(VecDst, @intFromFloat(src_vec * max));
                                              ^
C:\Users\user\AppData\Local\zig\p\12203f0d4afc83bae8571434ff48a459732c15c9542df13e0a97baedc73212d355a1\src\conv.zig:292:26: 0xd65f47 in floatToSigned__anon_10458 (example-play.exe.obj)
        floatToSignedSIMD(SrcType, src, DestType, dst);
                         ^
C:\Users\user\AppData\Local\zig\p\12203f0d4afc83bae8571434ff48a459732c15c9542df13e0a97baedc73212d355a1\src\main.zig:339:38: 0xd1e830 in convertTo__anon_7577 (example-play.exe.obj)
            f32 => conv.floatToSigned(SrcType, src, i16, @as([*]i16, @ptrCast(@alignCast(dst)))[0..dst_len]),
                                     ^
C:\Users\user\repos\mach-opus\examples\play.zig:62:23: 0xd151e3 in writeCallback (example-play.exe.obj)
    sysaudio.convertTo(
                      ^
C:\Users\user\AppData\Local\zig\p\12203f0d4afc83bae8571434ff48a459732c15c9542df13e0a97baedc73212d355a1\src\wasapi.zig:807:31: 0xd840cd in writeThread (example-play.exe.obj)
                player.writeFn(
                              ^
C:\Program Files\Zig\lib\std\Thread.zig:411:13: 0xd67b2c in callFn__anon_10487 (example-play.exe.obj)
            @call(.auto, f, args);
            ^
C:\Program Files\Zig\lib\std\Thread.zig:523:30: 0xd2072f in entryFn (example-play.exe.obj)
                return callFn(f, self.fn_args);
                             ^
???:?:?: 0x7ffddd83257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffddeaaaa57 in ??? (ntdll.dll)

The error seems to be caused by samples 605716 to 605725 of the decoded sound file:
{ 1.00861, 0.03097, 1.01480, 0.02588, 1.01671, 0.02050, 1.01438, 0.01490, 1.00786 }

Some of the values are >= 1, causing an overflow when converting from f32 to i16. To make sure that this isn't an issue with time.opus, I tried to play another file and encountered the same error (both files play fine on Window's Media Player).

I'm running Windows 11 with Zig 2024.1.0-mach

@TemariVirus TemariVirus added bug Something isn't working needs-triage Issues that need triaging labels Feb 16, 2024
@slimsag
Copy link
Member

slimsag commented Mar 6, 2024

Sorry for missing this.

I have a hunch it could be fixed already in sysaudio, but the example is not yet updated to use the latest version of sysaudio.

I suspect once #1170 is closed that this will work.

I'll ping you once you can test again if that's alright :)

@slimsag slimsag added sysaudio and removed needs-triage Issues that need triaging labels Mar 6, 2024
@slimsag slimsag changed the title opus: play.zig example crashes after a few seconds of playing sysaudio: opus play.zig example crashes after a few seconds of playing Mar 6, 2024
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

2 participants