Platform_Win32_Sound_DSound.cpp
Go to the documentation of this file.00001 //*** Platform_Win32_Sound_DSound.cpp *** 00002 00003 #include "Platform_Win32_Sound_DSound.h" 00004 #include "Platform_Win32_Sound_SoundStream_DSound.h" 00005 #include "Platform_OS.h" 00006 00007 //#define WIN32_LEAN_AND_MEAN 00008 #define VC_EXTRALEAN 00009 00010 00011 #define DIRECTSOUND_VERSION 0x0300 00012 #include <dsound.h> 00013 00014 00015 //*** Constructor *** 00016 00017 Platform_Win32_Sound_DSound::Platform_Win32_Sound_DSound(struct HWND__* windowHandle): 00018 windowHandle_(windowHandle), 00019 dsoundDLL_(0), 00020 directSound_(0) 00021 { 00022 00023 } 00024 00025 00026 //*** Setup *** 00027 00028 bool Platform_Win32_Sound_DSound::Setup() 00029 { 00030 dsoundDLL_=LoadLibrary("dsound.dll"); 00031 00032 if (dsoundDLL_) 00033 { 00034 typedef HRESULT (WINAPI *DirectSoundCreateDefinition)(LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter); 00035 DirectSoundCreateDefinition DirectSoundCreate=(DirectSoundCreateDefinition)GetProcAddress((HMODULE)dsoundDLL_, "DirectSoundCreate"); 00036 00037 00038 HRESULT hr; 00039 hr = DirectSoundCreate(NULL, &directSound_, NULL); 00040 if (!SUCCEEDED(hr)) 00041 { 00042 Platform::GetPlatform_OS()->OutputDebugText("Couldn't create DirectSound object\n"); 00043 return false; 00044 } 00045 00046 hr = directSound_->SetCooperativeLevel(windowHandle_, /* DSSCL_EXCLUSIVE*/ DSSCL_NORMAL); 00047 if (!SUCCEEDED(hr)) 00048 { 00049 Platform::GetPlatform_OS()->OutputDebugText("Couldn't set cooperative level for DirectSound object\n"); 00050 return false; 00051 } 00052 00053 return true; 00054 } 00055 00056 Platform::GetPlatform_OS()->OutputDebugText("Couldn't load dsound.dll\n"); 00057 return false; 00058 } 00059 00060 00061 //*** Start *** 00062 00063 Platform_Win32_Sound_DSound::~Platform_Win32_Sound_DSound() 00064 { 00065 if (dsoundDLL_) 00066 { 00067 if (directSound_) 00068 { 00069 directSound_->Release(); 00070 } 00071 FreeLibrary((HMODULE)dsoundDLL_); 00072 } 00073 } 00074 00075 00076 //*** Update *** 00077 00078 void Platform_Win32_Sound_DSound::Update() 00079 { 00080 } 00081 00082 00083 //*** CreateSoundStream *** 00084 00085 Platform_Sound_SoundStream* Platform_Win32_Sound_DSound::CreateSoundStream(int channels, int frequency, int bitsPerSample, int size) 00086 { 00087 return new Platform_Win32_Sound_SoundStream_DSound(directSound_,channels,frequency,bitsPerSample,size); 00088 } 00089
Reproduction/republishing of any material on this site without permission is strictly prohibited.
