0
0

In Winamp, there is a timer (the time the song has been playing) and the actual song. Well, in this case, the music and a timer need to be exactly in sync. Sure, this may not be how they actually coded this program, but the basic idea of the song being accurate with the timer is what I’m getting at.

I am currently programming a game that requires this type of setup. I know that you can set markers within a music to trigger events, but I would rather just be able to play a song and have it run exactly with a timer, and time events on that specific timer. My engine is built with its own timer, and has functions that run on certain events within the timer in the engine.

Well, the problem I have been having is parts of my levels are graphically intensive, and use a lot of the computer’s power. This reduces the amount of the CPU that FMOD can utilize, and the song crackles a bit, and goes off sync.

So my question is how can I get a song to play exact. What I was thinking is throughout the game, perhaps once a second, poll the song and my game timer to see if there is a significant difference. If so, adjust the song.

I am currently using a stream to play the song. Please forgive me because I am very new at FMOD, so I may not have included all of the important information on this problem. I hope someone can help me out with this. Thanks in advance,

–Vic–

Edit: Oh, and I just read the forum rules. I am programming in Visual C++ 6, Win XP, and programming just for a regular Windows fullscreen game. But much of that doesn’t matter as I am addressing the issue of how to keep a song playing in sync with an external timer.

  • You must to post comments
0
0

There is a FSOUND_Stream_GetTime function that tells you where in the song you are.

  • You must to post comments
0
0

Yeah, I know about that. I guess my main question is what would be the best way to do this performance wise. I don’t know what type of functions are acceptable to call frequently.

Last night, as a test, I did the following: I took the game time, and then subtracted the song time. The weird thing is I’d always get around 100 ms difference. Even if I’d set the time of the stream to the game time, I’d still get a 100 ms difference. However, this time was accurate. What I then did is if this difference was greater than 120 ms, I’d reset the playing time to the game time. The time was again 100 ms off, but the song played perfect to the events in the game.

I’m just curious if this is an acceptable method, and why the time might vary like that.

–Vic–

  • You must to post comments
0
0

I think it is an acceptable method, and I don’t think getting the time of a stream very frequently will get you any performance issues.

I suppose the 100 ms has to do with latency between the time you call the start function and the time it actually starts playing.

It might be related to fmod’s buffer size too.

  • You must to post comments
0
0

If you want trigger events from Fmod, you can use callbacks, markers and MPEGACCURATE. This way is very precise. 8)

  • You must to post comments
0
0

brett: You said to either use FSOUND_HW2D or to subtract the buffersize.

So first I tried opening the stream with the FSOUND_HW2D argument, but that didn’t seem to help much. In fact, the song never even played.

Here is my actual code:

[source]

FSOUND_Init(44100, 32, 0);

G.tempSong = FSOUND_Stream_OpenFile(“music/Aquilia.mp3”, 0 , 0);

G.musicChannel = FSOUND_Stream_Play(0, G.tempSong);

[/source]

If I put FSOUND_HW2D in place for the first 0 in FSOUND_Stream_OpenFile, the song doesn’t play. I’m not sure what I’m doing wrong there.

You also mentioned to subtract the buffer size. I really don’t know what you mean by that. I’m still a newbie :) Could you elaborate a little bit? Thanks,

–Vic–

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.