About Monkey 2 › Forums › Monkey 2 Development › Native interface questions.
This topic contains 3 replies, has 2 voices, and was last updated by
Simon Armstrong 2 years, 9 months ago.
-
AuthorPosts
-
July 17, 2016 at 8:53 pm #2235
Hi Mark,
Some questions about module development.
What are the best ways to do following:
- Returning const char * to monkey2
- Add a -Ddefine to compiler flags when building a module’s .c and .cpp
- What is state of audio modules?
For the first I am using the extern struct constcstring=”const char” as you do in gles20 and for the second I am hacking #define into appropriate header so they build properly.
I am also interested if you have any immediate plans to add to the module space and state of audio. Does openal mean sdl2 mixer should be deprecated. Does emscriptem have audio and how? Can monkey2 call webgl / webaudio/ webmidi directly for web? Am looking forward to exploring this area.
S
July 17, 2016 at 9:58 pm #2238Returning const char * to monkey2
This side of things is still a bit nasty, but for now I’d suggest make the function return a pointer to one of the char types in libc, eg: libc.char_t Ptr, libc.unsigned_char_t Ptr or libc.signed_char Ptr (I will probably also add const_char_t, const_signed_char_t etc).
Then use String.FromCString() or String.FromUtf8String() to convert the pointer to an mx2 string.
Add a -Ddefine to compiler flags when building a module’s .c and .cpp
You can’t yet, although you can hack the env_blah.txt file to force the define everywhere. I want to come up with a better way to achieve this rather than abusing #import ala bmx, but until then…
I am hacking #define into appropriate header so they build properly.
…is probably your best bet and what I actually what I’ve done for several modules.
What is state of audio modules?
Pretty good IMO!
Does openal mean sdl2 mixer should be deprecated.
I wont be using it myself for mojo.audio, but I don’t see why it can’t be left in there for others to use. Note also that AppInstance no longer inits SDL_AUDIO, but I probably don’t have to do this.
Does emscriptem have audio and how?
It has openal ‘built-in’. No fibers though, so no WaitQueued(). NumQueued can probably happen so you should eventually be able to poll.
Can monkey2 call webgl / webaudio/ webmidi directly for web?
Don’t see why not. #Import js might be useful here? Not in right now though.
July 17, 2016 at 10:07 pm #2239Thanks!
Yes, I imagine importing js will be very useful when I poke my nose in.
I think maybe emscripten is ok name for target but seems a bit cryptic for lay person. In monkey2 is there a way for #if testing between cpp and js or maybe native and web environments?
July 19, 2016 at 10:22 pm #2288OK, vsynth is running well on OpenAL,
To make use of new? std.audio stuff just been playing with skidmarks engine sample oscillator. Very happy it was so easy and bug free? and I may have missed a helper method…
Monkey12345678910111213141516171819202122232425262728293031323334353637383940Class Sampler Extends OscillatorField a:VField audioData:AudioDataField bytespersample:IntField pitch:FMethod New()Load("asset::engine1.wav")Print "sampler loaded:"+audioData.Length+"@"+audioData.Hertz+" format="+Int(audioData.Format)bytespersample=BytesPerSample(audioData.Format)pitch=440.0EndMethod Load(uri:String)audioData=AudioData.Load(uri)EndMethod Sample:V(hz:F) OverrideLocal t:=hz*audioData.Hertz/(pitch*AudioFrequency)Local delta0:=deltadelta+=tLocal f:=deltaf=f Mod (audioData.Length/bytespersample)Local i:Int=fLocal udata:=audioData.DataLocal sdata:=Cast<Byte Ptr>(udata)Select audioData.FormatCase AudioFormat.Mono8Return (udata[i]-128)/127.0Case AudioFormat.Mono16Return (sdata[i*2+1]*256+sdata[i*2+0])/32767.0Case AudioFormat.Stereo8Return (udata[i*2+0]-128)/127.0Case AudioFormat.Stereo16Return (sdata[i*4+1]*256+sdata[i*4+0])/32767.0EndReturn 0Endend -
AuthorPosts
You must be logged in to reply to this topic.