void Sound::Shutdown() { ShutdownWaveFile(&m_secondaryBuffer1); ShutdownDirectSound(); return; }
// the shutdown function releases the secondary buffer which held the .wav file audio data using the ShutdownWaveFile function. // once the other sounds are released we shutdown directsound buffer and interface. void SoundManager::Shutdown() { // release the 2ndary buffer ShutdownWaveFile(&mSecondBuffer); // release background music ShutdownWaveFile(&mBGMusic1Buffer); // shutdown the directsound api ShutdownDirectSound(); return; }
void SoundClass::Shutdown() { // Release the secondary buffer. ShutdownWaveFile(&m_secondaryBuffer1, &m_secondary3DBuffer1); // Shutdown the Direct Sound API. ShutdownDirectSound(); return; }
void SoundClass::Shutdown() { for (auto it = _waveBuffers.begin(); it != _waveBuffers.end(); ++it) { auto obj = (*it).second; if (obj) { ShutdownWaveFile(&obj); } } _waveBuffers.clear(); ShutdownWaveFile(&_secondaryBuffer1); ShutdownDirectSound(); }
/******************************************************* * WndProc * The main window procedure for the application * Inputs - application window handle - HWND message sent to the window - UINT wParam of the message being sent - WPARAM lParam of the message being sent - LPARAM * Outputs - LRESULT *********************************************************/ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { // Check for any available messages from the queue switch(message) { // The user hit the close button, close the application case WM_DESTROY: game->GameEnd(); // ShutdownDirect3D(); ShutdownDirectSound(); ShutdownDirectInput(); delete game; PostQuitMessage(0); return 0; } // Always return the message to the default window procedure for further processing return DefWindowProc(hWnd, message, wParam, lParam); }
void VDAudioOutputDirectSoundW32::ThreadRun() { if (!InitDirectSound()) { ShutdownDirectSound(); mMutex.Lock(); mbThreadInited = true; mbThreadInitSucceeded = false; mMutex.Unlock(); mUpdateEvent.signal(); return; } ThreadState threadState = kThreadStateStop; uint32 lastInitCount = 0; bool underflow = false; bool playing = false; uint32 dsStreamWritePosition = 0; if (!InitPlayback()) { ShutdownDirectSound(); mMutex.Lock(); mbThreadInited = true; mbThreadInitSucceeded = false; mMutex.Unlock(); mUpdateEvent.signal(); return; } mMutex.Lock(); mbThreadInited = true; mbThreadInitSucceeded = true; mUpdateEvent.signal(); mMutex.Unlock(); for(;;) { if (playing) mUpdateEvent.tryWait(10); else mUpdateEvent.wait(); mMutex.Lock(); threadState = (ThreadState)mThreadState; mMutex.Unlock(); if (threadState == kThreadStatePlay) { if (!underflow) { StartPlayback(); playing = true; } } else { StopPlayback(); playing = false; } if (threadState == kThreadStateExit) break; if (!playing) continue; Cursors cursors; if (!ReadCursors(cursors)) continue; uint32 level; mMutex.Lock(); level = mBufferLevel; // Compute current buffering level. sint32 bufferedLevel = mDSWriteCursor - cursors.mPlayCursor; if (bufferedLevel > (sint32)mDSBufferSizeHalf) bufferedLevel -= mDSBufferSize; else if (bufferedLevel < -(sint32)mDSBufferSizeHalf) bufferedLevel += mDSBufferSize; if (bufferedLevel < 0) { bufferedLevel = 0; mDSWriteCursor = cursors.mWriteCursor; } // Compute the stream play position. This should never go backward. If it // has, we have underflowed. uint32 newDSStreamPlayPos = dsStreamWritePosition - bufferedLevel; if (newDSStreamPlayPos < mDSStreamPlayPosition) { mDSStreamPlayPosition = dsStreamWritePosition; bufferedLevel = 0; } mDSBufferedBytes = bufferedLevel; mMutex.Unlock(); if (!level) { if (!underflow && playing) { // Check for underflow. if (!bufferedLevel) { StopPlayback(); playing = false; } } continue; } // compute how many bytes to copy uint32 toCopy = level; if (toCopy + bufferedLevel > mDSBufferSizeHalf) toCopy = mDSBufferSizeHalf - bufferedLevel; if (!toCopy) continue; // update local write position dsStreamWritePosition += toCopy; // lock and copy into DirectSound buffer const uint8 *src = mBuffer.data(); uint32 consumed = 0; while(toCopy > 0) { const uint32 tc2 = std::min<uint32>(toCopy, mBufferSize - mBufferReadOffset); const uint32 tc3 = std::min<uint32>(tc2, mDSBufferSize - mDSWriteCursor); WriteAudio(mDSWriteCursor, src + mBufferReadOffset, tc3); mBufferReadOffset += tc3; if (mBufferReadOffset >= mBufferSize) mBufferReadOffset = 0; mDSWriteCursor += tc3; if (mDSWriteCursor >= mDSBufferSize) mDSWriteCursor = 0; toCopy -= tc3; consumed += tc3; } mMutex.Lock(); mBufferLevel -= consumed; mMutex.Unlock(); // restart playback if we were in underflow state if (underflow && !playing) { underflow = false; playing = true; StartPlayback(); } mResponseEvent.signal(); } ShutdownPlayback(); ShutdownDirectSound(); }