| 347 | /////////////////////////////////////////// |
| 348 | |
| 349 | bool audio_init() { |
| 350 | au_mix_temp = sk_malloc_t(float, au_mix_temp_size); |
| 351 | memset(au_mix_temp, 0, sizeof(float) * au_mix_temp_size); |
| 352 | |
| 353 | if (ma_context_init(nullptr, 0, nullptr, &au_context) != MA_SUCCESS) { |
| 354 | return false; |
| 355 | } |
| 356 | |
| 357 | #if defined(_MSC_VER) |
| 358 | if (au_default_device_out_id.wasapi[0] == '\0') { |
| 359 | HRESULT hr = isac_activate(_countof(au_active_sounds), isac_data_callback); |
| 360 | |
| 361 | if (SUCCEEDED(hr)) { |
| 362 | log_info("Using audio backend: ISAC"); |
| 363 | return true; |
| 364 | } else if (hr == E_NOT_VALID_STATE) { |
| 365 | log_diag("ISAC audio backend not available, falling back to miniaudio! It's likely the device doesn't have Windows Sonic enabled, which can be found under Settings->Sound->Device Properties->Spatial Sound."); |
| 366 | } else { |
| 367 | log_warnf("ISAC audio backend failed 0x%X, falling back to miniaudio!", hr); |
| 368 | } |
| 369 | } |
| 370 | #endif |
| 371 | |
| 372 | au_config = ma_device_config_init(ma_device_type_playback); |
| 373 | au_config.playback.format = AU_SAMPLE_FORMAT; |
| 374 | au_config.playback.channels = 2; |
| 375 | au_config.sampleRate = AU_SAMPLE_RATE; |
| 376 | au_config.dataCallback = data_callback; |
| 377 | au_config.pUserData = nullptr; |
| 378 | |
| 379 | // If we've requested a specific output device, like Oculus requires, |
| 380 | // we set that up here. |
| 381 | #if defined(SK_OS_WINDOWS) || defined(SK_OS_WINDOWS_UWP) |
| 382 | if (au_default_device_out_id.wasapi[0] != '\0') { |
| 383 | au_config.playback.pDeviceID = &au_default_device_out_id; |
| 384 | } |
| 385 | #endif |
| 386 | |
| 387 | ma_result result = ma_device_init(&au_context, &au_config, &au_device); |
| 388 | if (result != MA_SUCCESS) { |
| 389 | log_warnf("Failed to open audio playback device, '%s'.", ma_result_description(result)); |
| 390 | |
| 391 | // Make a desperate attempt to fall back to a null device. |
| 392 | ma_backend backend = ma_backend_null; |
| 393 | if (ma_context_init(&backend, 1, nullptr, &au_context) != MA_SUCCESS) { |
| 394 | return false; |
| 395 | } |
| 396 | result = ma_device_init(&au_context, &au_config, &au_device); |
| 397 | |
| 398 | // Even the null device failed, so let's stop. |
| 399 | if (result != MA_SUCCESS) { |
| 400 | log_errf("Failed to open null audio playback device, '%s'.", ma_result_description(result)); |
| 401 | return false; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | result = ma_device_start(&au_device); |
| 406 | if (result != MA_SUCCESS) { |
nothing calls this directly
no test coverage detected