Beispiel #1
0
BOOL COXSound::PlayWithCallback()
	//	--- In:
	//	--- Out:
	//	--- Returns:	BOOL : TRUE if the function is successful
	//	---	Effect:		Plays a loaded WAVE asynchronously with callback notification
{
	// If playing asynchronously, there MUST be a callback
	// window to handle processing when the Wave completes.

	ASSERT((m_hCallbackWnd != NULL) && ::IsWindow(m_hCallbackWnd));

	if(!::SendMessage(m_hCallbackWnd,WM_OX_SOUNDABOUTTOPLAY,NULL,(LPARAM)this))
	{
		if(m_hWaveOut)
		{
			waveOutPause(m_hWaveOut);
			waveOutReset(m_hWaveOut);
		}

		CloseWaveOutDevice();

		if(!PrepareWaveHeader())
		{
			return FALSE;
		}

		return TRUE;
	}

	return FALSE;
}
Beispiel #2
0
void COXSound::HandleCallback()
{
	// Free up the buffer...
	FreeBuffer();

	// If looping, play it again...
	if(m_bLooping)
	{
		// Notification that we are looping again...
		if(m_hCallbackWnd != NULL)
		{
			::SendMessage(m_hCallbackWnd,WM_OX_SOUNDPLAYLOOPING,NULL,(LPARAM)this);
		}

		if(m_bIsPlaying)
		{
			PlayWithCallback();
		}
	}

	if(m_hCallbackWnd!=NULL && (!m_bLooping || !m_bIsPlaying))
	{
		CloseWaveOutDevice();

		m_bIsPlaying = FALSE;

		// If not looping, notify the callback window we have completed playback...
		::SendMessage(m_hCallbackWnd,WM_OX_SOUNDPLAYBACKCOMPLETE,NULL,(LPARAM)this);
	}
}
Beispiel #3
0
COXSound::~COXSound()
{
	Stop();
	CloseWaveOutDevice();
	FreeMem();

	// Unregister from global map
	VERIFY(m_allSoundObjects.RemoveKey(this));
}
WaveOutPulseAudio::~WaveOutPulseAudio()
{
    LOG(LOG_VERBOSE, "Going to destroy PulseAudio wave out object..");
    if (mWaveOutOpened)
    {
        LOG(LOG_VERBOSE, "..stopping wave out");
        Stop();
        LOG(LOG_VERBOSE, "..closing wave out device");
        CloseWaveOutDevice();
    }else
        LOG(LOG_VERBOSE, "Skipped CloseWaveOutDevice() because device is already closed");

    LOG(LOG_VERBOSE, "Destroyed");
}
Beispiel #5
0
void COXSound::Stop()
{
	// Stop the current sound from playing...
	if(!m_bIsPlaying)
	{
		return;
	}

	if (m_hWaveOut)
	{
		// changes were made on 10th of July: commented the next line 
		waveOutPause(m_hWaveOut);
		// and uncommented the next ones
		waveOutReset(m_hWaveOut);
		CloseWaveOutDevice();
	}
	
	// Stop playing any sound...
	PlaySound(NULL, NULL, 0);

	m_bIsPlaying = FALSE;
}
Beispiel #6
0
BOOL COXSound::PrepareWaveHeader()
	//	--- In:
	//	--- Out:
	//	--- Returns:	BOOL : TRUE if successful
	//	---	Effect:		Prepares WAVE data and header information for playback.
{
	// Internal protected call used to prepare the wave out device...

	MMRESULT mmResult = MMSYSERR_NOERROR;

	if (!m_lpWave)
	{
		return FALSE;
	}

	CloseWaveOutDevice();

	BYTE*			pbWaveData = NULL;
	LPWAVEFORMATEX	pWaveHeader = NULL;
	DWORD			dwBufferBytes = 0;

	::ZeroMemory(&m_waveFormatEx, sizeof(WAVEFORMATEX));
	m_waveFormatEx.cbSize = sizeof(WAVEFORMATEX);

	pWaveHeader = &m_waveFormatEx;

	// Parse the WAVE data...
	if(!ParseWaveData(m_lpWave,&pWaveHeader,&pbWaveData,&dwBufferBytes))
	{
		return FALSE;
	}

	if (!pbWaveData)
	{
		return FALSE;
	}

	// Save the WAVEFORMATEX header information...
	::CopyMemory(&m_waveFormatEx, pWaveHeader, sizeof(WAVEFORMATEX));

	// Open the wave output device for playback...
	mmResult = waveOutOpen(&m_hWaveOut, WAVE_MAPPER, pWaveHeader, (DWORD_PTR) &waveOutProc, (DWORD_PTR) this, CALLBACK_FUNCTION);
	m_mmLastResult = mmResult;

	if (mmResult != MMSYSERR_NOERROR)
	{
		return FALSE;
	}

	// Prepare the wave header to be written to the wave output device...
	m_lpWaveHdr=(LPWAVEHDR) GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE,sizeof(WAVEHDR));
	if (!m_lpWaveHdr)
	{
		return FALSE;
	}

	m_lpWaveData = GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE, dwBufferBytes + 1);
	if (!m_lpWaveData)
	{
		return FALSE;
	}

	// Copy the data to the global buffer...
	::CopyMemory(m_lpWaveData, pbWaveData, dwBufferBytes);

	// Set up the WAVEHDR structure...
	m_lpWaveHdr->lpData = (LPSTR) m_lpWaveData;
	m_lpWaveHdr->dwBufferLength = dwBufferBytes;
	m_lpWaveHdr->dwUser = (DWORD_PTR) this;
	m_lpWaveHdr->dwFlags = 0;
	m_lpWaveHdr->dwLoops = 0;

	mmResult = waveOutPrepareHeader(m_hWaveOut, m_lpWaveHdr, sizeof(WAVEHDR));
	m_mmLastResult = mmResult;
	if (mmResult != MMSYSERR_NOERROR)
	{
		return FALSE;
	}

	mmResult = waveOutWrite(m_hWaveOut, m_lpWaveHdr, sizeof(WAVEHDR));
	m_mmLastResult = mmResult;
	if (mmResult != MMSYSERR_NOERROR)
	{
		waveOutUnprepareHeader(m_hWaveOut, m_lpWaveHdr, sizeof(WAVEHDR));
		CloseWaveOutDevice();
		return FALSE;
	}

	m_bIsPlaying = TRUE;
	m_bIsLoaded = TRUE;

	return TRUE;
}