| 287 | } |
| 288 | |
| 289 | static Result ResetDevice(SoundSystem* sound) |
| 290 | { |
| 291 | if (!sound->m_DeviceType) |
| 292 | { |
| 293 | return RESULT_DEVICE_NOT_FOUND; |
| 294 | } |
| 295 | |
| 296 | if (sound->m_Device) |
| 297 | { |
| 298 | if (sound->m_IsDeviceStarted) |
| 299 | { |
| 300 | sound->m_DeviceType->m_DeviceStop(sound->m_Device); |
| 301 | sound->m_IsDeviceStarted = false; |
| 302 | } |
| 303 | sound->m_DeviceType->m_Close(sound->m_Device); |
| 304 | sound->m_Device = 0; |
| 305 | } |
| 306 | |
| 307 | HDevice new_device = 0; |
| 308 | Result result = sound->m_DeviceType->m_Open(&sound->m_DeviceParams, &new_device); |
| 309 | if (result != RESULT_OK) |
| 310 | { |
| 311 | dmLogError("Failed to reopen audio device"); |
| 312 | return result; |
| 313 | } |
| 314 | |
| 315 | sound->m_Device = new_device; |
| 316 | |
| 317 | DeviceInfo device_info = {0}; |
| 318 | sound->m_DeviceType->m_DeviceInfo(sound->m_Device, &device_info); |
| 319 | |
| 320 | if (device_info.m_FrameCount && device_info.m_FrameCount != sound->m_DeviceFrameCount) |
| 321 | { |
| 322 | dmLogWarning("Audio device reported frame count %u after reset (previous %u).", device_info.m_FrameCount, sound->m_DeviceFrameCount); |
| 323 | } |
| 324 | |
| 325 | if (device_info.m_MixRate && device_info.m_MixRate != sound->m_MixRate) |
| 326 | { |
| 327 | dmLogWarning("Audio device reported mix rate %u after reset (previous %u).", device_info.m_MixRate, sound->m_MixRate); |
| 328 | sound->m_MixRate = device_info.m_MixRate; |
| 329 | } |
| 330 | |
| 331 | sound->m_FrameCount = sound->m_DeviceFrameCount; |
| 332 | sound->m_NextOutBuffer = 0; |
| 333 | |
| 334 | return RESULT_OK; |
| 335 | } |
| 336 | |
| 337 | static float GainToScale(float gain) |
| 338 | { |