daily pastebin goal
64%
SHARE
TWEET

corbinFmodWrapper

invadrzim Apr 9th, 2012 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FMOD sound wrapper and sound manager wrapper interfaces:
  2.  
  3. //------------------------------------------------------------------------------
  4. //Copyright Charles Corbin
  5. //
  6. //FMOD audio system wrapping
  7. //------------------------------------------------------------------------------
  8. #pragma once
  9.  
  10. #include <fmod.hpp>
  11. #include <windows.h>
  12. //*********************************************
  13. //                              FMOD Sound
  14. //*********************************************
  15. class FSound
  16. {
  17.         FMOD::System*   localSystem;
  18.         FMOD::Channel*  channel;
  19.         FMOD::Sound*    sound;
  20.         FMOD_RESULT             result;
  21.  
  22. public:
  23.         FSound(FMOD::System* inSystem){localSystem = inSystem;};
  24.         ~FSound(){localSystem = NULL;};
  25.  
  26.         bool isPlaying();
  27.         bool playOnce();
  28.         bool playLooping();
  29.         bool playLooping(int inCount);
  30.         bool stop();
  31.  
  32.         bool mute();
  33.         bool unMute();
  34.         bool isMuted();
  35.  
  36.         bool pause();
  37.         bool unPause();
  38.         bool isPaused();
  39.  
  40.         void setVolume(float inVolume);
  41.         float getVolume();
  42.         void volumeUp(float inMag);
  43.         void volumeDown(float inMag);
  44.  
  45.         void loadFull(char* fileName);
  46.         void loadStream(char* fileName);
  47. };
  48.  
  49. ********************************************************************************************************
  50.  
  51.  
  52. FMOD sound wrapper bodies:
  53.  
  54. //*********************************************
  55. //                              FMOD Sound
  56. //*********************************************
  57. bool FSound::isPlaying()
  58. {
  59.         bool out;
  60.         channel->isPlaying(&out);
  61.         return out;
  62. }
  63. bool FSound::playOnce()
  64. {
  65.         return localSystem->playSound(FMOD_CHANNEL_FREE, sound, false, 0);
  66.  
  67. }
  68. bool FSound::playLooping()
  69. {
  70.         localSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
  71.         channel->setMode(FMOD_LOOP_NORMAL);
  72.         return true;
  73. }
  74. bool FSound::playLooping(int inCount)
  75. {
  76.         localSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
  77.         channel->setMode(FMOD_LOOP_NORMAL);
  78.         channel->setLoopCount(inCount - 1);
  79.         return true;
  80. }
  81. bool FSound::stop()
  82. {
  83.         return channel->stop();
  84. }
  85.  
  86. bool FSound::mute()
  87. {
  88.         return channel->setMute(true);
  89. }
  90. bool FSound::unMute()
  91. {
  92.         return channel->setMute(false);
  93. }
  94. bool FSound::isMuted()
  95. {
  96.         bool out;
  97.         channel->getMute(&out);
  98.         return out;
  99. }
  100.  
  101. bool FSound::pause()
  102. {
  103.         return channel->setPaused(true);
  104. }
  105. bool FSound::unPause()
  106. {
  107.         return channel->setPaused(false);
  108. }
  109. bool FSound::isPaused()
  110. {
  111.         bool out = 0.0;
  112.         channel->getPaused(&out);
  113.         return out;
  114. }
  115.  
  116. void FSound::setVolume(float inVolume)
  117. {
  118.         channel->setVolume(inVolume);
  119. }
  120.  
  121. float FSound::getVolume()
  122. {
  123.         float out;
  124.         channel->getVolume(&out);
  125.         return out;
  126. }
  127.  
  128. void FSound::volumeUp(float inMag)
  129. {
  130.         if(getVolume() + inMag > 1.0f){return;}
  131.         setVolume(getVolume() + inMag);
  132. }
  133. void FSound::volumeDown(float inMag)
  134. {
  135.         if(getVolume() - inMag > 1.0f){return;}
  136.         setVolume(getVolume() - inMag);
  137. }
  138.  
  139. void FSound::loadFull(char* fileName)
  140. {
  141.         if(!sound)
  142.         {
  143.                 result = localSystem->createSound(fileName, FMOD_DEFAULT, 0, &sound);
  144.                 stringstream errMsg;
  145.                 errMsg << "can't load sound: " << fileName;
  146.                 throw Error(result, errMsg.str());
  147.         }
  148. }
  149. void FSound::loadStream(char* fileName)
  150. {
  151.         localSystem->createStream(fileName, FMOD_DEFAULT, 0, &sound);
  152.         if(!sound)
  153.         {
  154.                 stringstream errMsg;
  155.                 errMsg << "can't load sound: " << fileName;
  156.                 throw Error(result, errMsg.str());
  157.         }
  158. }
  159.  
  160.  
  161. *********************************************************************************************************
  162.  
  163. How this is being implemented in the actual game:
  164.  
  165. in my game interface file i have:
  166.  
  167. FSound* testSound;
  168.  
  169. in the Game bodies file:
  170.  
  171. void Level_1::activate()
  172. {
  173.         //Audio Allocation
  174.         testSound = audio->loadFSound("snd_laserbolt.wav", true);
  175. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top