Scrolling Game Development Kit Forum
Welcome, Guest. Please login or register.
2010-09-09, 06:18:57 PM

Login with username, password and session length
Search:     Advanced search
8920 Posts in 1007 Topics by 168 Members
Latest Member: mogzdogz
* Home Help Search Login Register
+  Scrolling Game Development Kit Forum
|-+  SGDK Version 2
| |-+  Help, Errors, FAQ
| | |-+  Sounds mixed up?
« previous next »
Pages: [1] Print
Author Topic: Sounds mixed up?  (Read 397 times)
Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« on: 2010-02-01, 12:23:34 PM »

Hi guys!

Still working on my game (been more than a year now, wow time goes fast...) and I have about 100 sounds in my game.  There's not many more needed I think.  When I play the game with the sounds, it goes well for a while, but eventually it would seem the sounds get mixed up. 

For example, there is music playing and when the character slashes with his sword there is a "swoosh" sound.  I keep playing the game so more and more sounds are loaded and played and eventually (at different times, I can't seem to find what triggers this problem) I realize that when the character slashes, rather than playing the "swoosh" sound, the game restarts the music!  The "swoosh" sound is on ReplayMode.Restart, so I guess if the game gets confused about the sound channels, it could restart the music rather than the swoosh sound. 

Has anyone encountered that problem previously?  Is there a maximum number of sounds that can play simultaneously before the channels get mixed up?  Could it be because too much memory is allocated to the sounds?  Any idea?  Do you have general "best practices" I should follow when using the sounds?

I gave the example of the sword slash and the music, but any combination of sounds can get mixed up, it's not always those two.

Thanks! Smiley
Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #1 on: 2010-02-02, 06:30:37 AM »

Maybe you should make some sort of automated script in your game that plays a lot of sound effects in sequence to see if you can make the same behavior happen repeatedly.  Then we could maybe count the sound effects that play before things start getting mixed up and see if it might be related to a channel limit.
Logged

Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #2 on: 2010-02-02, 08:13:12 AM »

So I take it I'm the first to encounter this problem?

Okay, I'll make the script and see if I can reproduce the problem this way.

Thanks bluemonkmn! Smiley
Logged
Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #3 on: 2010-02-05, 12:25:00 PM »

Well, after a couple of days of trying to reproduce the problem systematically, I could not find a way to do it.  I went to FMod website, read some groups, etc.  Couldn't really find someone who has the same problem than me.  I looked into the FMod wiki, but there's not much in there yet...  So I scan Fmod.cs code and FmodBase.cs again in the hopes something would stand out as being a possible problem. 

While reading this, I got interested in the channel_callback and ChannelIndex (since I thought it was a channel problem).  Through some trials and errors, I think I found the solution.  In FModBase, each play sound uses FMOD.CHANNELINDEX.FREE.  I could not find many info about this, but since the other value in the enum is REUSE, I thought that FREE meant that FMod would use a free channel to play the sound and REUSE would mean to reuse the channel that is passed in as a parameter.  I don't know how FMod identifies free channels, so in the PlaySound function of FModBase I changed this:

if the sound is not already playing, I use FMOD.CHANNELINDEX.REUSE
if the sound is already playing and the soundreplay is StartNew, I use FMOD.CHANNELINDEX.FREE  (I have no sound using StartNew, so I don't know if it is good or not).
if the sound is already playing and the soundreplay is Continue, I don't use anything (no call to the PlaySound function, I'm just setting the volume if need be)
if the sound is already playing and the soundreplay is Restart, I use FMOD.CHANNELINDEX.REUSE

So the function becomes this:
Code:
     
      [Description("Play an FMOD sound effect")]
      public static void PlaySound([System.ComponentModel.Editor("CustomObject", "UITypeEditor")] CustomObjects.FMODBase Sound, SoundReplay ReplayOption)
      {         
         LoadSound(Sound);
         if (Sound.isPlaying)
         {
            switch(ReplayOption)
            {
               case SoundReplay.Continue:
                  ERRCHECK(Sound.channel.setVolume(Sound.Volume * Project.GameWindow.SFXVolume));
                  return;
               case SoundReplay.StartNew:
                  ERRCHECK(system.playSound(FMOD.CHANNELINDEX.FREE, Sound.sound, false, ref Sound.channel));
                  ERRCHECK(Sound.channel.setCallback(updateCallback));
                  ERRCHECK(Sound.channel.setVolume(Sound.Volume * Project.GameWindow.SFXVolume));
                  break;
               case SoundReplay.Restart:
                  Sound.Stop();
                  ERRCHECK(system.playSound(FMOD.CHANNELINDEX.REUSE, Sound.sound, false, ref Sound.channel));
                  ERRCHECK(Sound.channel.setCallback(updateCallback));
                  ERRCHECK(Sound.channel.setVolume(Sound.Volume * Project.GameWindow.SFXVolume));
                  break;
            }
         }
         else
         {
            ERRCHECK(system.playSound(FMOD.CHANNELINDEX.REUSE, Sound.sound, false, ref Sound.channel));
            ERRCHECK(Sound.channel.setCallback(updateCallback));
            ERRCHECK(Sound.channel.setVolume(Sound.Volume * Project.GameWindow.SFXVolume));
         }
      }

Oh, as you can see, there is some stuff in there to allow the user to control the volume (Project.GameWindow.SFXVolume), you can ignore that.

Since I made these modifications, the problem is gone!  Grin

Unfortunately, I haven't learned much about Fmod, but at least this problem is gone  (for now, I keep my fingers crossed).  Wink

Thanks guys!  Smiley
Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #4 on: 2010-02-05, 05:56:59 PM »

Good thing the sound framework in SGDK2 is completely open for alterations and corrections Smiley
Logged

bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #5 on: 2010-02-05, 06:34:43 PM »

I incorporated similar changes into the checked-in code.  I will probably make another official release of SGDK2 soon.

Code:
         if (Sound.isPlaying)
         {
            switch(ReplayOption)
            {
               case SoundReplay.Continue:
                  return false;
               case SoundReplay.StartNew:
                  ERRCHECK(system.playSound(FMOD.CHANNELINDEX.FREE, Sound.sound, false, ref Sound.channel));
                  break;
               case SoundReplay.Restart:
                  Sound.Stop();
                  ERRCHECK(system.playSound(FMOD.CHANNELINDEX.REUSE, Sound.sound, false, ref Sound.channel));
                  break;
            }
         }
         else
            ERRCHECK(system.playSound(FMOD.CHANNELINDEX.REUSE, Sound.sound, false, ref Sound.channel));

         ERRCHECK(Sound.channel.setCallback(updateCallback));
         ERRCHECK(Sound.channel.setVolume(Sound.Volume));
         Sound.lastSetVolume = Sound.Volume;
         return true;
      }
