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


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

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


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

示例1: 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

示例2: 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

示例3:

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

示例4: OpenSoundFile

static LPDIRECTSOUNDBUFFER OpenSoundFile(char *name)
{
    DSBUFFERDESC DSBufDESC;
    WAVEFORMATEX waveFormat;
    void* buf;
    DWORD size;
    HMMIO hmmio;
    MMCKINFO cParent, cSub;
    LPDIRECTSOUNDBUFFER lpDSBuf = NULL;
    
    MMIOINFO mem;
    int fileSize;

    char *data = LoadFile(name, &fileSize);
    
    memset(&mem, 0, sizeof(MMIOINFO));
    mem.pchBuffer = data;
    mem.cchBuffer = fileSize;
    mem.fccIOProc = FOURCC_MEM;
    hmmio = mmioOpen(NULL, &mem, MMIO_ALLOCBUF | MMIO_READ);

    cParent.fccType = mmioFOURCC('W','A','V','E');
    if (mmioDescend(hmmio, &cParent, NULL, MMIO_FINDRIFF) != MMSYSERR_NOERROR) {
        return NULL;
    }
    cSub.ckid = mmioFOURCC('f','m','t',' ');
    if (mmioDescend(hmmio, &cSub, &cParent, MMIO_FINDCHUNK) != MMSYSERR_NOERROR) {
        goto end;
    }
    mmioRead(hmmio, (char*)&waveFormat, cSub.cksize);
    mmioAscend(hmmio, &cSub, 0);
    if (waveFormat.wFormatTag != WAVE_FORMAT_PCM) {
        goto end;
    }
    cSub.ckid = mmioFOURCC('d','a','t','a');
    if (mmioDescend(hmmio, &cSub, &cParent, MMIO_FINDCHUNK) != MMSYSERR_NOERROR) {
        goto end;
    }
    ZeroMemory(&DSBufDESC, sizeof(DSBUFFERDESC));
    DSBufDESC.dwSize = sizeof(DSBUFFERDESC);
    DSBufDESC.dwFlags = DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_GLOBALFOCUS;
    DSBufDESC.dwBufferBytes = cSub.cksize;
    DSBufDESC.lpwfxFormat = &waveFormat;
    
    lpDS->CreateSoundBuffer(&DSBufDESC, &lpDSBuf, NULL);
    lpDSBuf->Lock(0, cSub.cksize, &buf, &size, NULL, 0, 0);
    mmioRead(hmmio, (HPSTR)buf, (LONG)cSub.cksize);
    lpDSBuf->Unlock(buf, size, NULL, 0);
    mmioClose(hmmio, MMIO_FHOPEN);
    return lpDSBuf;
 end:
    mmioClose(hmmio, MMIO_FHOPEN);
    free(data);
    return NULL;
}
开发者ID:f3yagi,项目名称:mysrc,代码行数:55,代码来源:sound.cpp

示例5: 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

示例6: LoadWave

// WAVE ファイルの読み込み 
LPDIRECTSOUNDBUFFER LoadWave(char *name)
{
	char *buf;
	UINT readsize;
	WAVEFORMATEX wf;
	LPDIRECTSOUNDBUFFER lpDSB = NULL;
	DSBUFFERDESC desc;
	LPVOID pMem1,pMem2;
	DWORD size1,size2;
	// WAVE ファイルを開く

	if (!YWaveOpen(name))
	{
		return NULL;
	}
	// メモリ領域の確保
	buf = (char *)malloc(m_ckIn.cksize);
	// 読み込み
	ZeroMemory(&wf,sizeof(WAVEFORMATEX));
	if (!YWaveRead(m_ckIn.cksize,buf,&readsize,&wf))
	{
		free(buf);
		return NULL;
	}
	// サウンドバッファの作成
	ZeroMemory(&desc,sizeof(DSBUFFERDESC));
	desc.dwSize = sizeof(DSBUFFERDESC);
	desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCDEFER | DSBCAPS_CTRLVOLUME;
	desc.dwBufferBytes = readsize;
	desc.lpwfxFormat = &wf;
	if (FAILED(lpDS->CreateSoundBuffer(&desc,&lpDSB,NULL)))
	{
		free(buf);
		return NULL;
	}
	// 領域をロック
	if (FAILED(lpDSB->Lock(0,readsize,&pMem1,&size1,&pMem2,&size2,0)))
	{
		free(buf);
		return 0;
	}
	// 書き込み
	memcpy(pMem1,buf,size1);
	if (size2)
	{
		memcpy(pMem2,buf + size1,size2);
	}
	// ロック解除
	lpDSB->Unlock(pMem1,size1,pMem2,size2);
	free(buf);
	// 閉じる
	YWaveClose();
	return lpDSB;
}
开发者ID:childs-heart,项目名称:ChiruhaSyana,代码行数:55,代码来源:DsoundMain.cpp

