当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECTSOUNDBUFFER::Restore方法代码示例

本文整理汇总了C++中LPDIRECTSOUNDBUFFER::Restore方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUNDBUFFER::Restore方法的具体用法?C++ LPDIRECTSOUNDBUFFER::Restore怎么用?C++ LPDIRECTSOUNDBUFFER::Restore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECTSOUNDBUFFER的用法示例。


在下文中一共展示了LPDIRECTSOUNDBUFFER::Restore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RestoreBuffer

//-----------------------------------------------------------------------------
// Name: CDSSound::RestoreBuffer()
// Desc: Restores the lost buffer. *pbWasRestored returns TRUE if the buffer was
//       restored.  It can also NULL if the information is not needed.
//-----------------------------------------------------------------------------
HRESULT CDSSound::RestoreBuffer(LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored)
{
    HRESULT hr;

    if (!pDSB) return CO_E_NOTINITIALIZED;
    if (pbWasRestored) *pbWasRestored = FALSE;

    DWORD dwStatus;
    if (FAILED(hr = pDSB->GetStatus(&dwStatus)))
        return DXTRACE_ERR(TEXT("GetStatus"), hr);

    if (dwStatus & DSBSTATUS_BUFFERLOST)
    {
        // Since the app could have just been activated, then
        // DirectSound may not be giving us control yet, so
        // the restoring the buffer may fail.
        // If it does, sleep until DirectSound gives us control.
        do
        {
            if (pDSB->Restore() == DSERR_BUFFERLOST) Sleep(10);
        }
        while ((hr = pDSB->Restore()) == DSERR_BUFFERLOST);

        if (pbWasRestored) *pbWasRestored = TRUE;

        return S_OK;
    }
    else return S_FALSE;
}
开发者ID:moltenguy1,项目名称:deusexmachina,代码行数:34,代码来源:DSUtil.cpp

示例2: DXTRACE_ERR

/*
===============
idAudioBufferWIN32::RestoreBuffer
Desc: Restores the lost buffer. *pbWasRestored returns true if the buffer was
      restored.  It can also NULL if the information is not needed.
===============
*/
int idAudioBufferWIN32::RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, bool* pbWasRestored )
{
    int hr;

    if( pDSB == NULL )
    {
        return -1;
    }
    if( pbWasRestored )
    {
        *pbWasRestored = false;
    }

    ulong dwStatus;
    if( FAILED( hr = pDSB->GetStatus( &dwStatus ) ) )
    {
        return DXTRACE_ERR( TEXT("GetStatus"), hr );
    }

    if( dwStatus & DSBSTATUS_BUFFERLOST )
    {
        // Since the app could have just been activated, then
        // DirectSound may not be giving us control yet, so
        // the restoring the buffer may fail.
        // If it does, sleep until DirectSound gives us control.
        do
        {
            hr = pDSB->Restore();
            if( hr == DSERR_BUFFERLOST )
            {
                Sleep( 10 );
            }
            hr = pDSB->Restore();
        }
        while( hr );

        if( pbWasRestored != NULL )
        {
            *pbWasRestored = true;
        }

        return S_OK;
    }
    else
    {
        return S_FALSE;
    }
}
开发者ID:revelator,项目名称:Revelator-Doom3,代码行数:55,代码来源:win_snd.cpp

示例3: streamwrite

static void streamwrite(DWORD pos) {

const SINT32	*pcm;
	HRESULT		hr;
	LPBYTE		blockptr1;
	LPBYTE		blockptr2;
	DWORD		blocksize1;
	DWORD		blocksize2;

	pcm = sound_pcmlock();
	if ((hr = pDSData3->Lock(pos, dsstreambytes,
								(LPVOID *)&blockptr1, &blocksize1,
								(LPVOID *)&blockptr2, &blocksize2, 0))
													== DSERR_BUFFERLOST) {
		pDSData3->Restore();
		hr = pDSData3->Lock(pos, dsstreambytes,
								(LPVOID *)&blockptr1, &blocksize1,
								(LPVOID *)&blockptr2, &blocksize2, 0);
	}
	if (SUCCEEDED(hr)) {
		if (pcm) {
			(*fnmix)((SINT16 *)blockptr1, pcm, blocksize1);
		}
		else {
			ZeroMemory(blockptr1, blocksize1);
		}
		pDSData3->Unlock(blockptr1, blocksize1, blockptr2, blocksize2);
	}
	sound_pcmunlock(pcm);
}
开发者ID:josejl1987,项目名称:neko-tracer,代码行数:30,代码来源:soundmng.cpp

