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;
};
The loading code is as follows
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;
}
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?
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;
}