Logged

Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #6 on: 2010-02-06, 09:27:35 AM »

Great! 

I'm curious to find out what is new in the next version! Smiley
Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #7 on: 2010-02-07, 07:29:30 AM »

I doubt there will be many surprises.  Just many of the minor tweaks we have talked about in the forums, now part of the official release.

Edit: I did just decide to add the sorting feature we talked about.  Originally I was going to implement it as a "Sort" command on the tree view's context menu, but it turns out it's easier just to keep everything sorted all the time (even after renaming an object).  So the next release will keep everything in the treeview sorted, which should make your objects much easier to find since you have so many.
« Last Edit: 2010-02-07, 09:05:10 AM by bluemonkmn » Logged

Vincent
Clever
Fanatic
***
Posts: 343


Working on a Legacy of Kain fangame.


View Profile Email
« Reply #8 on: 2010-02-07, 09:11:48 AM »

Excellent!

I was hoping the sort feature would be there, it will be much faster for me to find everything!

Thanks a lot!  Grin
Logged
bluemonkmn
SGDK Author
Administrator
Fanatic
*****
Posts: 2146


2678251 BlueMonkMN@gmail.com
View Profile WWW Email
« Reply #9 on: 2010-02-07, 11:18:58 AM »

Hm... I guess I should also upgrade to OpenTK version 1.0 beta 2, which seems to be the latest OpenTK.  And maybe switch to its keyboard/joystick handling instead of the temporary input handling I added to SGDK2 framework code before OpenTK supported Input handling on GLControls... if it works on GLControls now.
Logged

Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!