| 170 | } |
| 171 | |
| 172 | bool DSInit() |
| 173 | { |
| 174 | if (g_bDSAvailable) |
| 175 | { |
| 176 | g_uDSInitRefCount++; |
| 177 | return true; // Already initialised successfully |
| 178 | } |
| 179 | |
| 180 | num_sound_devices = 0; |
| 181 | HRESULT hr = DirectSoundEnumerate((LPDSENUMCALLBACK)DSEnumProc, NULL); |
| 182 | if (FAILED(hr)) |
| 183 | { |
| 184 | if (g_fh) fprintf(g_fh, "DSEnumerate failed (%08X)\n", (uint32_t)hr); |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | if (g_fh) |
| 189 | { |
| 190 | fprintf(g_fh, "Number of sound devices = %d\n", num_sound_devices); |
| 191 | } |
| 192 | |
| 193 | bool bCreatedOK = false; |
| 194 | for (int x = 0; x < num_sound_devices; x++) |
| 195 | { |
| 196 | hr = DirectSoundCreate(&sound_device_guid[x], &g_lpDS, NULL); |
| 197 | if (SUCCEEDED(hr)) |
| 198 | { |
| 199 | if (g_fh) fprintf(g_fh, "DSCreate succeeded for sound device #%d\n", x); |
| 200 | bCreatedOK = true; |
| 201 | break; |
| 202 | } |
| 203 | |
| 204 | if (g_fh) fprintf(g_fh, "DSCreate failed for sound device #%d (%08X)\n", x, (uint32_t)hr); |
| 205 | } |
| 206 | if (!bCreatedOK) |
| 207 | { |
| 208 | if (g_fh) fprintf(g_fh, "DSCreate failed for all sound devices\n"); |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | HWND hwnd = GetFrame().g_hFrameWindow; |
| 213 | _ASSERT(hwnd); |
| 214 | hr = g_lpDS->SetCooperativeLevel(hwnd, DSSCL_NORMAL); |
| 215 | if (FAILED(hr)) |
| 216 | { |
| 217 | if (g_fh) fprintf(g_fh, "SetCooperativeLevel failed (%08X)\n", (uint32_t)hr); |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | DSCAPS DSCaps; |
| 222 | memset(&DSCaps, 0, sizeof(DSCAPS)); |
| 223 | DSCaps.dwSize = sizeof(DSCAPS); |
| 224 | hr = g_lpDS->GetCaps(&DSCaps); |
| 225 | if (FAILED(hr)) |
| 226 | { |
| 227 | if (g_fh) fprintf(g_fh, "GetCaps failed (%08X)\n", (uint32_t)hr); |
| 228 | // Not fatal: so continue... |
| 229 | } |