0
0

Hi,

I’m new to FMOD programming and I’m using c++ with VIsual Studio 2008.

I’ve altered the PlaySound example code like so

Main.cpp

[code:j00ldu87]#include "fmod.hpp"

include <windows.h>

include <stdio.h>

include <conio.h>

include "functions.h"

int main()
{
FMOD::System *system;
FMOD_RESULT result;
unsigned int version;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
int key = NULL;

result = FMOD::System_Create(&amp;system);      // Create the main system object.
ERRCHECK(result);

result = system-&gt;getVersion(&amp;version);
ERRCHECK(result);

if (version &lt; FMOD_VERSION)
{
    printf(&quot;Error!  You are using an old version of FMOD %08x.  This program requires %08x\n&quot;, version, FMOD_VERSION);
    return 0;
}

result = system-&gt;init(32, FMOD_INIT_NORMAL, 0);  // Initialize FMOD.
ERRCHECK(result);

result = system-&gt;createSound(&quot;../media/drumloop.wav&quot;, FMOD_HARDWARE, 0, &amp;sound);
ERRCHECK(result); 

result = sound-&gt;setMode(FMOD_LOOP_OFF);    /* drumloop.wav has embedded loop points which automatically makes looping turn on, */
ERRCHECK(result);  

result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound, false, &amp;channel);
ERRCHECK(result);
result = channel-&gt;setVolume(0.5f);       // Set the volume while it is paused.
ERRCHECK(result);
result = channel-&gt;setPaused(false);      // This is where the sound really starts.
ERRCHECK(result);

system-&gt;update();

bool done = false;

/*
    Main loop.
*/
while(!done)
{

}

/*
    Shut down
*/
result = sound-&gt;release();
ERRCHECK(result);
result = system-&gt;close();
ERRCHECK(result);
result = system-&gt;release();
ERRCHECK(result);

return 0;

}[/code:j00ldu87]

What I found to be puzzling is the fact that although the main loop doesn’t appear to do anything, my programme wouldn’t play the sound if it was out commented.

So my question is a loop essential in order to play a sound? Please advice.

Cheers,

Dana

  • You must to post comments
0
0

Hi Dana, welcome to the forums.

If there is no loop then the cleanup code at the end will be called immediately after the sound is created and there will be no time to play the sound.

The reason the sound plays while the main function is just spinning in a loop is because FMOD is multi-threaded. The sound is playing in the ‘mixer’ thread.

If you want to learn more about multi-threading:
http://en.wikipedia.org/wiki/Thread_%28 … science%29

-Pete

  • You must to post comments
0
0

Hi Pete,

Oh i see, well it definitely answered my question. Thank you mate! :)

Regards,

Dana

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.