Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

ExManagerSound Class Reference

#include <ExManagerSound.h>

Inheritance diagram for ExManagerSound:

ExManagerObject< ExCSound > ExManager

Public Methods

void Init (void)
void Reset (void)
ExCAction InputCommand (ExCCommand Command)
ExCAction InputAction (ExCAction Action)
void DisplayAviableInput (void)
bool LoadSound (std::string)
bool RemoveSound (std::string)
void PlaySound (std::string)
void StopSound (std::string)
int GetSound (std::string)

Static Public Methods

ExManagerSound * CreateSingleton (void)

Private Methods

 ExManagerSound (void)
 ~ExManagerSound (void)

Private Attributes

bool m_initok
ALCcontext * context
ALCdevice * device
ALuint buffer_index
ALuint buffer [MAX_BUFFER]
ALint error
ALboolean loop
ALuint source_index
ALuint source_available
ALuint source [64]

Static Private Attributes

bool m_flag = false
ExManagerSound * m_instance = NULL

Constructor & Destructor Documentation

ExManagerSound void    [private]
 

Definition at line 43 of file ExManagerSound.cpp.

References buffer_index, m_initok, source_available, and source_index.

00044 {
00045   buffer_index = 0;
00046   source_index = 0;
00047   source_available = 0;
00048   m_initok=false;
00049 }

~ExManagerSound void    [private]
 

Definition at line 51 of file ExManagerSound.cpp.

References context.

00052 {
00053         alcDestroyContext (context);
00054 }


Member Function Documentation

ExManagerSound * CreateSingleton void    [static]
 

Definition at line 29 of file ExManagerSound.cpp.

References CreateSingleton(), Guard, m_flag, and m_instance.

Referenced by CreateSingleton(), and main().

00029                                                    {
00030 Guard(ExManagerSound* ExManagerSound::CreateSingleton(void))
00031         if(!m_flag)
00032         {
00033                 m_flag = true; // We are creating the error log now, so set flag to true
00034                 m_instance = new ExManagerSound; // Create the error log
00035         }else
00036         {
00037                 std::cout<<"Error singleton already created"<<std::endl;
00038         }
00039         return m_instance; 
00040 UnGuard
00041 }

void DisplayAviableInput void   
 

Definition at line 99 of file ExManagerSound.cpp.

References ExManager::Consol, DisplayAviableInput(), Guard, and m_initok.

Referenced by DisplayAviableInput(), and InitManager().

00099                                               {
00100 Guard (void ExManagerSound::DisplayAviableInput (void))
00101         if(!m_initok)return;
00102         *Consol<<"****************************************"<<std::endl;
00103         *Consol<<"* Soundsystem init success             *"<<std::endl;
00104         *Consol<<"****************************************"<<std::endl;
00105         *Consol<<"Company        : "<<alGetString (AL_VENDOR)<<std::endl;
00106         *Consol<<"Version        : "<<alGetString (AL_VERSION)<<std::endl;
00107         *Consol<<"Renderer       : "<<alGetString (AL_RENDERER)<<std::endl;
00108         *Consol<<"Extensions     : "<<alGetString (AL_EXTENSIONS)<<std::endl;
00109         *Consol<<"****************************************"<<std::endl;
00110 UnGuard
00111 }

int GetSound std::string   
 

Definition at line 223 of file ExManagerSound.cpp.

References GetSound(), and Guard.

Referenced by GetSound().

00223                                             {
00224 Guard (ExCSound* ExManagerSound::GetSound (std::string file))
00225         return -1;
00226 UnGuard
00227 }

void Init void    [virtual]
 

Reimplemented from ExManagerObject< ExCSound >.

Definition at line 56 of file ExManagerSound.cpp.

References buffer, ExManager::Consol, context, device, error, Guard, ExManagerObject::Init(), m_initok, MAX_BUFFER, MAX_SOURCE, source, and source_available.

Referenced by InitManager().

00057 {
00058 Guard (void ExManagerSound::init (void))
00059         ExManagerObject<ExCSound>::Init();      
00060         device = alcOpenDevice(NULL);
00061         if(device == NULL)
00062         {
00063                 *Consol <<"ExManagerSound:: alcOpenDevice error "<<std::endl;
00064                 return ;
00065         }
00066         context=alcCreateContext(device,NULL);
00067         alcMakeContextCurrent(context);
00068         //Generate buffers
00069         alGenBuffers(MAX_BUFFER,buffer);
00070         if ((error = alGetError()) != AL_NO_ERROR)
00071         {
00072                 *Consol<<"ExManagerSound:: alGenBuffers error:"<<error<<std::endl;
00073                 return ;
00074         }
00075         //Generate sources
00076         for(int i = 0; i < MAX_SOURCE ; i++)
00077         {
00078                 alGenSources(1 , &source[i]);
00079                 if ((error = alGetError()) != AL_NO_ERROR)
00080                 {
00081                         *Consol<<"ExManagerSound:: alGenSources error:"<<error<<std::endl;
00082                         return ;
00083                 }
00084         else source_available++;
00085         }
00086         m_initok=true;
00087 
00088         //LoadSound("idiot.wav");
00089 UnGuard
00090 }       

