00001 /* Crown and Cutlass 00002 * Sound Effect Code 00003 */ 00004 00005 #include <AL/al.h> 00006 #include "Log.h" 00007 #include "soundfile.h" 00008 #include "OpenALSource.h" 00009 #include "SoundSystem.h" 00010 #include "ISound.h" 00011 #include "ResourceManager/ResourceManager.h" 00012 #include "ResourceManager/IResource.h" 00013 #include "ResourceManager/SoundResource.h" 00014 #include "SoundEffect.h" 00015 00016 using namespace std; 00017 00018 SoundEffect::SoundEffect(string name): ISound() { 00019 m_resource = (SoundResource *) ResourceManager::s_resourceManager->Acquire(IResource::ConstructKey(SoundResource::s_type, name)); 00020 } 00021 00022 SoundEffect::~SoundEffect() { 00023 Stop(); 00024 SoundSystem::s_soundSystem->ReleaseSound(this); 00025 ResourceManager::s_resourceManager->Release(m_resource); 00026 } 00027 00028 void SoundEffect::Play() { 00029 if (m_source != NULL) { 00030 alSourcePlay(m_source->GetSource()); 00031 } else { 00032 Log::s_log->Message("Warning: SoundEffect Play without source set"); 00033 } 00034 } 00035 00036 void SoundEffect::Pause() { 00037 if (m_source != NULL) { 00038 alSourcePause(m_source->GetSource()); 00039 } 00040 } 00041 00042 void SoundEffect::Stop() { 00043 if (m_source != NULL) { 00044 alSourceStop(m_source->GetSource()); 00045 } 00046 } 00047 00048 void SoundEffect::Update(unsigned int ticks) { 00049 // Do nothing 00050 } 00051 00052 void SoundEffect::InitializeSource() { 00053 if (m_source == NULL) { 00054 Log::s_log->Message("Warning: Attempt to initialize NULL source"); 00055 return; 00056 } 00057 alSourcei(m_source->GetSource(), AL_BUFFER, m_resource->GetBuffer()); 00058 }
1.4.7