Mac OSX SoundEffectInstance issues

Hi guys,

I’m still working on Mac version of my game.

Now i got issues with sounds… it’s not easy to explain, but seems that Mono is messing up with audiobuffer, memory chunks or whatever… I don’t have always the same issues, sometimes a sound plays, sometimes not. Plus, i hitted the InstancePlayLimitException once, so i guess Mono don’t free the audio buffer after a soundInstance was used.

Now i’m posting some code which gives me so many problems:

 switch (number)
          {
              case 1:
                  levelMusic = level_1_Music;
                  levelMusicInstance = levelMusic.CreateInstance();
                  levelMusicInstance.IsLooped = true;
                  levelMusicInstance.Volume = 0.60f;
                break;

              case 12:
                  levelMusic = level_1_B_Music;
                  levelMusicInstance = levelMusic.CreateInstance();
                  levelMusicInstance.IsLooped = true;
                  levelMusicInstance.Volume = 0.60f;
                  break;

As you can see, i have one SoundEffect object (levelMusic) and one SoundEffectInstance object (levelMusicInstance). During a level play, i have to switch music, so i call this function and then i call a levelMusicInstance.Play()

Well… sometimes it works, sometimes not. It’s like Mono finds out the audio channel busy and won’t to play the song. It’s weird. On Windows with DirectSound everything works fine.

All the sounds are wmv converted xnb with monogame pipeline tool.
All the wmv are PCM signed 16bit stereo, 44100hz, 1411kpbs.

Can you help me please? :slight_smile: Thanks guys.

Well, i made some progress.

Before to reassign a new value to levelMusicInstance, i have to call levelMusicInstance.Dispose();

Seems that Mono can’t detect when a sound is over and must be disposed.

Still getting InstancePlayLimitException here and there.

This is what i’m doing:

On Loading assets:

testSound = cm.Load<SoundEffect>("Sounds/testSound");
        for (int c = 0; c < testSoundInstance.Length; c++)
            testSoundInstance[c] = testSound.CreateInstance();

On game cycle:

                if (testSoundCounter >= testSoundInstance.Length) 
                                                         testSoundCounter = 0;

                testSoundInstance[testSoundCounter].Play();
                testSoundCounter ++;

So i have this SoundEffectInstance array that loops playing a different instance of the same SoundEffect everytime. In this way i can play multiple sounds at the same time from the same source - doesn’t have to wait that the single instance has ended.

I think in someway Mono doesn’t clear the buffer or something when the sound ends and soon i hit the limit.
I can’t create and destroy the instance on the fly because of performance and because it would be bad coding too.

What could be the problem here?

It’s hard to say what the problem could be without investigating it.

Also, Mono is not the same as MonoGame. Mono is the banner under which the .NET runtime, C# compiler and .NET Framework live. MonoGame is a library that can be built with and run on Mono, or built with and run on the Microsoft .NET Framework. From your first post, wmv is Windows Media Video (you probably meant wav), and the Windows platform of MonoGame uses XAudio2. DirectSound was replaced by XAudio many years ago, which has been subsequently replaced by XAudio2.

Yes i was talking about monogame, not mono of course…

Seems there are so many issues with sounds here.

I’m getting sounds that plays well for a while, then suddenly don’t play anymore.
I’m getting sounds that doesn’t play at all.

What can i check to get a hint about what’s happening?
What are the common causes with sound issues?