ExCAction InputAction ExCAction    Action [virtual]
 

Reimplemented from ExManager.

Definition at line 242 of file ExManagerSound.cpp.

References ExManager::Consol, Guard, InputAction(), ExManagerObject< ExCSound >::List(), LoadSound(), ExCAction::m_Action, ExCAction::m_NextAction, ExCAction::m_Param, PlaySound(), RemoveSound(), and StopSound().

Referenced by InputAction(), and ExManagerCommand::ProcesExCAction().

00243 {
00244 Guard(ExCAction ExManagerSound::InputAction(ExCAction Action))
00245         switch(Action.m_Action)
00246         {
00247         case LIST_SOUND:List(); break;
00248         case REMOVE_SOUND:RemoveSound(Action.m_Param);break;
00249         case PLAY_SOUND:PlaySound(Action.m_Param);break;
00250         case STOP_SOUND:StopSound(Action.m_Param);break;
00251         case ADD_SOUND:LoadSound(Action.m_Param);break;
00252         case SET_REPEATS_SOUND: //ManagerSound->SetRepeats(Action.m_Param);break;
00253     case GET_REPEATS_SOUND:     //ManagerSound->GetRepeats(Action.m_Param);break;
00254         
00255         default:
00256                 *Consol<<"Can not file action in SOUND_ACTION_MAP"<<std::endl;
00257                 break;
00258         }       
00259 
00260         if(Action.m_NextAction){return *Action.m_NextAction;}
00261         else{return NOTHING;}
00262 UnGuard
00263 }

ExCAction InputCommand ExCCommand    Command [virtual]
 

Reimplemented from ExManager.

Definition at line 235 of file ExManagerSound.cpp.

References Guard, and InputCommand().

Referenced by InputCommand().

00236 {
00237 Guard(ExCAction ExManagerSound::InputCommand(ExCCommand Command))
00238         return NOTHING;
00239 UnGuard
00240 }

bool LoadSound std::string   
 

Definition at line 113 of file ExManagerSound.cpp.

References ExManagerObject< ExCSound >::Add(), buffer, buffer_index, ExManager::Consol, data, error, Guard, LoadSound(), loop, ExManagerObject< ExCSound >::m_ItMap, ExManagerObject< ExCSound >::m_Map, ExCSound::SetIdent(), ExCObject::SetName(), source, and source_index.

Referenced by InputAction(), ExManagerCommand::InputAction(), ExManagerCommand::LoadSetOfFile(), and LoadSound().

00113                                               {
00114 Guard (bool ExManagerSound::LoadSound(std::string file))
00115   //We check if the file already exist
00116         //For wav file
00117         ALsizei     size,freq;
00118         ALenum      format;
00119         ALvoid      *data;
00120          bool found = false;
00121 
00122         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
00123         {
00124                 if(m_ItMap->second.GetName()==file)
00125                 {
00126                         found = true;
00127                         break;
00128                 }
00129         }
00130         if(found)
00131         {
00132                 *Consol << " ***************************************" << std::endl;
00133                 *Consol << " ** File " << file.c_str() << " already load" << std::endl;
00134                 return -1;
00135         }
00136   
00137   // Load the wav file
00138         //std::string bufferload("../Data/sound/");
00139         //bufferload+=file;
00140         //alutLoadWAVFile((ALbyte*)bufferload.c_str(),&format,&data,&size,&freq,&loop);
00141         alutLoadWAVFile((ALbyte*)file.c_str(),&format,&data,&size,&freq,&loop);
00142   *Consol << " ***************************************" << std::endl;
00143   *Consol << " ** Loading " << file.c_str() << std::endl;
00144   *Consol << " - Format " << format << std::endl;
00145   *Consol << " - Data " << data << std::endl;
00146   *Consol << " - Size " << size << std::endl;
00147   *Consol << " - Freq " << freq << std::endl;
00148   if(loop) *Consol << " - Loop ON";
00149   else *Consol << " - Loop OFF";
00150 
00151         if ((error = alGetError()) != AL_NO_ERROR)
00152         {
00153                 *Consol<<"ExManagerSound:: LoadWavFile error:"<<error<<std::endl;
00154                 return -1;
00155         }
00156   // Copy wav file into the buffer
00157         alBufferData(buffer[buffer_index],format,data,size,freq);
00158         if ((error = alGetError()) != AL_NO_ERROR)
00159         {
00160                 *Consol<<"ExManagerSound:: alBufferData error:"<<error<<std::endl;
00161                 return -1;
00162         }
00163         else
00164         {
00165                 ExCSound Sound;
00166                 Sound.SetName(file.c_str());
00167                 Sound.SetIdent(buffer_index);
00168                 Add(Sound);
00169                 *Consol << " - ident " << buffer_index << std::endl;
00170         }
00171 
00172   // Unload the wav file
00173         alutUnloadWAV(format,data,size,freq);
00174         if ((error = alGetError()) != AL_NO_ERROR)
00175         {
00176                 *Consol<<"ExManagerSound:: alutUnloadWAV error:"<<error<<std::endl;
00177                 return -1;
00178         }
00179 
00180         // Generate source for this wav file
00181         alSourcei(source[source_index],AL_BUFFER,buffer[buffer_index]);
00182         if ((error = alGetError()) != AL_NO_ERROR)
00183         {
00184                 *Consol<<"ExManagerSound:: alSourcei error:"<<error<<std::endl;
00185                 return -1;
00186         }
00187   
00188         source_index++;
00189         buffer_index++;
00190 
00191         *Consol << " ----> " << file.c_str() << " load ok :-)"  << std::endl;
00192   
00193 
00194 
00195   return true;
00196         
00197 UnGuard
00198 }

