syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.93k stars 821 forks source link

EZAudio for Xamarin #221

Open Harigharan opened 8 years ago

Harigharan commented 8 years ago

Hi All,

I would like to use this library in my Xamarin iOS project. Is there any dll library for Xamarion iOS?

ashishkumargit commented 8 years ago

Hi,

I also need this. Can any one suggest me how to impliment EZAudio in xamarin.ios?

Harigharan commented 8 years ago

Anybody tried to bind this iOS library to Xamarin?

casamia918 commented 7 years ago

I tried to bind this library but end in fail.

(This is not the "How to bind guide". You should study binding objective-c library by reading Xamarin official guide. https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-c-libraries/ I wrote this to share my library binding experience and I assumed that you've already know about binding process)

To be fortunately, EZAudio already shipped it's precompiled framework file. So, what I have to do is just create APIDefinition.cs code using sharpie.

At first, when I tried to run "sharpie bind" command using header files as source, like this $ sharpie bind -output sharpie -namespace EZAudioBinding -sdk iphoneos10.0 ./EZAudio/*.h the result is fail. The reported error messages are related with __tg_sqrt, __tg_fmax blabla.


/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/usr/include/simd/common.h:1381:92: error: call to
      '__tg_fmin' is ambiguous
static double __SIMD_ATTRIBUTES__ vector_reduce_min(vector_double3 __x) { return __tg_fmin(__tg_fmin(__x.x, __x.z), __x.y); }

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/usr/include/simd/common.h:1419:81: error: call to
      '__tg_fmax' is ambiguous
static float __SIMD_ATTRIBUTES__ vector_reduce_max(vector_float2  __x) { return __tg_fmax(__x.x, __x.y); }

After googling, I found that these errors are related with clang compiler. https://bugzilla.xamarin.com/show_bug.cgi?id=34594

So, I attached the compiler options at the end of sharpie bind command

$ sharpie bind -output sharpie -namespace EZAudioBinding -sdk iphoneos10.0 ./EZAudio/*.h  \
>      -c \
>     -DINFINITY=1e500 \
>     -D__SIMD_MATH_HEADER__ \
>     -D__SIMD_LOGIC_HEADER__ \
>     -D__SIMD_GEOMETRY_HEADER__ \
>     -D__SIMD_BOOLEAN_TYPE__=_Bool

After that, the _tg related errors are gone. But still 1 error occurs. (The bind result shows lots of warning messages but they can be ignored, so I just proceeded.)

In file included from /var/folders/lf/4frwgk3n4pb72b8z54ty0r740000gn/T/tmp7b81c06b.h:8:
[PathToLibrary]/EZAudio/EZAudioOSX.h:26:9: fatal error: 'EZAudioOSX/EZAudio.h' file not found
#import <EZAudioOSX/EZAudio.h>

Again, I searched the google and found that these are framework related problem. https://forums.xamarin.com/discussion/40207/objective-sharpie-dosent-provide-bindings-for-framework-file

So, I modified to this command and the sharpie bind is end with success.

$ sharpie bind -output sharpie -namespace EZAudioBinding -sdk iphoneos10.0 -f [FrameworkBuildResultFolderPath]/EZAudioiOS.framework -fx-umbrella EZAudioiOS.h \
-c \     
-DINFINITY=1e500  \
-D__SIMD_MATH_HEADER__   \
-D__SIMD_LOGIC_HEADER__  \ 
-D__SIMD_GEOMETRY_HEADER__  \   
-D__SIMD_BOOLEAN_TYPE__=_Bool

(You can get the [FrameworkBuildResultFolderPath] by opening the EZAudio.xcodeproj, right click on the Products/EZAudioiOS.framework and click the 'Show in finder' menu item)

After that, I can get APIDefiinition.cs and StructsAndEnums.cs files. Of course, I copy this codes to my Xamarin's .iOS binding project and proceed to manual verifying job.

At the first build, I got 50~60 errors. I fix these errors one by one.

This is the my binding project source code, after the above jobs. https://github.com/casamia918/EZAudioBinding

After that, I got the last error message.

Error BI1017: btouch: Do not know how to make a signature for System.Single** in method 'FloatBuffersWithNumberOfFrames' (BI1017) (EZAudioBinding)

The error message are related with float* type. Many EZaudio methods are using float* to contain audio buffers. This is essential part but after read this below thread, I realized that I can't fix this problem.

https://forums.xamarin.com/discussion/48065/btouch-error-when-binding-unsafe-code

I'm really unhappy to get this result. Hope my exprience would be useful to someone.