1. SoLoud Wrapper
- Posted by Icy_Viking Mar 11, 2021
- 781 views
Hello All,
I am currently working on a wrapper of SoLoud for Euphoria. It is an audio library. I just want to make sure I am wrapping the functions correctly. It has a C-API.
Its the way pointers are init that is throwing me off, just wanna make sure I won't need to do anything special when making a wrapper for Eu.
EDIT: I found another header file, maybe it won't be so hard, but just wanna make sure. Note that it does come with a DLL.
C Code from header Soloud * Soloud_create(); int Soloud_init(Soloud * aSoloud);
C Code from the glue cpp file void * Soloud_create() { return (void *)new Soloud; } int Soloud_init(void * aClassPtr) { Soloud * cl = (Soloud *)aClassPtr; return cl->init(); }
atom sol ifdef WIN32 then sol = open_dll("soloud_x86.dll") elsifdef LINUX or FREEBSD then sol = open_dll("soloud_x86.so") end ifdef public constant xSoloud_create = define_c_func(sol,"+Soloud_create",{},C_POINTER) public function Soloud_create() return c_func(xSoloud_create,{}) end function public constant xSoloud_init = define_c_func(sol,"+Soloud_init",{C_POINTER},C_INT) public function Soloud_init(atom ptr) return c_func(xSoloud_init,{ptr}) end function
2. Re: SoLoud Wrapper
- Posted by ghaberek (admin) Mar 11, 2021
- 784 views
Yeah that looks good so far. I noticed this comment the "C" API page:
If the c++ API functions have default parameters, two functions are generated: one without the default parameters, and one with. The one where you can change the default parameters is post-fixed Ex, such as Soloud_init and Soloud_initEx.
So when you wrap functions that would have default parameters maybe just wrap the "Ex" version and provide the same defaults in the wrapper and then drop the "Ex" suffix, like this:
-- int Soloud_initEx( -- Soloud * aSoloud, -- unsigned int aFlags /* = Soloud::CLIP_ROUNDOFF */, -- unsigned int aBackend /* = Soloud::AUTO */, -- unsigned int aSamplerate /* = Soloud::AUTO */, -- unsigned int aBufferSize /* = Soloud::AUTO */, -- unsigned int aChannels /* = 2 */ -- ); constant _Soloud_initEx = define_c_func( Soloud, "Soloud_initEx", {C_POINTER,C_UINT,C_UINT,C_UINT,C_UINT,C_UINT}, C_INT ) public constant SOLOUD_AUTO = 0, SOLOUD_CLIP_ROUNDOFF = 1 public function Soloud_init( atom aSoloud, atom aFlags=SOLOUD_CLIP_ROUNDOFF, atom aBackend=SOLOUD_AUTO, atom aSampleRate=SOLOUD_AUTO, atom aBufferSize=SOLOUD_AUTO, atom aChannels=2 ) return c_func( _Soloud_initEx, {aSoloud,aFlags,aBackend,aSampleRate,aBufferSize,aChannels} ) end function
The documentation is here: "SoLoud 20200207" and the C header is here: include/soloud_c.h.
I don't see any declaration prefix in the header so there should be no need for a "+" in the function names that would force CDECL on Win32.
-Greg
3. Re: SoLoud Wrapper
- Posted by Icy_Viking Mar 11, 2021
- 783 views
Yeah that looks good so far. I noticed this comment the "C" API page:
If the c++ API functions have default parameters, two functions are generated: one without the default parameters, and one with. The one where you can change the default parameters is post-fixed Ex, such as Soloud_init and Soloud_initEx.
So when you wrap functions that would have default parameters maybe just wrap the "Ex" version and provide the same defaults in the wrapper and then drop the "Ex" suffix, like this:
-- int Soloud_initEx( -- Soloud * aSoloud, -- unsigned int aFlags /* = Soloud::CLIP_ROUNDOFF */, -- unsigned int aBackend /* = Soloud::AUTO */, -- unsigned int aSamplerate /* = Soloud::AUTO */, -- unsigned int aBufferSize /* = Soloud::AUTO */, -- unsigned int aChannels /* = 2 */ -- ); constant _Soloud_initEx = define_c_func( Soloud, "Soloud_initEx", {C_POINTER,C_UINT,C_UINT,C_UINT,C_UINT,C_UINT}, C_INT ) public constant SOLOUD_AUTO = 0, SOLOUD_CLIP_ROUNDOFF = 1 public function Soloud_init( atom aSoloud, atom aFlags=SOLOUD_CLIP_ROUNDOFF, atom aBackend=SOLOUD_AUTO, atom aSampleRate=SOLOUD_AUTO, atom aBufferSize=SOLOUD_AUTO, atom aChannels=2 ) return c_func( _Soloud_initEx, {aSoloud,aFlags,aBackend,aSampleRate,aBufferSize,aChannels} ) end function
The documentation is here: "SoLoud 20200207" and the C header is here: include/soloud_c.h.
I don't see any declaration prefix in the header so there should be no need for a "+" in the function names that would force CDECL on Win32.
-Greg
Thanks Greg, I wrapped the init function as you showed. I'll continue working on the wrapper. You're always a great help!