Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: music loop ran out of sync  (Read 3649 times)

0 Members and 1 Guest are viewing this topic.

robot

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 38
    • View Profile
music loop ran out of sync
« on: May 08, 2010, 03:16:37 PM »

hi there!

i would like to implement an rythm game so i learned something about the music functions and read some threads about it. unfortunatly there are not so many of them
like http://forum.dead-code.org/index.php?topic=3269.0

i see that the Get- and SetMusicPosition method doesn't work correctly so i use the Game.CurrentTime method for synchronisation like Mnemonic has suggested in some threads.
and it seems to work very exactly at the beginning but after a while it runs out of sync. to show you the problem i have following code:

first i play the loop sound:

Code: [Select]
Game.PlayMusicChannel(0,"takt.wav",true);
then i run a loop where an "X" will be written every time the music loop starts from the beginning

Code: [Select]
  var len = Game.GetSoundLength(Game.GetMusicChannel(0));
  var time = Game.CurrentTime;

  while(true)
  {
    if(Game.CurrentTime-time >= len)
    {
      time = Game.CurrentTime;
      Game.Msg("X");
    }
    Sleep(1);
  }


i ran this script and after a few minutes the "X" won't be written exactly at the loopbeginning. it totally ran out of sync.
so first i thought the GetSoundLength() didn't work correctly but in my opinion it does. i checked the wav file in my
cubase and its the same lenght like wme says (2594 ms).
so i wonder what causes this behaviour. maybe the Sleep() method? does the CurrentTime stops when calling the Sleep()?

i know this is a very special problem or maybe i'm working in a totaly wrong direction? ;D
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: music loop ran out of sync
« Reply #1 on: May 09, 2010, 09:39:51 PM »

You can try using Game.WindowsTime instead. That's the actual "live" timer. See if it makes a difference.
The bad thing about Game.WindowsTime is, that if the player saves the game and restores it late, your timing will be completely off.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

robot

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 38
    • View Profile
Re: music loop ran out of sync
« Reply #2 on: May 09, 2010, 10:14:05 PM »

thanks mnemonic for your answer but no, its the same problem with WindowsTime.
hmm, that means that both timers didn't work correctly!?

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: music loop ran out of sync
« Reply #3 on: May 10, 2010, 07:51:59 PM »

How much off is the timing? There will always be slight difference, because the scripts are updated once per frame. So if your game runs e.g. at 60FPS, the script is updated approximately every 17 milliseconds.
Other than that, Game.WindowsTime should be pretty precise, because it queries the Windows timer directly.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

robot

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 38
    • View Profile
Re: music loop ran out of sync
« Reply #4 on: May 10, 2010, 09:28:44 PM »

about 200 ms after one minute. but now i notice something interesting: my wav file is 2594 ms.
now i took a wav file with about 1 minute length and it was syncron. so it looks to me that there
must be a very small delay when looping the sound with PlayMusicChannel; maybe less than 1 ms...

i also tested it playing the two wav files (the same noise but one is longer) at the same time:

Code: [Select]
Game.PlayMusicChannel(0,"takt.short.wav",true);
Game.PlayMusicChannel(1,"takt.long.wav",true);

after a while you can hear the difference...
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: music loop ran out of sync
« Reply #5 on: May 10, 2010, 09:40:27 PM »

try preloading the sound
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

robot

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 38
    • View Profile
Re: music loop ran out of sync
« Reply #6 on: May 10, 2010, 10:10:43 PM »

hmm...but both wav sounds start at the same time like i wrote before so i think to preload them makes no difference.
however, i did an workaround:

my aim was to make a metal band playing there instruments seperatly at any time. so the timing of drum, guitar, bass
and vocals has to be correct.
now when the drummer start to play his drums, i also start to play the guitar, the bass and the vocal sound but with
volume 0. so i have to set only the volume to 100 when starting a other instrument.

seems to work, in this sense  ::rock  ;D
Logged
 

Page created in 0.021 seconds with 23 queries.