Nicely Wrapped Up FMod library

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

Page 1 of 1

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

#1 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • 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

#ifndef SOUND_MANAGER_H
#define SOUND_MANAGER_H

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

class SoundManager
{

public:

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

};


#endif



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);
   FSOUND_Stream_Play(channel,stream);
   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);
   FSOUND_PlaySound(channel,sample);
   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());
   FMUSIC_PlaySong(music);
   return true;
}

void SoundManager::Update()
{
   FSOUND_Update();
}

SoundManager::SoundManager()
{
   FSOUND_Init(44100,32,0);
}

SoundManager::~SoundManager()
{
   FSOUND_Close();
}



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

http://www.gamedev.n...article2098.asp


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