Author Topic: How to preload soundfiles?  (Read 2345 times)

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
How to preload soundfiles?
« on: 2012-Sep-13 »
Hi all,

when I load a MOD-soundfile with Fmod_Load() while playing the game, the graphics lag for a few millisecs while the file is getting loaded. The code I use is pretty straightforward and supposed to switch between two files only.

Code: (glbasic) [Select]
IF FMod_IsFinished() = TRUE
IF snd_current% = 0
FMod_Load(snd_current$[1])
snd_current% = 1
ELSEIF snd_current% = 1
FMod_Load(snd_current$[0])
snd_current% = 0
ENDIF
FMod_Play()
ENDIF

Now my question is: Is there a better way to load/play songs via Fmod, and how can I prevent the short lag while loading?

Best,
P.  :)
« Last Edit: 2012-Sep-17 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: Fmod_Load() lags
« Reply #1 on: 2012-Sep-14 »
I think the best way is to load all things you'll need for your game (music, sound, graphics etc.) before the main game loop, not in it. Depending on the size of the loaded files you'll see lags in the game. Not very nice!

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: Fmod_Load() lags
« Reply #2 on: 2012-Sep-16 »
Hi Quentin,

I would love to preload all music files, but I am not sure how that works with Fmod_Load(). Is it possible to read some audio-files into an array and then selectively play them using Fmod_Play()? I think that Fmod_Play() only plays the file that is currently loaded, so whenever I need to play a different file, I have to use fmod_load(myfile$) first... Fmod_Play(myfile$) doesn't work, right?

Or is it possible to do something like this (last time I tried it didn't work):

Code: (glbasic) [Select]
Global m[]
Dim m[3]

m[0] = Fmod_Load("file1.mod")
m[1] = Fmod_Load("file2.mod")
m[2] = Fmod_Load("file3.mod")

Fmod_Play(m[1])

Hope you can help me out here. Thanks in advance :-) ! P.
« Last Edit: 2012-Sep-16 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: How to preload soundfiles?
« Reply #3 on: 2012-Sep-17 »
sorry I'm not that familiar with FMOD and don't know which version you're using. Perhaps you'll find something like STREAM_OPEN to load a song into a buffer and STREAM_PLAY to play it afterwards.

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: How to preload soundfiles?
« Reply #4 on: 2012-Sep-17 »
Hm, Stream_Open / Stream_Play, are those OpenGL-commands? Didn't find them in the GLBasic documentation.

Anyway, I still believe that it has to be possible to use FMod_Load() and FMod_Play() to preload sounds at the start of the program and play them from memory. Would be kind of odd if that wasn't possible...

So if anyone has any idea of how to preload MOD-files and play them from memory, please leave a reply :-)
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

MrTAToad

  • Guest
Re: How to preload soundfiles?
« Reply #5 on: 2012-Sep-17 »
The FMOD system that GLBasic has an interface for is rather old - the later one uses completely different functions.  See this post of mine for more information : http://www.glbasic.com/forum/index.php?topic=2678.msg19891#msg19891

Steaming should be in the later versions, if I remember correctly...

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: How to preload soundfiles?
« Reply #6 on: 2012-Sep-17 »
Hm ok, now that really confuses me.  :blink:

So what exactly do I need in order to preload mod-files?
Which version of FMOD from their download page? (http://www.fmod.org/fmod-downloads.html)
Which are the functions that can be used in GLBasic?
Is there a tutorial somewhere so I don't have to bother the people in this forum?

Sorry, but the link to your post didn't make things clearer to me at all - if anything, things seem to have gotten much more complicated...  ::)


« Last Edit: 2012-Sep-17 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

MrTAToad

  • Guest
Re: How to preload soundfiles?
« Reply #7 on: 2012-Sep-17 »
The new FMOD system is a lot more complicated unfortunately, and I only did a few functions.  The main problem is that it isn't compatible with Linux

You would use FMOD_CreateSound to load all sounds which should work with MOD tunes - and then you use FMOD_PlaySound to play them
« Last Edit: 2012-Sep-17 by MrTAToad »

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: How to preload soundfiles?
« Reply #8 on: 2012-Sep-17 »
So is there another way of preloading music/mod files besides FMOD? BASS maybe?
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: How to preload soundfiles?
« Reply #9 on: 2012-Sep-17 »
Ok i just found out that Schranz0r posted a BASS.dll somewhere... maybe I'll drop him a PM.
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

MrTAToad

  • Guest
Re: How to preload soundfiles?
« Reply #10 on: 2012-Sep-17 »
By the way, both FMOD and BASS could require licences...

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: How to preload soundfiles?
« Reply #11 on: 2012-Sep-17 »
Hi MrTAToad, I know about the licensing issue, but since I'm not planning to sell my game (who's gonna buy the millionst breakout clone anyway), that's not a problem. I also figured it might be better to switch songs relative to the current level. Then the gameplay itself is not interrupted when loading the file. Perhaps not the most elegant solution, but as I want to complete the game soon (at least the first 32 levels), I decided to go with the most pragmatic approach.  :P

Still, if anyone out there knows about a simple solution for preloading mod-files - feel free to leave a reply :)
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

MrTAToad

  • Guest
Re: How to preload soundfiles?
« Reply #12 on: 2012-Sep-18 »
The other way would be to merge all your tunes into one large mod file.

The problem is that pre-loading everything increases memory usage - especially if a tune is only used a few times.