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

miniaudiohelpers library uses full implementation unnecessarily #38

Closed
stefandd opened this issue May 7, 2024 · 3 comments
Closed

miniaudiohelpers library uses full implementation unnecessarily #38

stefandd opened this issue May 7, 2024 · 3 comments

Comments

@stefandd
Copy link

stefandd commented May 7, 2024

The sole purpose of miniaudiohelpers.c is to determine some struct sizes. On all platforms. the C compiler can calculate struct sizes based on the struct definitions. Therefore, instead of a nearly > 1 MB large miniaudiohelpers library that also fully implements the miniaudio library, one can get an ~ 1 KB large one that is perfectly sufficient.

FIX: remove the #define MINIAUDIO_IMPLEMENTATION in miniaudiohelpers.c

// #define MINIAUDIO_IMPLEMENTATION

#include "miniaudio.h"

size_t MADataConverterSize();
size_t MAContextSize();
size_t MADeviceSize();
size_t MAMutexSize();

size_t MADataConverterSize()
{
  return sizeof(ma_data_converter);
}

size_t MAContextSize()
{
  return sizeof(ma_context);
}

size_t MADeviceSize()
{
  return sizeof(ma_device);
}

size_t MAMutexSize()
{
  return sizeof(ma_mutex);
}
@sol-vin
Copy link
Owner

sol-vin commented May 7, 2024

👋 Hey thank you so much! Wasn't really sure what to do about this. Do you think there is a better way of doing this entirely? I kind of feel like this isn't necessary and I need to either hardcode sizes once during postinstall or figure something else out for determining these struct sizes. I'm not even sure if this method of determining struct sizes is even valid because potentially raylib may flip some switches with miniaudio that could change struct sizes. Id love to hear your thoughts 🤔💭

@stefandd
Copy link
Author

stefandd commented May 8, 2024

Unfortunately, since the packing, padding and layout of structs are both platform and compiler vendor-specific (Microsoft does it differently than GCC etc.), you have no choice but to do this if the structs can't be expressed directly in a Crystal file. I tried to take a look at them, and they look like a nightmare, but I can't quickly tell if one could treat them like the Raylib structs or not.

However, your way of doing it should be fine as long Raylib doesn't modify the miniaudio struct layouts.

@sol-vin
Copy link
Owner

sol-vin commented Jun 19, 2024

Thanks for the input. I've heard various rumblings from people about this but I'm like not trying to maintain the miniaudio bindings just so I can unpack a struct someone needs in a rare situation (modifying the AudioCallback thing). I'm gonna set this up right now and give it a try.

@sol-vin sol-vin closed this as completed Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants