Exemplo n.º 1
0
/*
===============
idAudioBufferWIN32::Play
Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
      in the dwFlags to loop the sound
===============
*/
int idAudioBufferWIN32::Play( dword dwPriority, dword dwFlags ) {
    int hr;
    bool    bRestored;

    if( m_apDSBuffer == NULL ) {
        return -1;
	}

    // Restore the buffer if it was lost
    if( FAILED( hr = RestoreBuffer( m_apDSBuffer, &bRestored ) ) ) {
        common->Error( TEXT("RestoreBuffer"), hr );
	}

    if( bRestored ) {
        // The buffer was restored, so we need to fill it with new data
        if( FAILED( hr = FillBufferWithSound( m_apDSBuffer, false ) ) ) {
            common->Error( TEXT("FillBufferWithSound"), hr );
		}

        // Make DirectSound do pre-processing on sound effects
        Reset();
    }

    m_apDSBuffer->Play( 0, dwPriority, dwFlags );
	return 0;
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Name: CStreamingSound::Reset()
// Desc: Resets the sound so it will begin playing at the beginning
//-----------------------------------------------------------------------------
HRESULT CStreamingSound::Reset()
{
	HRESULT hr;

	if( m_apDSBuffer[0] == NULL || m_pWaveFile == NULL )
		return CO_E_NOTINITIALIZED;

	m_dwLastPlayPos     = 0;
	m_dwPlayProgress    = 0;
	m_dwNextWriteOffset = 0;
	m_bFillNextNotificationWithSilence = FALSE;

	// Restore the buffer if it was lost
	BOOL bRestored;
	if( FAILED( hr = RestoreBuffer( m_apDSBuffer[0], &bRestored ) ) )
		return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

	if( bRestored )
	{
		// The buffer was restored, so we need to fill it with new data
		if( FAILED( hr = FillBufferWithSound( m_apDSBuffer[0], FALSE ) ) )
			return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );
	}

	m_pWaveFile->ResetFile();

	return m_apDSBuffer[0]->SetCurrentPosition( 0L );
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------------
// Name: CSound::Play()
// Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
//       in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play( DWORD dwPriority, DWORD dwFlags )
{
    HRESULT hr;
    BOOL    bRestored;

    if( m_apDSBuffer == NULL )
        return CO_E_NOTINITIALIZED;

    LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer();

    if( pDSB == NULL )
        return DXTRACE_ERR( TEXT("GetFreeBuffer"), E_FAIL );

    // Restore the buffer if it was lost
    if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
        return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

    if( bRestored )
    {
        // The buffer was restored, so we need to fill it with new data
        if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
            return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );

        // Make DirectSound do pre-processing on sound effects
        Reset();
    }

    return pDSB->Play( 0, dwPriority, dwFlags );
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
// Name: CStreamingSound::HandleWaveStreamNotification()
// Desc: Handle the notification that tell us to put more wav data in the 
//       circular buffer
//-----------------------------------------------------------------------------
HRESULT CStreamingSound::HandleWaveStreamNotification()
{
    HRESULT hr;
    //DWORD   dwCurrentPlayPos;
    //DWORD   dwPlayDelta;
    //DWORD   dwBytesWrittenToBuffer;
    //VOID*   pDSLockedBuffer = NULL;
    //VOID*   pDSLockedBuffer2 = NULL;
    //DWORD   dwDSLockedBufferSize;
    //DWORD   dwDSLockedBufferSize2;

    if( m_pDSB == NULL )
        return CO_E_NOTINITIALIZED;

    // Restore the buffer if it was lost
    BOOL bRestored;
    if( FAILED( hr = RestoreBuffer( &bRestored ) ) )
        return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

    if( bRestored )
    	hr = FillBufferWithSound( TRUE );	//full it with data as it's restored
	else
		hr = FillBufferWithSound(FALSE);			// add one frame into it for play

    // The buffer was restored, so we need to fill it with new data
    if( FAILED( hr) )
        return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );

    return S_OK;
}
Exemplo n.º 5
0
void _restore_ekran1(void) {
	if( 0 != ekran1_buffer ) {
		int scr=Screen();
		Screen(1);
		RestoreBuffer(ekran1_buffer);
		Screen(scr);
	}
}
Exemplo n.º 6
0
/*
===============
idAudioBufferWIN32::Lock
===============
*/
bool idAudioBufferWIN32::Lock( void **pDSLockedBuffer, ulong *dwDSLockedBufferSize ) {
	int hr;
    // Restore the buffer if it was lost
    bool bRestored;
    if( FAILED( hr = RestoreBuffer( m_apDSBuffer, &bRestored ) ) ) {
        return false;
	}

    // Lock the DirectSound buffer
    if( FAILED( hr = m_apDSBuffer->Lock( 0, m_dwDSBufferSize, pDSLockedBuffer, dwDSLockedBufferSize, NULL, NULL, 0 ) ) ) {
        return false;
	}
	return true;
}
Exemplo n.º 7
0
/*
===============
idAudioBufferWIN32::GetCurrentPosition
===============
*/
bool idAudioBufferWIN32::GetCurrentPosition( ulong *pdwCurrentWriteCursor ) {
	int hr;

    // Make sure we have focus, and we didn't just switch in from
    // an app which had a DirectSound device
    if( FAILED( hr = RestoreBuffer( m_apDSBuffer, NULL ) ) ) {
        DXTRACE_ERR( TEXT("RestoreBuffer"), hr );
		return false;
	}

    if( FAILED( hr = m_apDSBuffer->GetCurrentPosition( NULL, pdwCurrentWriteCursor ) ) ) {
        return false;
	}
	return true;
}
Exemplo n.º 8
0
HRESULT DDuplexAudio::HandleRenderNotification(void)
{
	HRESULT hr;
	BOOL bRestored;

    if( FAILED( hr = RestoreBuffer( &bRestored ) ) )
		return hr;

	if( bRestored )
    	hr = FillBufferWithSound( TRUE );	//full it with data as it's restored
	else
		hr = FillBufferWithSound(FALSE);			// add one frame into it for play

	return hr;
}
Exemplo n.º 9
0
//-----------------------------------------------------------------------------
// Name: CSound::Play3D()
// Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
//       in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority, DWORD dwFlags, LONG lFrequency )
{
	HRESULT hr;
	BOOL    bRestored;
	DWORD   dwBaseFrequency;

	if( m_apDSBuffer == NULL )
		return CO_E_NOTINITIALIZED;

	IDirectSoundBuffer* pDSB = GetFreeBuffer();
	if( pDSB == NULL )
		return DXTRACE_ERR( TEXT("GetFreeBuffer"), E_FAIL );

	// Restore the buffer if it was lost
	if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
		return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

	if( bRestored )
	{
		// The buffer was restored, so we need to fill it with new data
		if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
			return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );
	}

	if( m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY )
	{
		pDSB->GetFrequency( &dwBaseFrequency );
		pDSB->SetFrequency( dwBaseFrequency + lFrequency );
	}

	// QI for the 3D buffer
	IDirectSound3DBuffer* pDS3DBuffer;
	hr = pDSB->QueryInterface( IID_IDirectSound3DBuffer, (VOID**) &pDS3DBuffer );
	if( SUCCEEDED( hr ) )
	{
		hr = pDS3DBuffer->SetAllParameters( p3DBuffer, DS3D_IMMEDIATE );
		if( SUCCEEDED( hr ) )
		{
			hr = pDSB->Play( 0, dwPriority, dwFlags );
		}

		pDS3DBuffer->Release();
	}

	return hr;
}
Exemplo n.º 10
0
    // ////////////////////////////////////////////////////////////////////
    //
    // ////////////////////////////////////////////////////////////////////
    HRESULT DirectSound8AudioBuffer::FillBufferWithSound(void)
    {
        HRESULT hr;
        VOID    *pDSLockedBuffer = NULL;     // a pointer to the DirectSound buffer
        DWORD   dwDSLockedBufferSize = 0;    // Size of the locked DirectSound buffer
        DWORD   dwWavDataRead        = 0;    // Amount of data read from the wav file

        if(m_Sample == NULL) {
            return (CO_E_NOTINITIALIZED);
        }

        // Make sure we have focus, and we didn't just switch in from
        // an app which had a DirectSound device
        if(FAILED(hr = RestoreBuffer(NULL))) {
            return DXUT_ERR(L"RestoreBuffer", hr);
        }

        I32 pcmBufferSize = m_Resource->GetPCMBufferSize();
        // Lock the buffer down
        if(FAILED(hr = m_Sample->Lock(0, pcmBufferSize,
                                      &pDSLockedBuffer, &dwDSLockedBufferSize,
                                      NULL, NULL, 0L))) {
            return (DXUT_ERR(L"Lock", hr));
        }

        if(pcmBufferSize == 0) {
            // Wav is blank, so just fill with silence
            FillMemory((BYTE*) pDSLockedBuffer,
                       dwDSLockedBufferSize,
                       (BYTE)(m_Resource->GetFormat()->wBitsPerSample == 8 ? 128 : 0));
        } else {
            CopyMemory(pDSLockedBuffer, m_Resource->GetPCMBuffer(), pcmBufferSize);
            if(pcmBufferSize < static_cast<I32>(dwDSLockedBufferSize)) {
                // If the buffer sizes are different fill in the rest with silence
                FillMemory((BYTE*) pDSLockedBuffer + pcmBufferSize,
                           dwDSLockedBufferSize - pcmBufferSize,
                           (BYTE)(m_Resource->GetFormat()->wBitsPerSample == 8 ? 128 : 0));
            }
        }

        // Unlock the buffer, we don't need it anymore.
        m_Sample->Unlock(pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);

        return (S_OK);
    }
