0
0

Hi,
First of all, sorry my poor english. Im brazilian and never had a course ๐Ÿ˜›

Well, im here to explain how i achieved the use of syncpoints on my application.

First, you need to create a timer whose will call the Fmod.System.update();
[code:3c5ghhly]
public void InitializeSoundSystem()
{
Fmod.System.init(4, INITFLAG.NORMAL, IntPtr.Zero);
CHANNEL_CALLBACK chCallback = new CHANNEL_CALLBACK(syncHandler);
//I used 4 channels to initialize
System.Timers.Timer timer = new System.Timers.Timer(10);
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_elapsed);
timer.Start();
}
void timer_elapsed(object s, System.Timers.ElapsedEventArgs e)
{
try { Fmod.System.update(); } catch { };
}

[/code:3c5ghhly]
After that im capable to create sounds

Suppose i have two musics and i have to fade-out the currently playing music and start the next music 2 seconds before the current music end.
I used the following code:
[code:3c5ghhly]
Channel c;
Sound s;
MusicInfo nextMusic;
public void PlayMusic(MusicInfo music, MusicInfo nextMusic)
{
this.nextMusic = nextMusic;
Fmod.System.createSound(music.FileName, MODE.HARDWARE | MODE.CREATESTREAM, ref exInfo, ref s);
//the "exInfo" define how to read the data from music only
Fmod.System.playSound(CHANNELINDEX.FREE, sound, false, ref channel));
IntPtr fadePtr = IntPtr.Zero;
sound.addSyncPoint((int)(music.Length – music.FadeOut), TIMEUNIT.MS, "FadeOut", ref fadePtr));
//the "FadeOut" is the name i gave to this syncpoint. It will be called n seconds before the end of the music(Length – FadeOut)
if(nextMusic != null)
{
//if the nextMusic exists i register the syncpoint
sound.addSyncPoint((int)(music.Length – 2000), TIMEUNIT.MS, "NextMusic", ref fadePtr));
}
//the last addSyncPoint will call the next music to be played;
channel.setCallback(CHANNEL_CALLBACKTYPE.SYNCPOINT, chCallback, music.GUID.ToInt32());
//the chCallback variable is my delegate wich will be called when syncpoint has reached

}

[/code:3c5ghhly]
After that i will have to create the method wich will handle the syncpoints calls:
[code:3c5ghhly]
public Fmod.RESULT syncHandler(IntPtr channel, CHANNEL_CALLBACKTYPE type, int command, uint commanddata1, uint commanddata2)
{
IntPtr syncPoint = IntPtr.Zero;
s.getSyncPoint(0, ref syncPoint);// the "0" is the syncpoint index. I read always the first item because i remove it after handle.
StringBuilder sb = new StringBuilder();
uint offset = 0;
s.getSyncPointInfo(syncPoint, sb, 1024, ref offsetType, TIMEUNIT.MS);// the 1024 is the buffer length of the string to be read. If you named your syncpoints with more than 1024 words, i suggest to change this length.
string currentSyncPoint = sb.ToString().Trim();
switch(currentSyncPoint)
{
case "FadeOut"://do something here

        break;
        case "NextMusic":
            PlayMusic(this.nextMusic, null);


    }
    //if all is fine, return RESULT.OK telling the FMOD it was successful to handle.
        s.deleteSyncPoint(syncPoint);//remove the syncpoint, so the next index will be zero
    return Fmod.RESULT.OK;
}

[/code:3c5ghhly]
As you see, i use only one channel_callback handler. I tried to use more (using one to handle the fadeout, one to start the nextmusic) but it only call the last registered handler. In my application i store the musics into a List and get the object using the command argument (is the index in my list).
Well, i hope it will help everyone with problems managing syncpoints[/code]

  • You must to post comments
0
0

Up ๐Ÿ˜›

  • You must to post comments
0
0

Good example, I’ll try. :)

  • You must to post comments
0
0

Using this approach was the only way i found working.
But i have some problems regarding the getSyncPointInfo. Sometimes it gives me the AccessViolationException (Attempted to read or write protected memory.)
Im hopeless about if fmod does the job i need

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.