Sign in to follow this  
Lil_Lloyd

FMOD set volume, set loop not working....

Recommended Posts

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]
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]


The loading code is as follows

[CODE]
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]

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]
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this