Exemplo n.º 11
0
bool CN3SndObj::FillBufferWithSound(CWaveFile* pWaveFile)
{
    if( NULL == m_lpDSBuff || NULL == pWaveFile )
		return false; // 포인터들 점검..
	
    HRESULT hr; 
    VOID*   pDSLockedBuffer      = NULL; // Pointer to locked buffer memory
    DWORD   dwDSLockedBufferSize = 0;    // Size of the locked DirectSound buffer
    DWORD   dwWavDataRead        = 0;    // Amount of data read from the wav file 

	DSBCAPS dsbc; dsbc.dwSize = sizeof(dsbc);
	m_lpDSBuff->GetCaps(&dsbc);
	if(dsbc.dwBufferBytes != pWaveFile->GetSize())
		return false; // 사이즈 점검..

    if( FAILED( hr = RestoreBuffer() ) ) 
        return false;

    // Lock the buffer down
	if( FAILED( hr = m_lpDSBuff->Lock( 0, dsbc.dwBufferBytes, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, NULL, 0L ) ) )
        return false;

	pWaveFile->ResetFile();

    if( FAILED( hr = pWaveFile->Read( (BYTE*) pDSLockedBuffer, dwDSLockedBufferSize, &dwWavDataRead ) ) )
		return false;

    if( dwWavDataRead == 0 )
    {
        // Wav is blank, so just fill with silence
        FillMemory( (BYTE*) pDSLockedBuffer, dwDSLockedBufferSize, (BYTE)(pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) );
    }
    else if( dwWavDataRead < dwDSLockedBufferSize )
    {
       // just fill in silence 
        FillMemory( (BYTE*) pDSLockedBuffer + dwWavDataRead, 
                    dwDSLockedBufferSize - dwWavDataRead, 
                    (BYTE)(pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) );
    }

    // Unlock the buffer, we don't need it anymore.
    m_lpDSBuff->Unlock( pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0 );

    return true;
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
// Name: CStreamingSound::Reset()
// Desc: Resets the sound so it will begin playing at the beginning
//-----------------------------------------------------------------------------
HRESULT CStreamingSound::Reset()
{
    HRESULT hr;

    if( m_pDSB == NULL )
        return CO_E_NOTINITIALIZED;

    m_dwLastPlayPos     = 0;
    m_dwPlayProgress    = 0;
    m_dwNextWriteOffset = 0;
    //m_bFillNextNotificationWithSilence = FALSE;

    // Restore the buffer if it was lost
    BOOL bRestored;
    if( FAILED( hr = RestoreBuffer( &bRestored ) ) )
        return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

    return m_pDSB->SetCurrentPosition( 0L );  
}
Exemplo n.º 13
0
//-----------------------------------------------------------------------------
// Name: CSound::Play()
// Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
//       in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play( DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, LONG lPan )
{
    HRESULT hr;
    BOOL    bRestored;

    if( m_apDSBuffer == NULL )
        return CO_E_NOTINITIALIZED;

    LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer();

    if( pDSB == NULL )
        return DXTRACE_ERR( TEXT("GetFreeBuffer"), E_FAIL );

    // Restore the buffer if it was lost
    if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
        return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

    if( bRestored )
    {
        // The buffer was restored, so we need to fill it with new data
        if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
            return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );
    }

    if( m_dwCreationFlags & DSBCAPS_CTRLVOLUME )
    {
        pDSB->SetVolume( lVolume );
    }

    if( lFrequency != -1 && 
        (m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY) )
    {
        pDSB->SetFrequency( lFrequency );
    }
    
    if( m_dwCreationFlags & DSBCAPS_CTRLPAN )
    {
        pDSB->SetPan( lPan );
    }
    
    return pDSB->Play( 0, dwPriority, dwFlags );
}
Exemplo n.º 14
0
//-----------------------------------------------------------------------------
// Name: CDSSound::Play3D()
// Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
//       in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CDSSound::Play3D(LPDS3DBUFFER p3DBuffer, DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, DWORD& outIndex)
{
    HRESULT hr;
    BOOL    bRestored;
    DWORD   dwBaseFrequency;

    if (!m_apDSBuffer) return CO_E_NOTINITIALIZED;

    LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer(outIndex);
    if (!pDSB) return DXTRACE_ERR(TEXT("GetFreeBuffer"), E_FAIL);

    // Restore the buffer if it was lost
    if (FAILED(hr = RestoreBuffer(pDSB, &bRestored)))
        return DXTRACE_ERR(TEXT("RestoreBuffer"), hr);

    if (bRestored)
        if (FAILED(hr = FillBufferWithSound(pDSB, FALSE)))
            return DXTRACE_ERR(TEXT("FillBufferWithSound"), hr);

    if (m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY)
    {
        pDSB->GetFrequency(&dwBaseFrequency);
        pDSB->SetFrequency(dwBaseFrequency + lFrequency);
    }
    if (m_dwCreationFlags & DSBCAPS_CTRLVOLUME) pDSB->SetVolume(lVolume);

    // QI for the 3D buffer
    LPDIRECTSOUND3DBUFFER pDS3DBuffer;
    hr = pDSB->QueryInterface(IID_IDirectSound3DBuffer, (VOID**) &pDS3DBuffer);
    if (SUCCEEDED(hr))
    {
        hr = pDS3DBuffer->SetAllParameters(p3DBuffer, DS3D_IMMEDIATE);
        if (SUCCEEDED(hr))
        {
            hr = pDSB->SetCurrentPosition(0);
            hr = pDSB->Play(0, dwPriority, dwFlags);
        }
        pDS3DBuffer->Release();
    }

    return hr;
}
Exemplo n.º 15
0
//-----------------------------------------------------------------------------
// Name: CStreamingSound::Play()
// Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
//       in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CStreamingSound::Play( DWORD dwPriority, DWORD dwFlags )
{
    HRESULT hr;
    BOOL    bRestored;

    if( m_pDSB == NULL )
        return CO_E_NOTINITIALIZED;

    // Restore the buffer if it was lost
    if( FAILED( hr = RestoreBuffer( &bRestored ) ) )
        return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

    if( bRestored )
    {
        // Make DirectSound do pre-processing on sound effects
        Reset();
    }

    return m_pDSB->Play( 0, dwPriority, dwFlags );
}
Exemplo n.º 16
0
void _M_RUCH_INFO(astr A_S) {
	aint KONIEC=0;
	rysuj(); MouseClick();
																					//	   INFO:
	OKNO(90,100,158,22);										//	   OKNO[90,100,158,22]
	GADGET(OKX+4,OKY+4,150,15,"",31,2,30,1,0);//	   GADGET[OKX+4,OKY+4,150,15,"",31,2,30,1,0]
	gad_text(1.0); Text(OKX+8,OKY+15,A_S);	//	   Ink 1,30 : Text OKX+8,OKY+15,A$
	void *sb=StoreBuffer(OKX-1,OKY-1,158+2,22+2);
	do {																		//	   Repeat
		rysuj();
		RestoreBuffer(sb);
		WaitVbl();
		if( MouseClick() ) {									//	      If Mouse Click=1
			KONIEC=-1;													//	         KONIEC=True
		}																			//	      End If
	} while( KONIEC==0 );										//	   Until KONIEC
	ZOKNO();																//	   ZOKNO
	FreeBuffer(sb);
	rysuj();
	WaitVbl();
}
Exemplo n.º 17
0
    // ////////////////////////////////////////////////////////////////////
    //
    // ////////////////////////////////////////////////////////////////////
    bool DirectSound8AudioBuffer::VOnRestore()
    {
        HRESULT hr;
        BOOL bRestored;

        // Restore the buffer if it was lost
        if(FAILED(hr = RestoreBuffer(&bRestored))) {
            GF_LOG_TRACE_ERR("DirectSound8AudioBuffer::VOnRestore()", "Failed to restore the buffer");
            return (false);
        }

        if(bRestored) {
            // The buffer was restored, so we need to fill it with new data
            if(FAILED(hr = FillBufferWithSound())) {
                GF_LOG_TRACE_ERR("DirectSound8AudioBuffer::VOnRestore()", "Failed to fill the buffer with sound");
                return (false);
            }
        } else {
            GF_LOG_TRACE_ERR("DirectSound8AudioBuffer::VOnRestore()", "Failed to restore the buffer so cannot fill it with sound");
        }

        return (true);
    }
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
// Name: CSound::FillBufferWithSound()
// Desc: Fills a DirectSound buffer with a sound file 
//-----------------------------------------------------------------------------
HRESULT CSound::FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger )
{
    HRESULT hr; 
    VOID*   pDSLockedBuffer      = NULL; // Pointer to locked buffer memory
    DWORD   dwDSLockedBufferSize = 0;    // Size of the locked DirectSound buffer
    DWORD   dwWavDataRead        = 0;    // Amount of data read from the wav file 

    if( pDSB == NULL )
        return CO_E_NOTINITIALIZED;

    // Make sure we have focus, and we didn't just switch in from
    // an app which had a DirectSound device
    if( FAILED( hr = RestoreBuffer( pDSB, NULL ) ) ) 
        return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );

    // Lock the buffer down
    if( FAILED( hr = pDSB->Lock( 0, m_dwDSBufferSize, 
                                 &pDSLockedBuffer, &dwDSLockedBufferSize, 
                                 NULL, NULL, 0L ) ) )
        return DXTRACE_ERR( TEXT("Lock"), hr );

    // Reset the wave file to the beginning 
    m_pWaveFile->ResetFile();

    if( FAILED( hr = m_pWaveFile->Read( (BYTE*) pDSLockedBuffer,
                                        dwDSLockedBufferSize, 
                                        &dwWavDataRead ) ) )           
        return DXTRACE_ERR( TEXT("Read"), hr );

    if( dwWavDataRead == 0 )
    {
        // Wav is blank, so just fill with silence
        FillMemory( (BYTE*) pDSLockedBuffer, 
                    dwDSLockedBufferSize, 
                    (BYTE)(m_pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) );
    }
    else if( dwWavDataRead < dwDSLockedBufferSize )
    {
        // If the wav file was smaller than the DirectSound buffer, 
        // we need to fill the remainder of the buffer with data 
        if( bRepeatWavIfBufferLarger )
        {       
            // Reset the file and fill the buffer with wav data
            DWORD dwReadSoFar = dwWavDataRead;    // From previous call above.
            while( dwReadSoFar < dwDSLockedBufferSize )
            {  
                // This will keep reading in until the buffer is full 
                // for very short files
                if( FAILED( hr = m_pWaveFile->ResetFile() ) )
                    return DXTRACE_ERR( TEXT("ResetFile"), hr );

                hr = m_pWaveFile->Read( (BYTE*)pDSLockedBuffer + dwReadSoFar,
                                        dwDSLockedBufferSize - dwReadSoFar,
                                        &dwWavDataRead );
                if( FAILED(hr) )
                    return DXTRACE_ERR( TEXT("Read"), hr );

                dwReadSoFar += dwWavDataRead;
            } 
        }
        else
        {
            // Don't repeat the wav file, just fill in silence 
            FillMemory( (BYTE*) pDSLockedBuffer + dwWavDataRead, 
                        dwDSLockedBufferSize - dwWavDataRead, 
                        (BYTE)(m_pWaveFile->m_pwfx->wBitsPerSample == 8 ? 128 : 0 ) );
        }
    }

    // Unlock the buffer, we don't need it anymore.
    pDSB->Unlock( pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0 );

    return S_OK;
}
Exemplo n.º 19
0
/*
===============
idAudioBufferWIN32::FillBufferWithSound
===============
*/
int idAudioBufferWIN32::FillBufferWithSound(LPDIRECTSOUNDBUFFER pDSB, bool bRepeatWavIfBufferLarger)
{
	int hr;
	void   *pDSLockedBuffer      = NULL; // Pointer to locked buffer memory
	ulong   dwDSLockedBufferSize = 0;    // Size of the locked DirectSound buffer
	int		dwWavDataRead        = 0;    // Amount of data read from the wav file

	if (pDSB == NULL)
		return -1;

	// we may not even have a wavefile
	if (m_pWaveFile==NULL) {
		return -1;
	}

	// Make sure we have focus, and we didn't just switch in from
	// an app which had a DirectSound device
	if (FAILED(hr = RestoreBuffer(pDSB, NULL))) {
		DXTRACE_ERR(TEXT("RestoreBuffer"), hr);
		return -1;
	}

	// Lock the buffer down
	if (FAILED(hr = pDSB->Lock(0, m_dwDSBufferSize, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, NULL, 0L))) {
		DXTRACE_ERR(TEXT("Lock"), hr);
		return -1;
	}

	// Reset the wave file to the beginning
	m_pWaveFile->ResetFile();

	if (FAILED(hr = m_pWaveFile->Read((byte *) pDSLockedBuffer, dwDSLockedBufferSize, &dwWavDataRead))) {
		return DXTRACE_ERR(TEXT("Read"), hr);
	}

	if (dwWavDataRead == 0) {
		// Wav is blank, so just fill with silence
		memset(pDSLockedBuffer, (byte)(m_pWaveFile->mpwfx.Format.wBitsPerSample == 8 ? 128 : 0), dwDSLockedBufferSize);
	}  else if (dwWavDataRead < (int)dwDSLockedBufferSize) {
		// If the wav file was smaller than the DirectSound buffer,
		// we need to fill the remainder of the buffer with data
		if (bRepeatWavIfBufferLarger) {
			// Reset the file and fill the buffer with wav data
			int dwReadSoFar = dwWavDataRead;    // From previous call above.

			while (dwReadSoFar < (int)dwDSLockedBufferSize) {
				// This will keep reading in until the buffer is full
				// for very short files
				if (FAILED(hr = m_pWaveFile->ResetFile())) {
					return DXTRACE_ERR(TEXT("ResetFile"), hr);
				}

				hr = m_pWaveFile->Read((byte *)pDSLockedBuffer + dwReadSoFar, dwDSLockedBufferSize - dwReadSoFar, &dwWavDataRead);

				if (FAILED(hr)) {
					return DXTRACE_ERR(TEXT("Read"), hr);
				}

				dwReadSoFar += dwWavDataRead;
			}
		} else {
			// Don't repeat the wav file, just fill in silence
			memset((byte *) pDSLockedBuffer + dwWavDataRead, (byte)(m_pWaveFile->mpwfx.Format.wBitsPerSample == 8 ? 128 : 0), dwDSLockedBufferSize - dwWavDataRead);
		}
	}

	// Unlock the buffer, we don't need it anymore.
	pDSB->Unlock(pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);

	return S_OK;
}
Exemplo n.º 20
0
//-----------------------------------------------------------------------------
// Name: CDSStreamingSound::HandleWaveStreamNotification()
// Desc: Handle the notification that tells us to put more wav data in the
//       circular buffer
//-----------------------------------------------------------------------------
HRESULT CDSStreamingSound::HandleWaveStreamNotification(BOOL bLoopedPlay)
{
	if (!m_apDSBuffer || !m_pWaveFile) return CO_E_NOTINITIALIZED;

	HRESULT hr;
	DWORD   dwCurrentPlayPos;
	DWORD   dwPlayDelta;
	DWORD   dwBytesWrittenToBuffer;
	VOID*   pDSLockedBuffer = NULL;
	VOID*   pDSLockedBuffer2 = NULL;
	DWORD   dwDSLockedBufferSize;
	DWORD   dwDSLockedBufferSize2;

    // Restore the buffer if it was lost
    BOOL bRestored;
    if (FAILED(hr = RestoreBuffer(m_apDSBuffer[0], &bRestored)))
        return DXTRACE_ERR(TEXT("RestoreBuffer"), hr);

    if (bRestored)
    {
        // The buffer was restored, so we need to fill it with new data
        if (FAILED(hr = FillBufferWithSound(m_apDSBuffer[0], FALSE)))
            return DXTRACE_ERR(TEXT("FillBufferWithSound"), hr);
        return S_OK;
    }

    // Lock the DirectSound buffer
    if (FAILED(hr = m_apDSBuffer[0]->Lock(m_dwNextWriteOffset, m_dwNotifySize,
                                          &pDSLockedBuffer, &dwDSLockedBufferSize,
                                          &pDSLockedBuffer2, &dwDSLockedBufferSize2, 0L)))
        return DXTRACE_ERR(TEXT("Lock"), hr);

    // m_dwDSBufferSize and m_dwNextWriteOffset are both multiples of m_dwNotifySize,
    // it should the second buffer, so it should never be valid
    if (pDSLockedBuffer2) return E_UNEXPECTED;

	WORD BitsPerSample = m_pWaveFile->GetFormat()->wBitsPerSample;
    if (!m_bFillNextNotificationWithSilence)
    {
        dwBytesWrittenToBuffer = m_pWaveFile->Read((char*) pDSLockedBuffer, dwDSLockedBufferSize);
    }
    else
    {
        // Fill the DirectSound buffer with silence
        this->stopCount++;
        FillMemory(pDSLockedBuffer, dwDSLockedBufferSize,
                   (BYTE)(BitsPerSample == 8 ? 128 : 0));
        dwBytesWrittenToBuffer = dwDSLockedBufferSize;
    }

    // If the number of bytes written is less than the
    // amount we requested, we have a short file.
    if (dwBytesWrittenToBuffer < dwDSLockedBufferSize)
    {
        if (!bLoopedPlay)
        {
            // Fill in silence for the rest of the buffer.
            FillMemory((BYTE*) pDSLockedBuffer + dwBytesWrittenToBuffer,
                       dwDSLockedBufferSize - dwBytesWrittenToBuffer,
                       (BYTE)(BitsPerSample == 8 ? 128 : 0));

            // Any future notifications should just fill the buffer with silence
            m_bFillNextNotificationWithSilence = TRUE;
        }
        else
        {
            // We are looping, so reset the file and fill the buffer with wav data
            DWORD dwReadSoFar = dwBytesWrittenToBuffer;    // From previous call above.
            while (dwReadSoFar < dwDSLockedBufferSize)
            {
                // This will keep reading in until the buffer is full (for very short files).
                m_pWaveFile->Reset();
                dwBytesWrittenToBuffer = m_pWaveFile->Read((char*)pDSLockedBuffer + dwReadSoFar,
                                                           dwDSLockedBufferSize - dwReadSoFar);
                n_assert(dwBytesWrittenToBuffer > 0);
                dwReadSoFar += dwBytesWrittenToBuffer;
            }
        }
    }

    // Unlock the DirectSound buffer
    m_apDSBuffer[0]->Unlock(pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);

    // Figure out how much data has been played so far.  When we have played
    // past the end of the file, we will either need to start filling the
    // buffer with silence or starting reading from the beginning of the file,
    // depending if the user wants to loop the sound
    if (FAILED(hr = m_apDSBuffer[0]->GetCurrentPosition(&dwCurrentPlayPos, NULL)))
        return DXTRACE_ERR(TEXT("GetCurrentPosition"), hr);

    // Check to see if the position counter looped
    if (dwCurrentPlayPos < m_dwLastPlayPos)
        dwPlayDelta = (m_dwDSBufferSize - m_dwLastPlayPos) + dwCurrentPlayPos;
    else
        dwPlayDelta = dwCurrentPlayPos - m_dwLastPlayPos;

    m_dwPlayProgress += dwPlayDelta;
    m_dwLastPlayPos = dwCurrentPlayPos;

    // If we are now filling the buffer with silence, then we have found the end so
    // check to see if the entire sound has played, if it has then stop the buffer.
    if (m_bFillNextNotificationWithSilence)
    {
        // We don't want to cut off the sound before it's done playing.
        if (m_dwPlayProgress >= (DWORD)m_pWaveFile->GetSize())
            m_apDSBuffer[0]->Stop();
    }

    // Update where the buffer will lock (for next time)
    m_dwNextWriteOffset += dwDSLockedBufferSize;
    m_dwTriggerWriteOffset = m_dwNextWriteOffset - m_dwNotifySize;
    m_dwNextWriteOffset %= m_dwDSBufferSize; // Circular buffer
    m_dwTriggerWriteOffset %= m_dwDSBufferSize;

    return S_OK;
}
Exemplo n.º 21
0
void _ARMIA(aint A) {
	//	Procedure ARMIA[A]

	aint AX=0,AY=0,PL=0,KONIEC=0,TEREN=0,I=0,DANE=0;
	aint STREFA=0,KONIEC2=0,STREFA2=0,TER2=0;

	_rysuj_armia_nr = A;

	AX=ARMIA[A][0][TX];											//	   AX=ARMIA(A,0,TX)
	AY=ARMIA[A][0][TY];											//	   AY=ARMIA(A,0,TY)
	PL=ARMIA[A][0][TMAG];										//	   PL=ARMIA(A,0,TMAG)
	if( PREFS[5]==1 ) {
		WJAZD(AX,AY,80,80,150,100,4);					//	   If PREFS(5)=1 : WJAZD[AX,AY,80,80,150,100,4] : End If
	}

	if( A<20 ) {
		DANE=-1;
	} else {
		if( ARMIA[A][0][TMAGMA]==0 || ARMIA[A][0][TMAGMA]==100 ) {
			DANE=-1;
		}
	}

	if( DANE!=0 ) {
		TEREN=ARMIA[A][0][TNOGI];
		AX=ARMIA[A][0][TX];
		AY=ARMIA[A][0][TY];
	}

	rysuj();
	_ARMIA_RYSUJ_INFO(A);

	void *sb=0, *sb2=0;
	sb = StoreBuffer(OKX-1,OKY-1,150+2,100+2);

	do {																		//	   Repeat
		rysuj();
		RestoreBuffer(sb);
		WaitVbl();
		if( MouseClick() ) {									//	      If Mouse Click=1
			STREFA=MouseZone();									//	         STREFA=Mouse Zone
			if( STREFA==1 || STREFA==0 ) {			//	         If STREFA=1 or STREFA=0
				KONIEC=-1;												//	            KONIEC=True
				ZOKNO();													//	            ZOKNO
			}																		//	         End If
			if( STREFA==11 ) {									//	         If STREFA=11
				//WPISZ(OKX+50,OKY+15,1,30,14,0);			//	            WPISZ[OKX+50,OKY+15,1,30,14]

				_rysuj_tlo_armia = rysuj_ekran_ptr;
				rysuj_ekran_ptr = _rysuj_armia;
				WPISZ_PC(OKX+50,OKY+15-TextBase(),100,10,14,ARMIA_S[A][0],2);	//rysuj tylko tlo i kursor
				rysuj_ekran_ptr = _rysuj_tlo_armia;
				sb = StoreBuffer(OKX-1,OKY-1,150+2,100+2);

				ARMIA_S[A][0]=WPI_S;							//	            ARMIA$(A,0)=WPI$
			}																		//	         End If
			if( STREFA==10 && A<20 ) {					//	         If STREFA=10 and A<20
				ZOKNO();													//	            ZOKNO
				KONIEC=-1;												//	            KONIEC=True
				rysuj();
				_ARMIA_RYSUJ_ROZKAZY(A);					//	            Gosub RYSUJ_ROZKAZY
				sb2 = StoreBuffer(OKX-1,OKY-1,80+2,150+2);
				KONIEC2=0;												//	            KONIEC2=False
				do {															//	            Repeat
					rysuj();
					RestoreBuffer(sb2);
					WaitVbl();
					if( MouseClick() ) {						//	               If Mouse Click=1
						STREFA2=MouseZone();					//	                  STREFA2=Mouse Zone
						if( STREFA2>0 && STREFA2<4 ) {//	                  If STREFA2>0 and STREFA2<4
							ZOKNO();										//	                     ZOKNO
							M_RUCH(A,STREFA2);					//	                     M_RUCH[A,STREFA2]
							KONIEC2=-1; KONIEC=-1;			//	                     KONIEC2=True : KONIEC=True
						}															//	                  End If
						if( STREFA2==4 && TEREN<70 ) {//	                  If STREFA2=4 and TEREN<70
							ZOKNO();										//	                     ZOKNO
							ARMIA[A][0][TTRYB]=4;				//	                     ARMIA(A,0,TTRYB)=4
							KONIEC2=-1; KONIEC=-1;			//	                     KONIEC=True : KONIEC2=True
						}															//	                  End If
						if( STREFA2==4 && TEREN>69 ) {//	                  If STREFA2=4 and TEREN>69
							if( MIASTA[TEREN-70][0][M_CZYJE]==1 ) {//	                     If MIASTA(TEREN-70,0,M_CZYJE)=1
								ZOKNO();									//	                        ZOKNO
								ARMIA[A][0][TTRYB]=0;			//	                        ARMIA(A,0,TTRYB)=0
								REKRUTACJA(10,TEREN-70,A);//	                        REKRUTACJA[10,TEREN-70,A]
								_ARMIA_RYSUJ_ROZKAZY(A);		//	                        Gosub RYSUJ_ROZKAZY
							}														//	                     End If
						}															//	                  End If
																					//
						if( STREFA2==6 ) {						//	                  If STREFA2=6
							ZOKNO();										//	                     ZOKNO
							SpriteOnOff(2,false);				//	                     Sprite Off 2
																					//	                     'Auto View Off
							_LOAD(KAT_S+"dane/gad","dane:gad","Dane",1);	//	                     _LOAD[KAT$+"dane/gad","dane:gad","Dane",1]
							ScreenOpen(1,320,160,32,LOWRES);//	                     Screen Open 1,320,160,32,Lowres
							Screen(1);									//	                     Screen 1
																					//	                     Curs Off : Flash Off
							ReserveZone(60);						//	                     Reserve Zone 60 : Get Bob Palette : Set Font FON1
							SetFont(FON1);
							GOBY=44;										//	                     GOBY=44
																					//	                     'Auto View On
							ARM=A;											//	                     ARM=A
							for(I=1;I<=10;++I) {				//	                     For I=1 To 10
								if( ARMIA[A][I][TE]>0 ) {	//	                        If ARMIA(A,I,TE)>0
									NUMER=I;								//	                           NUMER=I
									I=10;										//	                           I=10
								}													//	                        End If
							}														//	                     Next
							WYBOR(1);										//	                     WYBOR[1]
							ScreenClose(1);							//	                     Screen Close 1
							for(I=1;I<=50;++I) {				//	                     For I=1 To 50
								DelBob(GOBY+1);						//	                        Del Bob GOBY+1
							}														//	                     Next
							Screen(0);									//	                     Screen 0
							Sprite(2,SPX,SPY,1);				//	                     Sprite 2,SPX,SPY,1
							_ARMIA_RYSUJ_ROZKAZY(A);			//	                     Gosub RYSUJ_ROZKAZY
						}															//	                  End If
																					//
						if( STREFA2==8 ) {						//	                  If STREFA2=8
							KONIEC=-1;KONIEC2=-1;				//	                     KONIEC=True : KONIEC2=True
							ARMIA[A][0][TWAGA]=1;				//	                     ARMIA(A,0,TWAGA)=1
							ARM=A; WRG=40;							//	                     ARM=A : WRG=40
							SpriteOnOff(2,false);				//	                     Sprite Off 2
							SETUP(GS("070"),GS("071"),GS("072"));			//	                     SETUP["","Action",""]
							if( TEREN>69 ) {						//	                     If TEREN>69
								TER2=MIASTA[TEREN-70][1][M_X];//	                        TER2=MIASTA(TEREN-70,1,M_X)
								RYSUJ_SCENERIE(TER2,TEREN-70);//	                        RYSUJ_SCENERIE[TER2,TEREN-70]
								WRG=40;										//	                        WRG=40
																					//	                        'ustaw wieôniaków
								for(I=1;I<=7;++I) {				//	                        For I=1 To 7 : NOWA_POSTAC[40,I,9] : Next I
									NOWA_POSTAC(40,I,9);
								}
								for(I=8;I<=10;++I) {			//	                        For I=8 To 10 : NOWA_POSTAC[40,I,Rnd(8)] : Next I
									NOWA_POSTAC(40,I,Rnd(8));
								}
								for(I=1;I<=7;++I) {				//	                        For I=1 To 7 : ARMIA(40,I,TKORP)=20 : Next I
									ARMIA[40][I][TKORP]=20;
								}
								for(I=8;I<=10;++I) {			//	                        For I=8 To 10 : ARMIA(WRG,I,TKORP)=40 : Next I
									ARMIA[WRG][I][TKORP]=40;
								}
								ARMIA[40][0][TE]=10;			//	                        ARMIA(40,0,TE)=10
								USTAW_WOJSKO(WRG,1,1,1);	//	                        USTAW_WOJSKO[WRG,1,1,1]
							} else {										//	                     Else
								ARMIA[WRG][0][TE]=0;			//	                        ARMIA(WRG,0,TE)=0
								RYSUJ_SCENERIE(TEREN,-1);	//	                        RYSUJ_SCENERIE[TEREN,-1]
							}														//	                     End If
							USTAW_WOJSKO(ARM,1,1,0);		//	                     USTAW_WOJSKO[ARM,1,1,0]
							MAIN_ACTION();							//	                     MAIN_ACTION
																					//	                     'skasuj wieôniaków
							for(I=0;I<=10;++I) {				//	                     For I=0 To 10 : ARMIA(40,I,TE)=0 : Next I
								ARMIA[40][I][TE]=0;
							}
							SETUP0();										//	                     SETUP0
							VISUAL_OBJECTS();						//	                     VISUAL_OBJECTS
							CENTER(AX,AY,0);						//	                     CENTER[AX,AY,0]
							Sprite(2,SPX,SPY,1);				//	                     Sprite 2,SPX,SPY,1
						}															//	                  End If
																					//
						if( STREFA2==5 ) {						//	                  If STREFA2=5
							ZOKNO();										//	                     ZOKNO
							ARMIA[A][0][TTRYB]=0;				//	                     ARMIA(A,0,TTRYB)=0
							KONIEC=-1;KONIEC2=-1;				//	                     KONIEC=True : KONIEC2=True
						}															//	                  End If
						if( STREFA2==7 ) {						//	                  If STREFA2=7
							ZOKNO();										//	                     ZOKNO
							KONIEC2=-1;									//	                     KONIEC2=True
						}															//	                  End If
					}																//	               End If
				} while( 0==KONIEC2 );						//	            Until KONIEC2
			}																		//	         End If
			if( STREFA==10 && A>19 ) {					//	         If STREFA=10 and A>19
				if( ARMIA[A][0][TMAGMA]==0 ) {		//	            If ARMIA(A,0,TMAGMA)=0
					gad_text(1.0);									//	               Ink 31,6 : Text OKX+48,OKY+89,"@"
					Text(OKX+48,OKY+89,"@");
					ARMIA[A][0][TMAGMA]=100;				//	               ARMIA(A,0,TMAGMA)=100
					goto SKIP;											//	               Goto SKIP
				}																	//	            End If
				if( ARMIA[A][0][TMAGMA]==100 ) {	//	            If ARMIA(A,0,TMAGMA)=100
					gad_text(1.0);									//	               Gr Writing 1 : Ink 6,6
					Text(OKX+47,OKY+89,"  ");				//	               Text OKX+47,OKY+89,"  "
					ARMIA[A][0][TMAGMA]=0;					//	               ARMIA(A,0,TMAGMA)=0
				}																	//	            End If
				if( ARMIA[A][0][TMAGMA]>0 && ARMIA[A][0][TMAGMA]<100 ) {//	            If ARMIA(A,0,TMAGMA)>0 and ARMIA(A,0,TMAGMA)<100
					ZOKNO();												//	               ZOKNO
					KONIEC=-1;											//	               KONIEC=True
					SZPIEGUJ(A,1);									//	               SZPIEGUJ[A,1]
				}																	//	            End If
				SKIP:															//	            SKIP:
					;
			}																		//	         End If
		}																			//	      End If
	} while( KONIEC==0 );										//	   Until KONIEC

	FreeBuffer(sb);
	FreeBuffer(sb2);
																					//	   Goto OVER
																					//	   OVER:
																					//	End Proc
}