示例4: AppMixintoPrimaryBuffer

BOOL AppMixintoPrimaryBuffer(
	APPSTREAMINFO * lpAppStreamInfo,
	LPDIRECTSOUNDBUFFER lpDsbPrimary,
	DWORD dwDataBytes,
	DWORD dwOldPos,
	LPDWORD lpdwNewPos
	){
		LPVOID lpvPtr1;
		DWORD dwBytes1;
		LPVOID lpvPtr2;
		DWORD dwBytes2;
		HRESULT hr;
		//得到写指针
		hr = lpDsbPrimary->Lock(dwOld, dwDataBytes, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
		if (DSERR_BUFFERLOST == hr)//需要重新装载并重试锁定
		{
			lpDsbPrimary->Restore();
			hr = lpDsbPrimary->Lock(dwOld, dwDataBytes, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
		}
		if (SUCCEEDED(hr)){
			CustomMixer(lpAppStreamInfo, lpvPtr1, dwBytes1);
			*lpdwNewPos = dwOldPos + dwBytes1;
			if (NULL != lpvPtr2){
				CustomMixer(lpAppStreamInfo, lpvPtr2, dwBytes2);
				*lpdwNewPos = dwBytes2;//
			}
			hr = lpDsbPrimary->Unlock(lpvPtr1, dwBytes1, lpvPtr2, dwBytes2);
			if (SUCCEEDED(hr)){
				return TRUE;
			}
		}
		return FALSE;
}
开发者ID:u-stone,项目名称:code-database,代码行数:33,代码来源:DirectSound.cpp

示例5: SNDDMA_BeginPainting

/*
==============
SNDDMA_BeginPainting

Makes sure dma.buffer is valid
===============
*/
void SNDDMA_BeginPainting( void ) {
	int		reps;
	DWORD	dwSize2;
	DWORD	*pbuf, *pbuf2;
	HRESULT	hresult;
	DWORD	dwStatus;

	if ( !pDSBuf ) {
		return;
	}

	// if the buffer was lost or stopped, restore it and/or restart it
	if ( pDSBuf->GetStatus (&dwStatus) != DS_OK ) {
		Com_Printf ("Couldn't get sound buffer status\n");
	}
	
	if (dwStatus & DSBSTATUS_BUFFERLOST)
		pDSBuf->Restore ();
	
	if (!(dwStatus & DSBSTATUS_PLAYING))
		pDSBuf->Play(0, 0, DSBPLAY_LOOPING);

	// lock the dsound buffer

	reps = 0;
	dma.buffer = NULL;

	while ((hresult = pDSBuf->Lock(0, gSndBufSize, (void **)&pbuf, &locksize, 
								   (void **)&pbuf2, &dwSize2, 0)) != DS_OK)
	{
		if (hresult != DSERR_BUFFERLOST)
		{
			Com_Printf( "SNDDMA_BeginPainting: Lock failed with error '%s'\n", DSoundError( hresult ) );
			S_Shutdown ();
			return;
		}
		else
		{
			pDSBuf->Restore( );
		}

		if (++reps > 2)
			return;
	}
	dma.buffer = (unsigned char *)pbuf;
}
开发者ID:deathsythe47,项目名称:jaMME,代码行数:53,代码来源:win_snd.cpp

示例6: GetFreeBuffer

LPDIRECTSOUNDBUFFER CSBuffer::GetFreeBuffer(VOID)
{
	DWORD Status;
	HRESULT rval;
	LPDIRECTSOUNDBUFFER Buffer;
	Status = 0;
	nBufferIdx = MAX_DUPLE_COUNT;
	if(m_lpDSB==NULL) return NULL;
	if(m_ID!=0)
	{
		Buffer=m_lpDSB[m_Current];
		rval = Buffer->GetStatus(&Status);
		nBufferIdx = m_Current;
		if(FAILED(rval)) Status = 0;
		
		if((Status & DSBSTATUS_PLAYING) == DSBSTATUS_PLAYING)
		{
			if(m_nBuffers > 1)
			{
				if (++m_Current >= m_nBuffers) 
				{
					m_Current = 0;
				}
				
				Buffer = m_lpDSB[m_Current];
				rval = Buffer->GetStatus(&Status);
				nBufferIdx = m_Current;				
				if(SUCCEEDED(rval) && (Status & DSBSTATUS_PLAYING) == DSBSTATUS_PLAYING)
				{	
					// Play중이면 소리를 멈추고 처음으로 돌린다.
/*					Buffer->Stop();
					Buffer->SetCurrentPosition(0);
					
*/				
					// Play중이면 소리를 다음 소리는 Play 하지 말것
					m_Current = m_Current==0 ? m_nBuffers-1 : m_Current-1;
					Buffer = NULL;
					nBufferIdx = MAX_DUPLE_COUNT;
				}
			}
			else 
			{
				Buffer=NULL;
				nBufferIdx = MAX_DUPLE_COUNT;
			}
		}
		
		if(Buffer && (Status & DSBSTATUS_BUFFERLOST))
			if(FAILED(Buffer->Restore()))
			{
				Buffer = NULL;
				nBufferIdx = MAX_DUPLE_COUNT;
			}
	}

	return Buffer;
}
开发者ID:KaSt,项目名称:mir2ei,代码行数:57,代码来源:SBuffer.cpp

示例7:

static void
buffer_lock_3()
{
	HRESULT		hr;

	hr = _pDSB3->Lock(0, _dwBufSize, &_LpvPtr3, &_DwBytes3, NULL, NULL, 0);
	if (hr ==DSERR_BUFFERLOST)
	{
		_pDSB3->Restore();
		_pDSB3->Lock(0, _dwBufSize, &_LpvPtr3, &_DwBytes3, NULL, NULL, 0);
	}
}
开发者ID:RetroAchievements,项目名称:RASuite,代码行数:12,代码来源:AudioOut.cpp

示例8: Play

// Play
void AudioStream::Play (long volume, int looping)
{
	if (m_pdsb) {
		// If playing, stop
		if (m_fPlaying) {
			if ( m_bIsPaused == FALSE)
			Stop_and_Rewind();
		}

		// Cue for playback if necessary
		if (!m_fCued) {
			Cue ();
		}

		if ( looping )
			m_bLooping = 1;
		else
			m_bLooping = 0;

		// Begin DirectSound playback
		HRESULT hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING);
		if (hr == DS_OK) {
			m_nTimeStarted = timer_get_milliseconds();
			Set_Volume(volume);
			// Kick off timer to service buffer
			m_timer.constructor();

			m_timer.Create (m_nBufService, m_nBufService, DWORD (this), TimerCallback);

			// Playback begun, no longer cued
			m_fPlaying = TRUE;
			m_bIsPaused = FALSE;
		}
		else {
			// If the buffer was lost, try to restore it
			if ( hr == DSERR_BUFFERLOST ) {
				hr = m_pdsb->Restore();
				if ( hr == DS_OK ) {
					hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING);
				}
				else {
					nprintf(("Sound", "Sound => Lost a buffer, tried restoring but got %s\n", get_DSERR_text(hr) ));
					Int3();	// get Alan, he wants to see this
				}
			}

			if ( hr != DS_OK ) {
				nprintf(("Sound", "Sound => Play failed with return value %s\n", get_DSERR_text(hr) ));
			}
		}
	}
}
开发者ID:NonCreature0714,项目名称:freespace2,代码行数:53,代码来源:AudioStr.cpp

示例9: DSUtil_GetFreeSoundBuffer

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
LPDIRECTSOUNDBUFFER DSUtil_GetFreeSoundBuffer( SoundObject* pSound )
{
    HRESULT hr;
    DWORD   dwStatus;

    if( NULL == pSound )
        return NULL;

    LPDIRECTSOUNDBUFFER pDSB = pSound->pdsbBuffers[pSound->dwCurrent];
    if( NULL == pDSB )
        return NULL;

    hr = pDSB->GetStatus( &dwStatus );
    if( FAILED(hr) )
        dwStatus = 0;

    if( dwStatus & DSBSTATUS_PLAYING )
    {
        if( pSound->dwNumBuffers <= 1 )
            return NULL;

        if( ++pSound->dwCurrent >= pSound->dwNumBuffers )
            pSound->dwCurrent = 0;

        pDSB = pSound->pdsbBuffers[pSound->dwCurrent];
        
        hr = pDSB->GetStatus( &dwStatus);
        if( FAILED(hr) )
            dwStatus = 0;

        if( dwStatus & DSBSTATUS_PLAYING )
        {
            pDSB->Stop();
            pDSB->SetCurrentPosition( 0 );
        }
    }

    if( dwStatus & DSBSTATUS_BUFFERLOST )
    {
        if( FAILED( pDSB->Restore() ) )
            return NULL;
            
        if( FAILED( DSUtil_FillSoundBuffer( pDSB, pSound->pbWaveData,
                                            pSound->cbWaveSize ) ) )
            return NULL;
    }

    return pDSB;
}
开发者ID:grakidov,项目名称:Render3D,代码行数:53,代码来源:dsutil.cpp

示例10: DSUtil_ReloadSoundBuffer

//-----------------------------------------------------------------------------
// Name: DSUtil_ReloadSoundBuffer()
// Desc: 
//-----------------------------------------------------------------------------
HRESULT DSUtil_ReloadSoundBuffer( LPDIRECTSOUNDBUFFER pDSB, LPCTSTR strName )
{
    BYTE* pbWaveData;
    DWORD cbWaveSize;

    if( FAILED( DSUtil_GetWaveResource( NULL, strName, NULL, &pbWaveData,
                                        &cbWaveSize ) ) )
        return E_FAIL;

    if( FAILED( pDSB->Restore() ) )
        return E_FAIL;

    if( FAILED( DSUtil_FillSoundBuffer( pDSB, pbWaveData, cbWaveSize ) ) )
        return E_FAIL;

    return S_OK;
}
开发者ID:grakidov,项目名称:Render3D,代码行数:21,代码来源:dsutil.cpp

示例11: memcpy

BOOL LC3Sound::WriteDataToBuffer(
    LPDIRECTSOUNDBUFFER lpDsb,
    DWORD dwOffset,
    LPBYTE lpbSoundData,
    DWORD dwSoundBytes)
{
    LPVOID lpvPtr1;
    DWORD dwBytes1;
    LPVOID lpvPtr2;
    DWORD dwBytes2;
    HRESULT hr;
    
	//	lpDirectSound->lpVtbl->SetCooperativeLevel( lpDirectSound, hwnd, DSSCL_EXCLUSIVE);
		
    // Obtain write pointer.
    hr = lpDsb->Lock(dwOffset, dwSoundBytes, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);

    // If we got DSERR_BUFFERLOST, restore and retry lock.
    if(DSERR_BUFFERLOST == hr) {
        lpDsb->Restore();
        hr = lpDsb->Lock(dwOffset, dwSoundBytes, &lpvPtr1,
             &dwBytes1, &lpvPtr2, &dwBytes2, 0);
    }
    if(DS_OK == hr) {
        // Write to pointers.
        memcpy(lpvPtr1, lpbSoundData, dwBytes1);
        if(NULL != lpvPtr2) {
            memcpy(lpvPtr2, lpbSoundData+dwBytes1, dwBytes2);
        }
        // Release the data back to DirectSound.
        hr = lpDsb->Unlock(lpvPtr1, dwBytes1, lpvPtr2, dwBytes2);
        if(DS_OK == hr) {
            // Success!
            return TRUE;
        }
    }
    
//		lpDirectSound->lpVtbl->SetCooperativeLevel( lpDirectSound, hwnd, DSSCL_NORMAL);
    
    // If we got here, then we failed Lock, Unlock, or Restore.
    return FALSE;
}
开发者ID:MaddTheSane,项目名称:lc3tonegenerator,代码行数:42,代码来源:SoundHandler.cpp

示例12: DS_UploadSample

/*------------------------------------------------------------------------
*
* PROTOTYPE  : BOOL static DS_UploadSample(uint16_t channel, uint32_t offset, char *buffer, uint32_t size, int mode)
*
* DESCRIPTION :  Upload a raw sample into a DSound buffer.
*
*/
static BOOL DS_UploadSample(uint16_t channel, uint32_t offset, void *buffer, uint32_t size)
{

	HRESULT  hr;
    void *lpP1 = NULL;
    ULONG  dwB1 = 0;
    void *lpP2 = NULL;
    ULONG  dwB2 = 0;
    LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[channel].pbuffer;
    if ((!pDS)||(!buffer))
    {
        return FALSE;
    }

	do
    {
		hr = pDS->Lock(offset, size, &lpP1, &dwB1, &lpP2, &dwB2, 0);
        if (hr == DSERR_BUFFERLOST)
			pDS->Restore();
    }while(hr==DSERR_BUFFERLOST);

	if (hr != DS_OK)
    {
        return FALSE;
    }
    if (lpP1)
		sysMemCpy(lpP1, buffer     , dwB1);
    if (lpP2)
		sysMemCpy(lpP2, (uint8_t*)buffer+ dwB1, dwB2);

	hr = pDS->Unlock( lpP1, dwB1, lpP2, dwB2);
    if (hr != DS_OK)
    {
        return FALSE;
    }
    return TRUE;
}
开发者ID:cbxbiker61,项目名称:nogravity,代码行数:44,代码来源:snd_ds6.cpp

示例13: write

void DirectSound::write(u16 * finalWave, int length)
{
	if(!pDirectSound) return;


	HRESULT      hr;
	DWORD        status = 0;
	DWORD        play = 0;
	LPVOID       lpvPtr1;
	DWORD        dwBytes1 = 0;
	LPVOID       lpvPtr2;
	DWORD        dwBytes2 = 0;

	if( !speedup && throttle && !gba_joybus_active) {
		hr = dsbSecondary->GetStatus(&status);
		if( status & DSBSTATUS_PLAYING ) {
			if( !soundPaused ) {
				while( true ) {
					dsbSecondary->GetCurrentPosition(&play, NULL);
					  int BufferLeft = ((soundNextPosition <= play) ?
					  play - soundNextPosition :
					  soundBufferTotalLen - soundNextPosition + play);

		          if(BufferLeft > soundBufferLen)
				  {
					if (BufferLeft > soundBufferTotalLen - (soundBufferLen * 3))
						soundBufferLow = true;
					break;
				   }
				   soundBufferLow = false;

		          if(dsbEvent) {
		            WaitForSingleObject(dsbEvent, 50);
		          }
		        }
			}
		}/* else {
		 // TODO: remove?
			 setsoundPaused(true);
		}*/
	}


	// Obtain memory address of write block.
	// This will be in two parts if the block wraps around.
	if( DSERR_BUFFERLOST == ( hr = dsbSecondary->Lock(
		soundNextPosition,
		soundBufferLen,
		&lpvPtr1,
		&dwBytes1,
		&lpvPtr2,
		&dwBytes2,
		0 ) ) ) {
			// If DSERR_BUFFERLOST is returned, restore and retry lock.
			dsbSecondary->Restore();
			hr = dsbSecondary->Lock(
				soundNextPosition,
				soundBufferLen,
				&lpvPtr1,
				&dwBytes1,
				&lpvPtr2,
				&dwBytes2,
				0 );
	}

	soundNextPosition += soundBufferLen;
	soundNextPosition = soundNextPosition % soundBufferTotalLen;

	if( SUCCEEDED( hr ) ) {
		// Write to pointers.
		CopyMemory( lpvPtr1, finalWave, dwBytes1 );
		if ( lpvPtr2 ) {
			CopyMemory( lpvPtr2, finalWave + dwBytes1, dwBytes2 );
		}

		// Release the data back to DirectSound.
		hr = dsbSecondary->Unlock( lpvPtr1, dwBytes1, lpvPtr2, dwBytes2 );
	} else {
		systemMessage( 0, _T("dsbSecondary->Lock() failed: %08x"), hr );
		return;
	}
}
开发者ID:MrSwiss,项目名称:visualboyadvance-m,代码行数:82,代码来源:DirectSound.cpp

