Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Fmod Ex, audio sync problem  (Read 3908 times)

Ice

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
Fmod Ex, audio sync problem
« on: July 20, 2008, 08:06:52 AM »

Hi guys. I'm trying to create Fmod Ex sound module for Theora Plugin. It almost works, but I have one problem: audio is out of sync, it starts to play 1 second later (with all theora clips).
There is cegui demo with new fmod module (tested only on linux): http://berks.narod.ru/cegui_fmodex.tar.bz2
So, is there any solution?
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Fmod Ex, audio sync problem
« Reply #1 on: July 20, 2008, 08:39:29 AM »

Perhaps you could try the OpenAL sound system? Though, I haven't seen too many audio sync issues starting out so bad, so don't have much advise. There could very well be some sort of bug. What Theora lib are you using? The last time this was really updated/tested was a couple years ago. Could be some changing in the theora lib for sure.
Logged

Ice

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
Re: Fmod Ex, audio sync problem
« Reply #2 on: July 21, 2008, 07:27:13 AM »

Tried with theora 1.0_beta2-r1 and 1.0_beta3-r1, fmod 4.11.03.
OpenAL doesn't work for me, it produces some kind of static noise instead of sound  :)
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Fmod Ex, audio sync problem
« Reply #3 on: July 21, 2008, 09:05:04 AM »

Hmm, odd. What OS? Maybe try not using Fmod Ex, the samples were built with a previous Fmod version (before Ex).
Logged

Ice

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
Re: Fmod Ex, audio sync problem
« Reply #4 on: July 22, 2008, 06:45:43 AM »

Gentoo linux amd64.
Even when I managed to compile samples with old fmod-3.75 (there were some gcc4 related problems in fmoddyn.h), program refuses to start with error:
Code: [Select]
An exception has occured: OGRE EXCEPTION(5:ItemIdentityException): fmod?.so not found in FmodSoundManager::startDon't know why, because libfmod is there:
Code: [Select]
# whereis libfmod.so
libfmod: /usr/lib/libfmod.so /usr/lib64/libfmod.so
# whereis libfmod-3.75.so
libfmod-3.75: /usr/lib/libfmod-3.75.so /usr/lib64/libfmod-3.75.so
and of course I changed
Code: [Select]
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
  inst = FMOD_CreateInstance( "libfmod-3.74.so" );
to
Code: [Select]
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
  inst = FMOD_CreateInstance( "libfmod-3.75.so" );
in FmodSoundManager::start().  :-\
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Fmod Ex, audio sync problem
« Reply #5 on: July 22, 2008, 07:02:00 AM »

You can try hard coding the path in the library loading. Or, try putting the fmod library into the plugin folder. Perhaps you need to refresh your ld cache, ldconfig or whatnot.
Logged

Ice

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
Re: Fmod Ex, audio sync problem
« Reply #6 on: July 23, 2008, 12:53:00 PM »

Hardcoding the path and ldconfig stuff doesn't work (even tried to run with LD_LIBRARY_PATH="/usr/lib64/OGRE" variable).
BTW, I tried to debug my fmodex sound plugin and found that audio timer and movie timer are always identical when playing movie (+/- 0.002 sec). But in all movies sound appears after 0.5-1 second.... Is it magic? :)
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Fmod Ex, audio sync problem
« Reply #7 on: July 23, 2008, 01:05:09 PM »

Hmm, no magic I can recall. Might be a 64 bit issue, as I have never tested any of this under such an OS with 64 bit support. Perhaps, if you have access to another machine which is not 64 bit and see what the behavior is.

As for why the library will not load, that is a mystery. You could run ld on the audio module to see if it can locate the fmod library from the command line and try to fix the issue from there.
Logged

Ice

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
Re: Fmod Ex, audio sync problem
« Reply #8 on: July 24, 2008, 10:41:42 AM »

My friend helped me to find possible reason of the problem - when movie starts to play, fmod calls callback to feed data. But it seems like there is no data in the buffer yet (len - how many data fmod wants, numRead - how many data we read from buffer):
Code: [Select]
Loading library FMOD_MOD
FmodSoundManager:start OK
Vorbis Headers: 3 Theora Headers : 3
Texture: Europe.ogg: Loading 1 faces(PF_B8G8R8,352x288x1) with 0 generated mipmaps from Image. Internal format is PF_X8R8G8B8,352x288x1.
Latency: 2.97215
len - 16384 numRead - 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
len- 16384 numRead- 0
Audio timer- 0.008
Audio timer- 0.008
Movie time- 0.008
Audio timer- 0.035
...
Then after 0.5 sec fmod tries to call callback again:
Code: [Select]
Movie time- 0.49
Audio timer- 0.49
len- 16384 numRead- 16384
len- 16384 numRead- 16384
len- 16384 numRead- 10752
len- 16384 numRead- 0
len- 16384 numRead- 0
Audio timer- 0.528
FMOD timer- 22579
Audio timer- 0.528
and sound starts to play.
Also, there is parameter when initialising fmod:
Quote
decodebuffersize
[in] Optional. Specify 0 to ignore. For streams. This determines the size of the double buffer (in PCM samples) that a stream uses. Use this for user created streams if you want to determine the size of the callback buffer passed to you. Specify 0 to use FMOD's default size which is currently equivalent to 400ms of the sound format created/loaded.
I think it defines 'len' value. And I guess fmod won't start play sound until it fill buffer with this amount of data. When I changed 'decodebuffersize' to 2048, audio delay decreased, but not disappeared. If I change 'decodebuffersize' to any value less then 2048, then sound becomes crappy.
So, is there any easy way to fill the buffer with certain amount of data, and only then start to play movie?
« Last Edit: July 24, 2008, 10:43:46 AM by Ice »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Fmod Ex, audio sync problem
« Reply #9 on: July 24, 2008, 07:39:14 PM »

Maybe a method needs to be added to video plugin to somehow resync audio / video in regards to how much the audio library is buffering before playback. not sure best method to do this. Though, I don't recall any initial sync problems this noticeable. I know there was drift, that would happen after so long, but not at the start. Ideas are welcome. However, I'm sure you are aware that I do not actively maintain this library anymore. The best I would suggest is patch it so it works for you and your videos as well as seems well on other computers (ie by adding a hard coded .5 delay to video timer perhaps). Or, find a general method to make it work with different audio libs.

Though, I would nowadays probably use gstreamer library to enable playback of multiple types of codecs.. I might even use ffmpeg again. As, these are generally more high performant than the theora library (even when using the theora codec, those libs have more optimised code paths and are typically easier to work with than ogg/theora/vorbis).
Logged

Ice

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
Re: Fmod Ex, audio sync problem
« Reply #10 on: July 25, 2008, 12:33:39 PM »

Finally, with your help I found the solution.
I just added extra 'if' to blitFrameCheck function to wait until audio buffer is ready. Now it works great. Again, thanks for your great plugin!
P.S.: I would like to fork your project (TheoraVideo and SoundModules parts) because you don't maintain it anymore. What do you think about it?
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Fmod Ex, audio sync problem
« Reply #11 on: July 25, 2008, 04:28:25 PM »

If you wanted to create a fork at such a site as Sourceforge, I would be happy :) Would be useful, i just don't have anytime for maintaining this anymore, as I'm not currently using it.
Logged

dermont

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 23
    • View Profile
Re: Fmod Ex, audio sync problem
« Reply #12 on: August 15, 2008, 04:18:09 AM »

@Ice, nice job with the Fmod Ex sound module. Thanks for sharing your code.
Logged