void PlaySound std::string   
 

Definition at line 200 of file ExManagerSound.cpp.

References ExManager::Consol, error, Guard, ExManagerObject< ExCSound >::m_ItMap, ExManagerObject< ExCSound >::m_Map, PlaySound(), and source.

Referenced by InputAction(), and PlaySound().

00200                                               {
00201 Guard (void ExManagerSound::PlaySound (std::string file))
00202         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
00203         {
00204                 if(m_ItMap->second.GetName()==file)
00205                 {
00206                         alSourcePlay(source[m_ItMap->second.GetIdent()]);
00207                         *Consol<<"Play sound :"<<file<<" ident:"<<m_ItMap->second.GetIdent()<<std::endl;
00208                         if ((error = alGetError()) != AL_NO_ERROR)
00209                         {
00210                                 *Consol<<"ExManagerSound:: alSourcePlay error:"<<error<<std::endl;
00211                         }
00212                         return;
00213                 }
00214         }
00215 UnGuard
00216 }

bool RemoveSound std::string   
 

Definition at line 229 of file ExManagerSound.cpp.

References Guard, and RemoveSound().

Referenced by InputAction(), and RemoveSound().

00229                                                 {
00230 Guard (bool ExManagerSound::RemoveSound (std::string file))
00231         return true;
00232 UnGuard
00233 }

void Reset void    [virtual]
 

Reimplemented from ExManagerObject< ExCSound >.

Definition at line 92 of file ExManagerSound.cpp.

References Guard, ExManagerObject::Reset(), and Reset().

Referenced by ExManagerCommand::ProcesExCAction(), and Reset().

00093 {
00094 Guard (void ExManagerSound::Reset (void))
00095         ExManagerObject<ExCSound>::Reset();
00096 UnGuard
00097 }

void StopSound std::string   
 

Definition at line 218 of file ExManagerSound.cpp.

References Guard, and StopSound().

Referenced by InputAction(), and StopSound().

00218                                               {
00219 Guard (void ExManagerSound::StopSound (std::string file))
00220 UnGuard
00221 }


Field Documentation

ALuint buffer[MAX_BUFFER] [private]
 

Definition at line 82 of file ExManagerSound.h.

Referenced by Init(), and LoadSound().

ALuint buffer_index [private]
 

Definition at line 81 of file ExManagerSound.h.

Referenced by ExManagerSound(), and LoadSound().

ALCcontext* context [private]
 

Definition at line 77 of file ExManagerSound.h.

Referenced by Init(), and ~ExManagerSound().

ALCdevice* device [private]
 

Definition at line 78 of file ExManagerSound.h.

Referenced by Init().

ALint error [private]
 

Definition at line 83 of file ExManagerSound.h.

Referenced by Init(), LoadSound(), and PlaySound().

ALboolean loop [private]
 

Definition at line 86 of file ExManagerSound.h.

Referenced by LoadSound().

bool m_flag = false [static, private]
 

Definition at line 26 of file ExManagerSound.cpp.

Referenced by CreateSingleton().

bool m_initok [private]
 

Definition at line 76 of file ExManagerSound.h.

Referenced by DisplayAviableInput(), ExManagerSound(), and Init().

ExManagerSound * m_instance = NULL [static, private]
 

Definition at line 27 of file ExManagerSound.cpp.

Referenced by CreateSingleton().

ALuint source[64] [private]
 

Definition at line 89 of file ExManagerSound.h.

Referenced by Init(), LoadSound(), and PlaySound().

ALuint source_available [private]
 

Definition at line 88 of file ExManagerSound.h.

Referenced by ExManagerSound(), and Init().

ALuint source_index [private]
 

Definition at line 87 of file ExManagerSound.h.

Referenced by ExManagerSound(), and LoadSound().


The documentation for this class was generated from the following files:
Generated on Tue Dec 10 18:20:44 2002 for ExNihilo by doxygen1.3-rc1