mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.08k stars 361 forks source link

Crashes and/or strange output when using WinMM backend #873

Closed day-garwood closed 4 months ago

day-garwood commented 4 months ago

Hi there, For some reason, WinMM backend is crashing or else outputting staticky audio when using my own device context and using ma_engine_read_pcm_frames in a callback. Tried both the "engineConfig.noDevice=MA_TRUE" and "engineConfig.pDevice=&MyDevice" methods, both yield the same result.

Release builds will generally (apart from a few occasions) crash before the sound even plays. Debug builds usually always play the (garbled) sound before a sigtrap occurs, probably at the point of uninitialising the device.

Interestingly, using an engine-managed device works fine, but then my code works fine for WASAPI and DirectSound so not actually sure whether this is a problem with my code or not.

I have uploaded some interesting files that should give you more of an idea as to what might be happening.

If you need any more info let me know. Cheers.

mackron commented 4 months ago

Check that you're initializing your device to use ma_format_f32 for the format. That is what ma_engine_read_pcm_frames() outputs, always.

day-garwood commented 4 months ago

Thanks for that. The debug log shows that we're trying to use 16-bit Signed Integer, so that would definitely explain a lot. I wasn't setting the format based on info in the docs: "Note that leaving the format, channel count and/or sample rate at their default values will result in the internal device's native configuration being used which is useful if you want to avoid the overhead of miniaudio's automatic data conversion." I misunderstood that. I wasn't setting any of those values in the device config but instead assumed they would be set up in the device and everything would match up in the engine. But now you've said that, I've only just realised that we don't give a format to the engine config. Cheers.