示例7: LoopBlank

static int LoopBlank(void)
{
  void *mema=NULL,*memb=NULL;
  DWORD sizea=0,sizeb=0;

  LoopBuffer->Lock(0, LoopLen, &mema,&sizea, &memb,&sizeb, 0);
  
  if (mema) memset(mema,0,sizea);

  LoopBuffer->Unlock(mema,sizea, memb,sizeb);

  return 0;
}
开发者ID:alban-rochel,项目名称:pixbox-pcsx-rearmed,代码行数:13,代码来源:dsnd.cpp

示例8: SNDDXClearAudioBuffer

void SNDDXClearAudioBuffer()
{
	// we shouldn't need to provide 2 buffers since it's 1 contiguous range
	// but maybe newer directsound implementations have issues
	LPVOID buffer1;
	LPVOID buffer2;
	DWORD buffer1_size, buffer2_size;
	HRESULT hr = lpDSB2->Lock(0, 0, &buffer1, &buffer1_size, &buffer2, &buffer2_size, DSBLOCK_ENTIREBUFFER);
	if(FAILED(hr))
		return;
	memset(buffer1, 0, buffer1_size);
	if(buffer2)
		memset(buffer2, 0, buffer2_size);
	lpDSB2->Unlock(buffer1, buffer1_size, buffer2, buffer2_size);
}
开发者ID:BlueSplash,项目名称:svn-desmume,代码行数:15,代码来源:snddx.cpp

示例9: 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

示例10: soundmng_reset

void soundmng_reset(void) {

	LPBYTE	blockptr1;
	LPBYTE	blockptr2;
	DWORD	blocksize1;
	DWORD	blocksize2;

	if ((pDSData3) &&
		(SUCCEEDED(pDSData3->Lock(0, dsstreambytes * 2,
							(LPVOID *)&blockptr1, &blocksize1,
							(LPVOID *)&blockptr2, &blocksize2, 0)))) {
		ZeroMemory(blockptr1, blocksize1);
		if ((blockptr2 != NULL) && (blocksize2 != 0)) {
			ZeroMemory(blockptr2, blocksize2);
		}
		pDSData3->Unlock(blockptr1, blocksize1, blockptr2, blocksize2);
		pDSData3->SetCurrentPosition(0);
		dsstreamevent = (UINT8)-1;
	}
}
开发者ID:josejl1987,项目名称:neko-tracer,代码行数:20,代码来源:soundmng.cpp

示例11: WriteBuffer

void WriteBuffer(int * DestBuf, short * SrcBuf, int datalen)
{
    void * writePtr1;
    void * writePtr2;
    unsigned long length1;
    unsigned long length2;

    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) DestBuf;

    unsigned long WriteCur;

    dsBuffer->GetCurrentPosition(NULL, &WriteCur);

    dsBuffer->Lock(WriteCur, datalen, &writePtr1, &length1, &writePtr2, &length2, 0);
    memcpy(writePtr1, SrcBuf, length1);
    memcpy(writePtr2, SrcBuf + length1, length2);
    dsBuffer->Unlock(writePtr1, length1, writePtr2, length2);

    dsBuffer->SetCurrentPosition(WriteCur);
}
开发者ID:process,项目名称:Project-8,代码行数:20,代码来源:sound.cpp

示例12: CreateOutputBuffer

LPDIRECTSOUNDBUFFER SoundBuffersMG::CreateOutputBuffer(const long int BufferBytes, const long int SamplesPerSec=8000, 
													   const int BitsPerSample=32, const int Channels=1, void* pData=NULL)
	{
	DSBUFFERDESC desc;
	desc.dwSize = sizeof(DSBUFFERDESC);
	desc.dwFlags = DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME;
	desc.guid3DAlgorithm = DS3DALG_DEFAULT; 
	desc.dwBufferBytes = BufferBytes;
	desc.dwReserved = 0;

	WAVEFORMATEX waveFmt; 
	waveFmt.cbSize = sizeof(WAVEFORMATEX);
	waveFmt.nChannels = Channels;
	waveFmt.nSamplesPerSec = SamplesPerSec;
	waveFmt.wBitsPerSample = BitsPerSample;
	waveFmt.nBlockAlign = (waveFmt.nChannels*waveFmt.wBitsPerSample)/8;
	waveFmt.nAvgBytesPerSec = waveFmt.nSamplesPerSec*waveFmt.nBlockAlign;
	waveFmt.wFormatTag = WAVE_FORMAT_PCM;

	desc.lpwfxFormat = &waveFmt;

	LPDIRECTSOUNDBUFFER pStaticBuffer;	
	hr =  pDSound->CreateSoundBuffer( &desc, &pStaticBuffer,NULL);
	if( FAILED(hr) )
		return NULL;

	if( pData != NULL )
	{
		LPVOID pBufferData = NULL;
		DWORD dataSize = 0;
		pStaticBuffer->Lock(0, NULL, &pBufferData, &dataSize, NULL, NULL, DSBLOCK_ENTIREBUFFER);

		memcpy(pBufferData, (LPVOID)pData, desc.dwBufferBytes);

		pStaticBuffer->Unlock(pBufferData, desc.dwBufferBytes, NULL, NULL);
	}

	OutputBuffers.push_back(pStaticBuffer);
	
	return pStaticBuffer;
	}
