| 106 | //----------------------------------------------------------------------------- |
| 107 | |
| 108 | HRESULT DSGetLock(const std::shared_ptr<SoundBuffer>& pVoice, uint32_t dwOffset, uint32_t dwBytes, |
| 109 | SHORT** ppDSLockedBuffer0, DWORD* pdwDSLockedBufferSize0, |
| 110 | SHORT** ppDSLockedBuffer1, DWORD* pdwDSLockedBufferSize1) |
| 111 | { |
| 112 | DWORD nStatus; |
| 113 | HRESULT hr = pVoice->GetStatus(&nStatus); |
| 114 | if(hr != DS_OK) |
| 115 | return hr; |
| 116 | |
| 117 | if(nStatus & DSBSTATUS_BUFFERLOST) |
| 118 | { |
| 119 | do |
| 120 | { |
| 121 | hr = pVoice->Restore(); |
| 122 | if(hr == DSERR_BUFFERLOST) |
| 123 | Sleep(10); |
| 124 | } |
| 125 | while(hr != DS_OK); |
| 126 | } |
| 127 | |
| 128 | // Get write only pointer(s) to sound buffer |
| 129 | if(dwBytes == 0) |
| 130 | { |
| 131 | if(FAILED(hr = pVoice->Lock(0, 0, |
| 132 | (void**)ppDSLockedBuffer0, pdwDSLockedBufferSize0, |
| 133 | (void**)ppDSLockedBuffer1, pdwDSLockedBufferSize1, |
| 134 | DSBLOCK_ENTIREBUFFER))) |
| 135 | return hr; |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | if(FAILED(hr = pVoice->Lock(dwOffset, dwBytes, |
| 140 | (void**)ppDSLockedBuffer0, pdwDSLockedBufferSize0, |
| 141 | (void**)ppDSLockedBuffer1, pdwDSLockedBufferSize1, |
| 142 | 0))) |
| 143 | return hr; |
| 144 | } |
| 145 | |
| 146 | return hr; |
| 147 | } |
| 148 | |
| 149 | //----------------------------------------------------------------------------- |
| 150 |
no test coverage detected