Accessing a microphone

Hello! Does anyone here have experience with accessing a microphone on any platform? I need to use microphone input for my current project (desktop and Android), but I can’t find any good resources. https://github.com/clemos/openfl-webaudio doesn’t look that useful at the moment because I’m not targeting web, and https://github.com/josuigoa/CameraMic looks very early in development, and I’d prefer not to use any extensions if possible.

I thought a good place to start might be to just import the flash.media.Microphone standard library class and try playing around with it, but Haxe tells me that type is not found. I’m starting to think I’ve overlooked something obvious. If anyone who has used microphones in Haxe/OpenFL before could give me some pointers, I’d really appreciate it!

I think they just added sound input in SDL recently:

http://sdl.5483.n7.nabble.com/Audio-capture-support-and-new-Mac-iOS-audio-target-td47522.html

That might be the easiest/most stable way to get audio capture going on native. Could figure out a way to add it to Lime as an official API

Thanks for the info. It looks like SDL 2.0.5 supported was added to lime about a year ago, so since I’m using the latest release I should have be using it.

I’ve never tried to access SDL functions in Haxe before. Some googling makes it look like I’ll need to make an extension, unless there’s something I’m missing? SDL has support for microphone input, but I’m just not sure what I need to do to actually use this in my project.

We have classes in C++ that access SDL methods, here: https://github.com/openfl/lime/tree/develop/project/src/backend/sdl

I think the next steps would be to add something like an SDLMicrophone.cpp file, and to build up support. It does need to be as you would develop a native extension, but it could occur within Lime rather than being a separate project

Thanks for the help! I’ll start by looking at those and the SDL example that was linked from the thread you linked. If this works out and is clean I’ll make a pull request to add it to lime.

Happy to help if you have any questions or need help on integrating things in :slight_smile:

I’ve looked at the classes that access SDL methods and tried to make some progress, but I have to admit I’m confused. The Joystick class for example: this file also includes (I’m guessing) this file, and to be honest, even after looking at the SDL Joystick code, I’m not sure how it was determined what how these classes would be built. I’m new to the audio world as well, which doesn’t help. I’m sorry if I’m missing something obvious, but I’m not sure how to take the next step to go from where I am now to a working SDLMicrophone class.

In the native code, we expose bindings in our “ExternalInterface.cpp” file. Each call we make there tends to be described in a general header. For example, our joystick API is described by the lime.ui.Joystick header, here:

Then is called by our “ExternalInterface.cpp” file, here:

But the implementation is done by SDL on this method. In there future, there may be other backend systems we support, but we only support SDL at the moment.

The reason we have an “SDLJoystick.h” file (in this case) is because we need to make some internal calls from “SDLApplication.cpp” into “SDLJoystick.cpp”, but this is only because joystick events come from the SDL main loop.