Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,142 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,357 people online right now. Registration is fast and FREE... Join Now!




Nicely Wrapped Up FMod library

 
Reply to this topicStart new topic

Nicely Wrapped Up FMod library, Heres a nice little wrapper for the fmod library i wrote today

stayscrisp
18 Aug, 2008 - 04:23 PM
Post #1

Dori-mu in Ko-do
Group Icon

Joined: 14 Feb, 2008
Posts: 906



Thanked: 36 times
Dream Kudos: 250
My Contributions
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

CODE

#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
CODE


#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
CODE


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



choose stream to play music files and the other functions for sound effects smile.gif 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.net/reference/articles/article2098.asp


gotta love singletons smile.gif

This post has been edited by stayscrisp: 18 Aug, 2008 - 04:31 PM

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 03:56AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month