About Monkey 2 › Forums › Monkey 2 Development › MacOS Audio not fit for purpose!
This topic contains 14 replies, has 3 voices, and was last updated by
AdamStrange
1 year, 7 months ago.
-
AuthorPosts
-
September 15, 2017 at 7:10 am #10483
Just been doing some audio stuff and getting really unhappy about the continued audio problems on MacOS
This is in regard to ALL loaded samples having the beginning few microseconds being cut off before playing.
So playing a drum sound will miss the first few milliseconds of playback and thus clip the sound at the beginning resulting in sound not being played correctly.
Until this is properly fixed I can NO recommend Monkey2 sound as fit for purpose (on MacOS)
Mark – you already know about this issue. are you actually going to address it?
September 15, 2017 at 9:34 pm #10492Can you post a sample you are having problems with?
This is playing something that sounds a lot like a sine wave, which would suggest it’s not actually a playback problem:
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField _sounds:=New Sound[4]Field _soundid:=0Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )Local n:=8192Local s:=11025 '44100Local p:=1 '.25Local data:=New AudioData( n,AudioFormat.Mono8,s )For Local i:=0 Until ndata.Data[i]=Sin( i*p ) * 127+128Next_sounds[0]=New Sound( data )data=New AudioData( n,AudioFormat.Mono16,s )For Local i:=0 Until nCast<Short Ptr>(data.Data)[i]=Sin( i*p ) * 32767Next_sounds[1]=New Sound( data )data=New AudioData( n,AudioFormat.Stereo8,s )For Local i:=0 Until ndata.Data[i*2+0]=Sin( i*p ) * 127+128data.Data[i*2+1]=Sin( i*p ) * 127+128Next_sounds[2]=New Sound( data )data=New AudioData( n,AudioFormat.Stereo16,s )For Local i:=0 Until nCast<Short Ptr>(data.Data)[i*2+0]=Sin( i*p ) * 32767Cast<Short Ptr>(data.Data)[i*2+1]=Sin( i*p ) * 32767Next_sounds[3]=New Sound( data )EndMethod OnRender( canvas:Canvas ) OverrideIf Keyboard.KeyHit( Key.Space )_soundid=(_soundid+1)&3_sounds[_soundid].Play()EndifApp.RequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndSeptember 15, 2017 at 9:44 pm #10493…also works fine with 44100hz, even short sample data lengths such as 32.
I had assumed this was a macos openal bug, looks like I was wrong.
September 15, 2017 at 10:14 pm #10495.
September 15, 2017 at 10:17 pm #10496even more odd, changing n to 8192 produces a bit of noise, silence and then a wallop for each sound.Play
September 15, 2017 at 10:22 pm #10497But you can still hear something? I’m stuck with crappy monitor HDMI audio (through a KVM!) and with 64 samples I can hear a noticeable ‘click’ here, which I don’t find particularly surprising as the sound is only playing for 1/11025*64, ie: ~6ms!
Not quite sure what everyone’s expecting here…
September 15, 2017 at 10:38 pm #10498Updated my sine wave code so you can try different lengths. Like how stereo is definitely louder than mono!
Do you hear a steady sine wave with n=8192?
As for your code, not sure you can just throw some numbers at audio and then say ‘thats wrong’ (well, with my level of experience anyway). I just noticed that setting data to ‘0’ produces a noticeable click when it stops. I assume this is because 128 is really 0 as mono8 is unsigned – changing 0 to 128 prevents this click. I guess it’s the transitions that count with audio.
I am still not convinced there’s actually any problem as yet.
September 15, 2017 at 10:39 pm #10499What’s a ‘wallop’? Pehaps the 0->128 click at the end?
September 15, 2017 at 11:25 pm #10500Ignore me and my dumb posts, forgot it was unsigned.
The numbers were suppose to generate a short burst of a 440hz sawtooth then silence which I was thinking would be louder / easier to hear than sin wave for very short durations.
September 16, 2017 at 5:53 am #10509I am using loaded audio, not generated.
mono, 16 bit
Here’s a demo app showing exactly what is going on…
September 16, 2017 at 5:54 am #10510September 16, 2017 at 8:53 am #10520Ok, I can reproduce this, but I have no idea what’s up, except that it doesn’t seem to be in monkey2 code.
Openal (and quick time) don’t seem to like the sample at all. I get very much the same problem if I play it with quicktime, except it works first time. Also, playing in Ted works sometimes when you loop it or repeat it, sometimes not.
If I blast over the first N bytes of the sample with a sine wave, the sine wav plays OK so it’s not that the audio driver isn’t playing the first N bytes, it’s just playing them wrong!
I will keep looking into this, but to be honest it may be a while before there’s a solution as it may involve writing a completely new driver from scratch, so go ahead and tell everyone monkey2 sucks on macos in the meantime! There are no such problems on windows anyway.
Perhaps try a different sample?
September 16, 2017 at 9:27 am #10521Success!
I tried a 3rd party openal.dylib instead of the system openal framework and it fixed the kick.wav issue!
Will add this for the next release, mx2cc needs some changes too to be able to import dylibs properly.
September 16, 2017 at 9:41 am #10523Brilliant
:}
just so you know. the sample used was just picked by random. all other samples exhibit the same issues. also the same when creating sounds from imported AudioData too
September 16, 2017 at 10:27 am #10525Mark, heres a thought…
If you are going to make some changes to support dylibs. would it be possible to support dylib creation within monkey2?
That way, we could compile and recompile the openal dylib directly and also possibly sort out future stuff like effects?
-
AuthorPosts
You must be logged in to reply to this topic.