示例14: sizeof

// playing thread
static DWORD __stdcall dsound_play_thread(void *param) {
  // primary buffer caps
  DSBCAPS caps;
  caps.dwSize = sizeof(caps);
  primary_buffer->GetCaps(&caps);

  // primary buffer format
  WAVEFORMATEX format;
  primary_buffer->GetFormat(&format, sizeof(format), NULL);

  // timer resolustion
  timeBeginPeriod(1);

  // temp buffer for vsti process
  float output_buffer[2][4096];

  // data write posision
  int write_position = 0;

  // start playing primary buffer
  primary_buffer->Play(0, 0, DSBPLAY_LOOPING);

  while (dsound_thread) {
    DWORD play_pos, write_pos;

    // get current position
    primary_buffer->GetCurrentPosition(&play_pos, &write_pos);

    // size left in buffer to write.
    int data_buffer_size = (caps.dwBufferBytes + write_position - write_pos) % caps.dwBufferBytes;

    // write buffer size
    int write_buffer_size = buffer_size * format.nBlockAlign;

    // size left in buffer
    int write_size = write_buffer_size - data_buffer_size;

    // maybe data buffer is underflowed.
    if (write_size < 0) {
      write_size = (caps.dwBufferBytes + write_pos + write_buffer_size - write_position) % caps.dwBufferBytes;
    }

    // write data at least 32 samles
    if (write_size >= 32 * format.nBlockAlign) {
      //printf("%8d, %8d, %8d, %8d, %8d\n", timeGetTime(),  (caps.dwBufferBytes + write_position + write_size - write_pos) % caps.dwBufferBytes, write_pos, write_size, write_buffer_size);

      // samples
      uint samples = write_size / format.nBlockAlign;

      if (export_rendering()) {
        memset(output_buffer[0], 0, samples * sizeof(float));
        memset(output_buffer[1], 0, samples * sizeof(float));
      } else   {
        // update
        song_update(1000.0 * (double)samples / (double)format.nSamplesPerSec);

        // call vsti process func
        vsti_update_config((float)format.nSamplesPerSec, 4096);
        vsti_process(output_buffer[0], output_buffer[1], samples);
      }

      // lock primary buffer
      void  *ptr1, *ptr2;
      DWORD size1, size2;
      HRESULT hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);

      // device lost, restore and try again
      if (DSERR_BUFFERLOST == hr) {
        primary_buffer->Restore();
        hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);
      }

      // lock succeeded
      if (SUCCEEDED(hr)) {
        float *left = output_buffer[0];
        float *right = output_buffer[1];

        uint samples1 = size1 / format.nBlockAlign;
        uint samples2 = size2 / format.nBlockAlign;

        if (ptr1) write_buffer((short *)ptr1, left, right, samples1);
        if (ptr2) write_buffer((short *)ptr2, left + samples1, right + samples1, samples2);

        hr = primary_buffer->Unlock(ptr1, size1, ptr2, size2);

        write_position = (write_position + write_size) % caps.dwBufferBytes;
      }

    } else   {
      Sleep(1);
    }
  }

  // stop sound buffer
  primary_buffer->Stop();

  // timer resolustion
  timeEndPeriod(10);

//.........这里部分代码省略.........
开发者ID:YueLinHo,项目名称:freepiano,代码行数:101,代码来源:output_dsound.cpp

示例15: soundmng_pcmload

