Platform_Win32_Sound.cpp
Go to the documentation of this file.00001 //*** Platform_Win32_Sound.cpp *** 00002 00003 #include "Platform_Win32_Sound.h" 00004 #include "Platform_Win32_Sound_Technology.h" 00005 #include "Platform_Win32_Sound_DSound.h" 00006 #include "Platform_Win32_Sound_WMM.h" 00007 #include "Platform_Win32_Sound_NoSound.h" 00008 #include "Platform_Win32_OS.h" 00009 00010 #define WIN32_LEAN_AND_MEAN 00011 #define VC_EXTRALEAN 00012 #include <malloc.h> 00013 00014 //*** Constructor *** 00015 00016 Platform_Win32_Sound::Platform_Win32_Sound(Platform_Win32_OS* os): 00017 windowHandle_(os->GetWindowHandle()), 00018 technology_(Technology_Undefined), 00019 technologyInstance_(0) 00020 { 00021 Platform::RegisterEventListener(this); 00022 00023 // Check commandline flags 00024 bool nosound=false; 00025 bool forcewmm=false; 00026 if (os->GetCommandLineString()) 00027 { 00028 char* cmdline=strdup(os->GetCommandLineString()); 00029 char* token=strtok(cmdline," "); 00030 while (token) 00031 { 00032 if (stricmp(token,"-nosound")==0) 00033 { 00034 nosound=true; 00035 } 00036 if (stricmp(token,"-forcewmm")==0) 00037 { 00038 forcewmm=true; 00039 } 00040 00041 token=strtok(0," "); 00042 } 00043 free(cmdline); 00044 } 00045 00046 // Choose default technology based on commandline flags 00047 if (nosound) 00048 { 00049 SetTechnology(Technology_NoSound); 00050 } 00051 else if (forcewmm) 00052 { 00053 SetTechnology(Technology_WMM); 00054 } 00055 else 00056 { 00057 SetTechnology(Technology_DSound); 00058 } 00059 } 00060 00061 00062 //*** Destructor *** 00063 00064 Platform_Win32_Sound::~Platform_Win32_Sound() 00065 { 00066 if (technologyInstance_) 00067 { 00068 delete technologyInstance_; 00069 technologyInstance_=0; 00070 technology_=Technology_Undefined; 00071 } 00072 00073 Platform::UnregisterEventListener(this); 00074 } 00075 00076 00077 //*** OnOsYield *** 00078 00079 void Platform_Win32_Sound::OnOsYield() 00080 { 00081 if (!technologyInstance_) 00082 { 00083 return; 00084 } 00085 00086 technologyInstance_->Update(); 00087 } 00088 00089 00090 //*** CreateSoundStream *** 00091 00092 Platform_Sound_SoundStream* Platform_Win32_Sound::CreateSoundStream(int channels, int frequency, int bitsPerSample, int size) 00093 { 00094 if (!technologyInstance_) 00095 { 00096 return 0; 00097 } 00098 00099 return technologyInstance_->CreateSoundStream(channels,frequency,bitsPerSample,size); 00100 } 00101 00102 00103 //*** SetTechnology *** 00104 00105 void Platform_Win32_Sound::SetTechnology(Platform_Win32_Sound::Technology technology) 00106 { 00107 if (technologyInstance_) 00108 { 00109 delete technologyInstance_; 00110 technologyInstance_=0; 00111 } 00112 00113 technology_=technology; 00114 00115 if (technology_>=Technology_Undefined) 00116 { 00117 return; 00118 } 00119 00120 switch(technology_) 00121 { 00122 case Technology_DSound: 00123 { 00124 technologyInstance_=new Platform_Win32_Sound_DSound(windowHandle_); 00125 } break; 00126 00127 case Technology_WMM: 00128 { 00129 technologyInstance_=new Platform_Win32_Sound_WMM(); 00130 } break; 00131 case Technology_NoSound: 00132 { 00133 technologyInstance_=new Platform_Win32_Sound_NoSound(); 00134 } break; 00135 } 00136 00137 if (!technologyInstance_->Setup()) 00138 { 00139 DowngradeTechnology(); 00140 } 00141 } 00142 00143 00144 //*** DowngradeTechnology *** 00145 00146 void Platform_Win32_Sound::DowngradeTechnology() 00147 { 00148 Platform::GetPlatform_OS()->OutputDebugText("Method failed for technology %d, falling back on technology %d\n",technology_,technology_+1); 00149 00150 if (technologyInstance_) 00151 { 00152 delete technologyInstance_; 00153 technologyInstance_=0; 00154 } 00155 00156 Technology newTechnology=(Technology)(technology_+1); 00157 00158 if (newTechnology<Technology_Undefined) 00159 { 00160 SetTechnology(newTechnology); 00161 return; 00162 } 00163 00164 technology_=Technology_Undefined; 00165 technologyInstance_=0; 00166 } 00167 00168
Reproduction/republishing of any material on this site without permission is strictly prohibited.
