0
0

Completely new to FMOD here. I’ve been looking around at examples and tutorials and I have produced the following code, which as far as I can tell should work. However, when I run the code I don’t hear any sound (although I do hear some sort of blip, if that’s important). Any advice would be extremely helpful, even if it’s just to point me to a tutorial I might not have seen yet (have yet to find a really good one…).

[code:1weje1j7]#include "inc/fmod.hpp"

include "inc/fmod_errors.h"

include <stdio.h>

include <string.h>

include <cstdlib>

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}

int main() {
FMOD::System *system;
FMOD::Sound *sound1;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
unsigned int version;
void *buff = 0;
// Create a System object and initialize.
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
// Load sound file:
result = system->createSound("5.wav", FMOD_SOFTWARE, 0, &sound1);
ERRCHECK(result);
// Set volume:
channel->setVolume(0.5f);
// Play sound:
result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
system->update();
// Shutdown:
result = sound1->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}[/code:1weje1j7]

Could it be something not related to the code? For instance, do I need to make sure to exit all audio players first?

And yes, I’ve checked that "5.wav" exists and plays correctly in other audioplayers, if I put a random sound file name in there that doesn’t I get a file not found error.

I’m compiling with the following command:

[code:1weje1j7]g++ fmod_tutorial.cpp /path/to/libfmodex.dylib -o a.out[/code:1weje1j7]

And set my DYLD_LIBRARY_PATH variable as:

[code:1weje1j7]export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/path/to/libfmodex.dylib[/code:1weje1j7]

Any help will be greatly appreciated,

Thanks!

  • You must to post comments
0
0

You’re playing the sound, and then immediately shutting down.

Try replacing the update() call with something like this:

[code:6r5bg497]bool bIsPlaying = true;
while(bIsPlaying)
{
system->update();
channel->isPlaying(&bIsPlaying);
}
[/code:6r5bg497]

Also, you’re setting the volume on the channel before you’re playing anything on it. You should switch the order of your playSound() and setVolume() calls.

Hope that helps!

(Edit: Added note about setVolume())

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.