Nicely Wrapped Up FMod library

Heres a nice little wrapper for the fmod library i wrote today

Page 1 of 1

0 Replies - 2999 Views - Last Post: 18 August 2008 - 05:23 PM Rate Topic: -----

#1 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Nicely Wrapped Up FMod library

Posted 18 August 2008 - 05:23 PM

hey everyone

if you have a project and you dont wanna use SDL for sound i have nicely wrapped up the Fmod library in c++ style for anyone who wants it, it still needs a lot of work to include all the features of FMOD but it will work to play music and sound effects easily enjoy, add both files to your project


#include <string>
#include "fmod.h"

class SoundManager


   static SoundManager* Instance();
   bool PlayStream(const std::string& filename, int channel);
   bool PlayMusic(const std::string& filename);
   bool PlaySample(const std::string& filename, int channel);
   void Update();
   SoundManager(const SoundManager&);
   SoundManager& operator=(const SoundManager&);



cpp file
#include "SoundManager.h"

#include <string>

SoundManager* SoundManager::Instance()
	static SoundManager sm;
	return &sm;

// Use streams for mp3s and other compressed audio
bool SoundManager::PlayStream(const std::string& filename, int channel)
   FSOUND_STREAM* stream = FSOUND_Stream_Open(filename.c_str(), 0, 0, 0);
   return true;   
// Use samples for sound effects and such
bool SoundManager::PlaySample(const std::string& filename, int channel)
   FSOUND_SAMPLE* sample = FSOUND_Sample_Load(0,filename.c_str(), 0, 0, 0);
   return true;
// Use music for things such as midi files, not very useful streams are better
bool SoundManager::PlayMusic(const std::string& filename)
   FMUSIC_MODULE* music = FMUSIC_LoadSong(filename.c_str());
   return true;

void SoundManager::Update()



example usage
SoundManager::Instance()->PlayStream("MetalMusic.mp3", 1);

choose stream to play music files and the other functions for sound effects :) the int is the channel you want the sound to play on, with a total of 32 channels i think, FMOD is not for commercial projects

any questions?

quick link if you dont know what FMOD is


gotta love singletons :)

This post has been edited by stayscrisp: 18 August 2008 - 05:31 PM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1