Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Lil_Lloyd   Members   -  Reputation: 287

Like
0Likes
Like

Posted 09 July 2012 - 07:13 AM

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:

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;
}


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS