0
0

I’m having some real issues with controlling the looping and volume of audio effects in my game. I have a sample class played by FMOD as follows:

[code:1amkvvrn]
class Sound
{
public:
FMOD_SOUND* soundData;
FMOD_CHANNEL* channel;
Sound();
~Sound();
const std::string& GetName()const {return name;}
void SetName(const std::string& fileName) {name = fileName;}
private:
std::string name;
};

[/code:1amkvvrn]

The loading code is as follows

[code:1amkvvrn]
bool Audio::Load(const std::string& fileName,const std::string& name)
{
if(fileName.length() == 0 || name.length() == 0) return false;
Sound* sample = new Sound;
sample->SetName(name);
FMOD_RESULT res;
res = FMOD_System_CreateSound(
system,
fileName.c_str(),
FMOD_DEFAULT,
NULL,
&sample->soundData);
if(res != FMOD_OK) return false;
samples.push_back(sample); //pushes the sample into a vector of sounds for playback later
return true;
}
[/code:1amkvvrn]

However the playback code uses FMOD_Channel_Set functions to set different variables, but they don’t seem to work! They neither loop or change the volume of the playback. Can someone please help?

[code:1amkvvrn]
bool Audio::Play(const std::string& name,float volume,bool looped,int numLoops)
{
FMOD_RESULT res;
Sound* sample = FindSound(name);
if(sample->soundData != NULL)
{

if(!looped)
{
FMOD_Channel_SetLoopCount(sample->channel,-1);
}
else
{
FMOD_Channel_SetLoopCount(sample->channel,numLoops);
}

//set the sample volume using the channel stored within the sound object
//set during loading

FMOD_Channel_SetVolume(sample->channel,volume);

res = FMOD_System_PlaySound(
system,
FMOD_CHANNEL_FREE,
sample->soundData,
true,
&sample->channel);

if(res!=FMOD_OK)return false;

FMOD_Channel_SetPaused(sample->channel,false);
}
return true;
}
[/code:1amkvvrn]

  • You must to post comments
0
0

You need to call playSound first to create a channel, only then can you use the set functions.
If you get the FMOD_RESULT from those set functions with the current code you will receive FMOD_ERR_INVALID_HANDLE.

  • You must to post comments
0
0

Thank you very much Matthew!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.