开发者ID:bobxiv,项目名称:ICCore,代码行数:41,代码来源:SoundBuffers.cpp

示例13: WriteSeg

static int WriteSeg(const void *buff)
{
  void *mema=NULL,*memb=NULL;
  DWORD sizea=0,sizeb=0;
  int ret;

  // Lock the segment at 'LoopWrite' and copy the next segment in
  ret = LoopBuffer->Lock(LoopWrite, LoopSeg, &mema, &sizea, &memb, &sizeb, 0);
  if (ret != DS_OK)
    lprintf("LoopBuffer->Lock() failed: %i\n", ret);

  if (mema) memcpy(mema,buff,sizea);
//  if (memb) memcpy(memb,DSoundNext+sizea,sizeb);
  if (sizeb != 0) lprintf("sizeb is not 0! (%i)\n", sizeb);

  ret = LoopBuffer->Unlock(mema,sizea, memb, sizeb);
  if (ret != DS_OK)
    lprintf("LoopBuffer->Unlock() failed: %i\n", ret);

  return 0;
}
开发者ID:alban-rochel,项目名称:pixbox-pcsx-rearmed,代码行数:21,代码来源:dsnd.cpp

示例14: _CreateSoundBuffer

LPDIRECTSOUNDBUFFER MkSoundBuffer::_CreateSoundBuffer(LPDIRECTSOUND directSound, const WAVEFORMATEX& waveFormatEx, const MkByteArray& dataBuffer)
{
	// 사운드 버퍼 생성
	DSBUFFERDESC desc;
	::ZeroMemory(&desc, sizeof(DSBUFFERDESC));
	desc.dwSize = sizeof(DSBUFFERDESC);
	desc.dwFlags = DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN;
	desc.dwBufferBytes = dataBuffer.GetSize();
	desc.lpwfxFormat = const_cast<LPWAVEFORMATEX>(&waveFormatEx);

	LPDIRECTSOUNDBUFFER soundBuffer = NULL;
	do
	{
		if (FAILED(directSound->CreateSoundBuffer(&desc, &soundBuffer, NULL)))
			break;

		// 사운드 버퍼에 데이터 복사
		LPVOID primarySoundBuffer = NULL;
		LPVOID secondarySoundBuffer = NULL;
		DWORD primaryLength, secondaryLength;

		if (FAILED(soundBuffer->Lock(0, desc.dwBufferBytes, &primarySoundBuffer, &primaryLength, &secondarySoundBuffer, &secondaryLength, 0)))
			break;

		memcpy_s(primarySoundBuffer, primaryLength, dataBuffer.GetPtr(), primaryLength); // 순환 버퍼의 앞부분 복사
		memcpy_s(secondarySoundBuffer, secondaryLength, dataBuffer.GetPtr() + primaryLength, secondaryLength); // 순환 버퍼의 뒷부분 복사

		if (FAILED(soundBuffer->Unlock(primarySoundBuffer, primaryLength, secondarySoundBuffer, secondaryLength)))
			break;

		return soundBuffer;
	}
	while (false);

	if (soundBuffer != NULL)
	{
		soundBuffer->Release();
	}
	return NULL;
}
开发者ID:jaeseock,项目名称:MiniKey,代码行数:40,代码来源:MkSound_MkSoundBuffer.cpp

示例15: DSUtil_FillSoundBuffer

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
HRESULT DSUtil_FillSoundBuffer( LPDIRECTSOUNDBUFFER pDSB, BYTE* pbWaveData,
                                DWORD dwWaveSize )
{
    VOID* pMem1;
    VOID* pMem2;
    DWORD dwSize1;
    DWORD dwSize2;

    if( NULL == pDSB || NULL == pbWaveData || 0 == dwWaveSize )
        return E_FAIL;

    if( FAILED( pDSB->Lock( 0, dwWaveSize, &pMem1, &dwSize1, &pMem2,
                            &dwSize2, 0 ) ) )
        return E_FAIL;

    if( 0 != dwSize1 ) CopyMemory( pMem1, pbWaveData, dwSize1 );
    if( 0 != dwSize2 ) CopyMemory( pMem2, pbWaveData+dwSize1, dwSize2 );

    pDSB->Unlock( pMem1, dwSize1, pMem2, dwSize2);

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


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