Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,646 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,120 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
post 18 Aug, 2008 - 04:23 PM
Post #1


D.I.C Regular

***
Joined: 14 Feb, 2008
Posts: 258



Thanked 6 times
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 offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:47AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month