On Fri, 19 Oct 2018 at 22:26, Ethan Lee flibitijibibo@flibitijibibo.com wrote:
To test the waters, I added the global custom allocator func and tried it out with our existing COM wrapper, and aside from making sure that it's absolutely called before any API call, it's kind of nice! The commit is in a separate branch for now:
https://github.com/FNA-XNA/FAudio/commit/d36e46bf5609859e5796fed378c3d4b2411...
So that's pretty much what it would look like on the Wine side too; any function that initializes any portion of the XAudio/XACT APIs would need to set the functions before doing anything else. There's definitely redundancy and I probably shouldn't be using static functions in our COM wrapper, for example, but it works and manages to fix things in a way that allows our COM wrapper to work with the stock FAudio.dll on Windows, so that's nice!
This doesn't have to be the official API right away, of course, so I'm open to feedback on this.
I should note that I'm not all that familiar with the specifics of the XAudio API, so I may be missing the obvious here, but it's not clear to me why the allocation callbacks would need to be globals. (Reasons you don't want them to be globals include e.g. different parts of the same process loading the library, potentially with different allocators.)
For what it's worth, the kind of API I had in mind would look roughly like this:
HRESULT faudio_create(const struct faudio_create_info *create_info, void **xaudio2) { ... }
HRESULT XAudio2Create(IXAudio2 **xaudio2, UINT32 flags, XAUDIO2_PROCESSOR proc) { struct faudio_create_info create_info;
create_info.type = FAUDIO_STRUCTURE_TYPE_CREATE_INFO; create_info.next = NULL;
create_info.pfn_malloc = SDL_malloc; create_info.pfn_realloc = SDL_realloc; create_info.pfn_free = SDL_free;
create_info.iid = &IID_IXAudio28; create_info.flags = flags; create_info.proc = proc;
return faudio_create(&create_info, (void **)xaudio2); }
Which (again, unsurprisingly) is fairly similar to the vkd3d API.