void soundmng_pcmload(UINT num, const OEMCHAR *filename, UINT type) {

	EXTROMH				erh;
	RIFF_HEADER			riff;
	BOOL				head;
	WAVE_HEADER			whead;
	UINT				size;
	WAVE_INFOS			info;
	PCMWAVEFORMAT		pcmwf;
	DSBUFFERDESC		dsbdesc;
	LPDIRECTSOUNDBUFFER dsbuf;
	HRESULT				hr;
	LPBYTE				blockptr1;
	LPBYTE				blockptr2;
	DWORD				blocksize1;
	DWORD				blocksize2;

	if ((pDSound == NULL) || (num >= SOUND_MAXPCM)) {
		goto smpl_err1;
	}
	erh = extromio_open(filename, type);
	if (erh == NULL) {
		goto smpl_err1;
	}
	if ((extromio_read(erh, &riff, sizeof(riff)) != sizeof(riff)) ||
		(riff.sig != WAVE_SIG('R','I','F','F')) ||
		(riff.fmt != WAVE_SIG('W','A','V','E'))) {
		goto smpl_err2;
	}

	head = FALSE;
	while(1) {
		if (extromio_read(erh, &whead, sizeof(whead)) != sizeof(whead)) {
			goto smpl_err2;
		}
		size = LOADINTELDWORD(whead.size);
		if (whead.sig == WAVE_SIG('f','m','t',' ')) {
			if (size >= sizeof(info)) {
				if (extromio_read(erh, &info, sizeof(info)) != sizeof(info)) {
					goto smpl_err2;
				}
				size -= sizeof(info);
				head = TRUE;
			}
		}
		else if (whead.sig == WAVE_SIG('d','a','t','a')) {
			break;
		}
		if (size) {
			extromio_seek(erh, size, ERSEEK_CUR);
		}
	}
	if (!head) {
		goto smpl_err2;
	}
	ZeroMemory(&pcmwf, sizeof(PCMWAVEFORMAT));
	pcmwf.wf.wFormatTag = LOADINTELWORD(info.format);
	if (pcmwf.wf.wFormatTag != 1) {
		goto smpl_err2;
	}
	pcmwf.wf.nChannels = LOADINTELWORD(info.channel);
	pcmwf.wf.nSamplesPerSec = LOADINTELDWORD(info.rate);
	pcmwf.wBitsPerSample = LOADINTELWORD(info.bit);
	pcmwf.wf.nBlockAlign = LOADINTELWORD(info.block);
	pcmwf.wf.nAvgBytesPerSec = LOADINTELDWORD(info.rps);

	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
	dsbdesc.dwSize = DSBUFFERDESC_SIZE;
	dsbdesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME |
						DSBCAPS_CTRLFREQUENCY | DSBCAPS_STATIC | 
						DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
	dsbdesc.dwBufferBytes = size;
	dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf;
	if (FAILED(pDSound->CreateSoundBuffer(&dsbdesc, &dsbuf, NULL))) {
		goto smpl_err2;
	}

	hr = dsbuf->Lock(0, size, (LPVOID *)&blockptr1, &blocksize1,
								(LPVOID *)&blockptr2, &blocksize2, 0);
	if (hr == DSERR_BUFFERLOST) {
		dsbuf->Restore();
		hr = dsbuf->Lock(0, size, (LPVOID *)&blockptr1, &blocksize1,
									(LPVOID *)&blockptr2, &blocksize2, 0);
	}
	if (SUCCEEDED(hr)) {
		extromio_read(erh, blockptr1, blocksize1);
		if ((blockptr2) && (blocksize2)) {
			extromio_read(erh, blockptr2, blocksize2);
		}
		dsbuf->Unlock(blockptr1, blocksize1, blockptr2, blocksize2);
		pDSwave3[num] = dsbuf;
	}
	else {
		dsbuf->Release();
	}

smpl_err2:
	extromio_close(erh);

smpl_err1:
//.........这里部分代码省略.........
开发者ID:josejl1987,项目名称:neko-tracer,代码行数:101,代码来源:soundmng.cpp


注:本文中的LPDIRECTSOUNDBUFFER::Restore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。