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


C++ LPDIRECTSOUND8::SetCooperativeLevel方法代码示例

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


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

示例1: InitDSound

static int InitDSound(HWND hWnd)
{
    HRESULT hr;
    pDirectSoundCreate8 SoundCreate;    

    dsoundDLL = LoadLibrary("dsound.dll");
    if (dsoundDLL == NULL) {
        WriteLog("not find dsound.dll");
    }
    SoundCreate = (pDirectSoundCreate8)GetProcAddress(dsoundDLL, "DirectSoundCreate8");
    hr = SoundCreate(NULL, &lpDS, NULL);
    if (FAILED(hr)) {
        goto end;
    }
    hr = lpDS->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
    if (FAILED(hr)) {
        goto end;
    }
    DSBUFFERDESC desc;
    ZeroMemory(&desc,sizeof(DSBUFFERDESC));
    desc.dwSize = sizeof(DSBUFFERDESC);
    desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
    hr = lpDS->CreateSoundBuffer(&desc, &lpDSP, NULL);
    if (FAILED(hr)) {
        goto end;
    }
    WriteLog("init sound\n");
    return 1;
 end:
    return 0;
}
开发者ID:f3yagi,项目名称:mysrc,代码行数:31,代码来源:sound.cpp

示例2: Dsoundinit

bool Dsoundinit( HWND hwnd )
{	

	// SBArrの初期化
	initSBArr();

	// DirectSound8 の作成
	if (FAILED(DirectSoundCreate8(NULL,&lpDS,NULL)))
	{
		MessageBox(NULL,"DirectSound オブジェクトの作成に失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
		return false;
	}

	// DirectSound の協調レベルを設定
	if (FAILED(lpDS->SetCooperativeLevel(hwnd,DSSCL_PRIORITY)))
	{
		MessageBox(NULL,"DirectSound の協調レベルの設定に失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
		// 閉じる
		SendMessage(hwnd,WM_CLOSE,0,0);
		return false;
	}
	// プライマリ サウンドバッファ作成
	DSBUFFERDESC desc;
	ZeroMemory(&desc,sizeof(DSBUFFERDESC));
	desc.dwSize = sizeof(DSBUFFERDESC);
	desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	if (FAILED(lpDS->CreateSoundBuffer(&desc,&lpDSP,NULL)))
	{
		MessageBox(NULL,"プライマリサウンドバッファの作成に失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
		// 閉じる
		SendMessage(hwnd,WM_CLOSE,0,0);
		return false;
	}
	//ここまでは一回行えばOKの処理

	//SEの数だけセカンダリバッファにデータ読み込み
	//読み込みファイル名をリストから読み込む

	initSBFileList();
	int nCount;

	for(nCount = 0;nCount <= SE_MAX - 1;nCount++){
		// WAVE ファイルの読み込み
//		MessageBox(NULL,SBArr[nCount].cSeFileName,"",MB_OK);

		SBArr[nCount].SB_lpDSB = LoadWave(SBArr[nCount].cSeFileName); //効果音
		if (SBArr[nCount].SB_lpDSB == NULL)
		{
			MessageBox(NULL,"ファイルの読み込みに失敗しました。","DirectSoundエラー",MB_OK | MB_ICONSTOP);
			// 閉じる
			SendMessage(hwnd,WM_CLOSE,0,0);
			return false;
		}
	}

	return true;
}
开发者ID:childs-heart,项目名称:ChiruhaSyana,代码行数:57,代码来源:DsoundMain.cpp

示例3: SNDDMA_Activate

/*
=================
SNDDMA_Activate

When we change windows we need to do this
=================
*/
void SNDDMA_Activate( void ) {
	if ( !pDS ) {
		return;
	}

	if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) )	{
		Com_Printf ("sound SetCooperativeLevel failed\n");
		SNDDMA_Shutdown ();
	}
}
开发者ID:MilitaryForces,项目名称:MilitaryForces,代码行数:17,代码来源:win_snd.c

示例4: InitSound

BOOL InitSound()
{
	DSBUFFERDESC	dsbdesc;


	if (!hWnd)
	{
		return true;
	}

	if (!lpds)
	{
		//Create DirectSound interface
		if (DirectSoundCreate8(NULL, &lpds, NULL))
		{
			Error("DirectSoundCreate8(NULL, &lpds, NULL)");
			return true;
		}

		//Set cooperative level
		if (lpds->SetCooperativeLevel(hWnd, DSSCL_NORMAL))
		{
			Error("lpds->SetCooperativeLevel(hWnd, DSSCL_NORMAL)");
			CloseSound();
			return true;
		}
	}


	//Get primary buffer and set it to run silently
	if (!lpdsbPrimary)
	{
		ZeroMemory(&dsbdesc, sizeof(dsbdesc));
		dsbdesc.dwSize = sizeof(dsbdesc);
		dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
		if (lpds->CreateSoundBuffer(&dsbdesc, &lpdsbPrimary, NULL))
		{
			Error("lpds->CreateSoundBuffer(&dsbdesc, &lpdsbPrimary, NULL)");
			CloseSound();
			return true;
		}

		if (lpdsbPrimary->Play(0, 0, DSBPLAY_LOOPING))
		{
			Error("lpdsbPrimary->Play(0, 0, DSBPLAY_LOOPING)");
			CloseSound();
			return true;
		}
	}

	Settings.SoundEnabled = true;

	return false;
}
开发者ID:torso,项目名称:gamelad,代码行数:54,代码来源:Sound.cpp

示例5: FAILED

/*******************************************************************
* initDirectSound
* Initializes DirectSound
*******************************************************************/
bool D3DUtil::initDirectSound(HWND hwnd)
{
	HRESULT hr;

	hr = DirectSoundCreate8( NULL, &g_pDS, NULL );
	if FAILED (hr)
		return false;

	// Set DirectSound cooperative level 
	hr = g_pDS->SetCooperativeLevel( hwnd, DSSCL_PRIORITY );
	if FAILED ( hr )
		return false;

	return true;
}
开发者ID:Enigma0960,项目名称:endtasks,代码行数:19,代码来源:D3DUtil.cpp

示例6: initAudio

/**
 * \brief Initialize audio service.
 *
 *  Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ee416960(v=vs.85).aspx
 */
bool Main::initAudio()
{
    LPDIRECTSOUND8 pds;
    HRESULT result = DirectSoundCreate8(NULL, &pds, NULL);
    if (result != DS_OK)
    {
        Platform::error << "DirectSoundCreate8() failed.";
        return false;
    }
    result = pds->SetCooperativeLevel(applicationWindowHandle, DSSCL_NORMAL);
    if (result != DS_OK)
    {
        return false;
    }
    return true;
}
开发者ID:csusbdt,项目名称:seng,代码行数:21,代码来源:Main.cpp

示例7: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	LPDIRECTSOUND8 lpsd;
	//DirectSound基于COM,but you do not have to initilize COM, if you don't use effective DMOs
	//HRESULT hr = DirectSoundCreate8(NULL, &lpsd, NULL);
	//if (FAILED(hr)){
	//	cout << "DirectSound Create failed" << endl;
	//	return 0;
	//}
    hr = CoInitializeEx(NULL, 0);
	if (FAILED(hRes)){
		cout << "CoInitializeEx failed" << endl;
		return 0;
	}
	hr = CoCreateInstanceEx(&CLSID_DirectSound8, 
		NULL,
		CLSTX_INPROC_SERVER,
		IID_IDirectSound8,
		(LPVOID*)&lpsd);
	if (FAILED(hr)){
		cout << "CoCreateInstanceEx failed" << endl;
		return 0;
	}
	hr = lpsd->Initialize(NULL);
	if (FAILED(hr)){
		cout << "DirectSound Device Initialize failed" << endl;
		return 0;
	}
	//不设置这个,没有声音
	hr = lpsd->SetCooperativeLevel(NULL, DSSCL_PRIORITY);
	if (FAILED(hr)){
		cout << "SetCooperativeLevel Failed" << endl;
		return 0;
	}
	DSCAPS dscaps;
	dscaps.dwSize = sizeof(DSCAPS);
	hr = lpsd->GetCaps(&dscaps);//得到设备的相关参数,这一步一般不需要做
	if (FAILED(hr)){
		cout << "GetCaps failed" << endl;
		return 0;
	}
	//创建二级缓存,这个控制声音从源到目的地, source sound can come from synthesizer,another buffer,a wav file,resource
	//CreateBaseBuffer(lpsd, );

	CoUninitialize();
	return 0;
}
开发者ID:u-stone,项目名称:code-database,代码行数:47,代码来源:DirectSound.cpp

示例8: SNDDMA_Shutdown

/*
==================
SNDDMA_Shutdown
==================
*/
void SNDDMA_Shutdown( void ) {
	Com_DPrintf( "Shutting down sound system\n" );

	if ( pDS ) {
		Com_DPrintf( "Destroying DS buffers\n" );
		if ( pDS )
		{
			Com_DPrintf( "...setting NORMAL coop level\n" );
			pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY );
		}

		if ( pDSBuf )
		{
			Com_DPrintf( "...stopping and releasing sound buffer\n" );
			pDSBuf->Stop();
			pDSBuf->Release();
		}

		// only release primary buffer if it's not also the mixing buffer we just released
		if ( pDSPBuf && ( pDSBuf != pDSPBuf ) )
		{
			Com_DPrintf( "...releasing primary buffer\n" );
			pDSPBuf->Release();
		}
		pDSBuf = NULL;
		pDSPBuf = NULL;

		dma.buffer = NULL;

		Com_DPrintf( "...releasing DS object\n" );
		pDS->Release();
	}

	if ( hInstDS ) {
		Com_DPrintf( "...freeing DSOUND.DLL\n" );
		FreeLibrary( hInstDS );
		hInstDS = NULL;
	}

	pDS = NULL;
	pDSBuf = NULL;
	pDSPBuf = NULL;
	dsound_init = false;
	memset ((void *)&dma, 0, sizeof (dma));
	CoUninitialize( );
}
开发者ID:MilitaryForces,项目名称:MilitaryForces,代码行数:51,代码来源:win_snd.c

示例9: ApplicationCreateWritePrimaryBuffer

BOOL ApplicationCreateWritePrimaryBuffer(
	LPDIRECTSOUND8 lpDirectSound, 
	LPDIRECTSOUNDBUFFER8 *lplpDsb,
	LPDWORD lpdwBufferSize,
	HWND hwnd
	){
		DSBUFFERDESC dsbdesc;
		DSBCAPS dsbcaps;
		HRESULT hr;
		WAVEFORMATEX wf;

		memset(&wf, 0, sizeof(WAVEFORMATEX));
		wf.wFormatTag = WAVE_FORMAT_PCM;
		wf.nChannels = 2;
		wf.nSamplesPerSec = 22050;
		wf.nBlockAlign = 4;
		wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
		wf.wBitsPerSample = 16;

		memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
		dsbdesc.dwSize = sizeof(DSBUFFERDESC);
		dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
		//缓存大小由声音硬件返回
		dsbdesc.dwBufferBytes = 0;
		dsbdesc.lpwfxFormat = NULL;//对于主缓存来说必须是NULL

		//得到写数据协作权限
		hr = lpDirectSound->SetCooperativeLevel(hwnd, DSSCL_WRITEPRIMARY);
		if (SUCCEEDED(hr)){
			hr = lpDirectSound->CreateSoundBuffer(&dsbdesc, lplpDsb, NULL);
			if (SUCCEEDED(hr)){
				hr = (*lplpDsb)->SetFormat(&wf);
				if (SUCCEEDED(hr)){
					dsbcaps.dwSize = sizeof(DSBCAPS);
					(*lplpDsb)->GetCaps(&dsbcaps);
					*lpdwBufferSize = dsbcaps.dwBufferBytes;
					return TRUE;
				}
			}
		}
		//失败
		*lplpDsb = NULL;
		*lpdwBufferSize = 0;
		return FALSE;
}
开发者ID:u-stone,项目名称:code-database,代码行数:45,代码来源:DirectSound.cpp

示例10: init

CString COggDlg::init(HWND hwnd,int sm)
{
	DirectSoundCreate8(NULL,&m_ds,NULL);
	if(m_ds==NULL) return _T("DirectSoundを生成できません。\nDirectX7が正常にインストールされているか確認してください。");
	if(m_ds->SetCooperativeLevel(hwnd,DSSCL_PRIORITY)!=DS_OK){
		return _T("DirectSoundの強調レベルを設定できません。\nDirectX7が正常にインストールされているか確認してください。");
	}
	hw=0;
//	ZeroMemory(&d,sizeof(d));d.dwSize=sizeof(d);HRESULT r =m_ds->GetCaps(&d);
//	if(r!=DS_OK){
//		return "DirectSoundの情報を獲得出来ません。\nDirectX7が正常にインストールされているか確認してください。";
//	}
//	if(d.dwFlags & (DSCAPS_SECONDARYSTEREO|DSCAPS_PRIMARYSTEREO |DSCAPS_PRIMARY16BIT) && d.dwFreeHwMemBytes!=0){
//		hw=DSBCAPS_LOCHARDWARE;
//	}::timeSetEvent
	m_p=NULL;
	DSBUFFERDESC dss;
	ZeroMemory(&dss,sizeof(dss));
	dss.dwSize=sizeof(dss);
//	dss.dwFlags=DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY|DSBCAPS_PRIMARYBUFFER|hw;
	dss.dwFlags=DSBCAPS_PRIMARYBUFFER;
	dss.lpwfxFormat=NULL;
	dss.dwBufferBytes=0;
	if(m_ds->CreateSoundBuffer(&dss,&m_p,NULL)!=DS_OK){
		return _T("DirectSoundのプライマリバッファを生成できません。\nDirectX7が正常にインストールされているか確認してください。");
	}
	if(m_p!=NULL){
//		//PCMWAVEFORMAT p;
		WAVEFORMATEX p;
		ZeroMemory(&p,sizeof(p));
		p.wFormatTag=WAVE_FORMAT_PCM;
		p.nChannels= wavch;
		p.nSamplesPerSec= wavbit;
		p.wBitsPerSample = wavsam;
		p.nBlockAlign = p.nChannels * p.wBitsPerSample / 8;
		p.nAvgBytesPerSec = p.nSamplesPerSec * p.nBlockAlign;
		p.cbSize = 0;
		m_p->SetFormat(&p);
	}
	//m_p->QueryInterface(IID_IDirectSound3DListener, (LPVOID*)&m_listener);
	//m_listener->SetPosition(0.0f, 0.0f, 0.0f, DS3D_IMMEDIATE);

	return _T("");
}
开发者ID:otoboku,项目名称:oggYSEDbgm,代码行数:44,代码来源:oggDlg_ds.cpp

示例11: DS_DestroyBuffers

/*
** DS_DestroyBuffers
*/
static void DS_DestroyBuffers( void )
{
	Com_Printf( "Destroying DirectSound 8 buffers\n" );
	if ( pDS )
	{
		Com_Printf( "...setting NORMAL coop level\n" );
#ifdef QDSNDCOMPILERHACK
		pDS->lpVtbl->SetCooperativeLevel( pDS, cl_hwnd, DSSCL_NORMAL );
#else
		pDS->SetCooperativeLevel(cl_hwnd, DSSCL_NORMAL);
#endif
	}

	if ( pDSBuf )
	{
		Com_Printf( "...stopping and releasing secondary buffer\n" );
#ifdef QDSNDCOMPILERHACK
		pDSBuf->lpVtbl->Stop(pDSBuf);
		pDSBuf->lpVtbl->Release(pDSBuf);
#else
		pDSBuf->Stop();
		pDSBuf->Release();
#endif
	}
	
	// only release primary buffer if it's not also the mixing buffer we just released
	if ( pDSPBuf && ( pDSBuf != pDSPBuf ) )
	{
		Com_Printf( "...releasing primary buffer\n" );
#ifdef QDSNDCOMPILERHACK
		pDSPBuf->lpVtbl->Stop(pDSPBuf);
		pDSPBuf->lpVtbl->Release(pDSPBuf);
#else
		pDSPBuf->Stop();
		pDSPBuf->Release();
#endif
	}

	pDSBuf = NULL;
	pDSPBuf = NULL;

	dma.buffer = NULL;
}
开发者ID:Jaegermeiste,项目名称:quake2_322,代码行数:46,代码来源:snd_win.c

示例12: InitDSound

void InitDSound()
{
    int seconds = 1;

    DirectSoundCreate8(NULL, &ds8, NULL);
    ds8->SetCooperativeLevel(window.getWindowHwnd(), DSSCL_NORMAL);

    waveFormat.wFormatTag = WAVE_FORMAT_PCM;
    waveFormat.nChannels = 1;
    waveFormat.nSamplesPerSec = 44100;
    waveFormat.wBitsPerSample = 16;
    waveFormat.nBlockAlign = (waveFormat.wBitsPerSample/8)*waveFormat.nChannels;
    waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
    waveFormat.cbSize = 0;

    memset(&bufdesc, 0, sizeof(DSBUFFERDESC)); 
    bufdesc.dwSize = sizeof(DSBUFFERDESC); 
    bufdesc.dwFlags = DSBCAPS_STATIC | DSBCAPS_GLOBALFOCUS;
    bufdesc.dwBufferBytes = waveFormat.nAvgBytesPerSec * seconds;
    bufdesc.guid3DAlgorithm = GUID_NULL;
    bufdesc.lpwfxFormat = &waveFormat;
}
开发者ID:process,项目名称:Project-8,代码行数:22,代码来源:sound.cpp

示例13: run

void DXAudioOutput::run() {
	HRESULT hr;
	DSBUFFERDESC        dsbdesc;
	WAVEFORMATEXTENSIBLE wfx;
	WAVEFORMATEXTENSIBLE wfxSet;
	int ns = 0;
	unsigned int chanmasks[32];

	LPDIRECTSOUND8             pDS = NULL;
	LPDIRECTSOUNDBUFFER       pDSBPrimary = NULL;
	LPDIRECTSOUNDBUFFER       pDSBOutput = NULL;
	LPDIRECTSOUNDNOTIFY8       pDSNotify = NULL;

	DWORD	dwBufferSize;
	DWORD	dwLastWritePos;
	DWORD	dwLastPlayPos;
	DWORD	dwTotalPlayPos;
	int iLastwriteblock;
	LPVOID aptr1, aptr2;
	DWORD nbytes1, nbytes2;

	int playblock;
	int nowriteblock;
	DWORD dwPlayPosition, dwWritePosition;

	unsigned int iByteSize;

	bool bOk;
	DWORD dwSpeakerConfig;

	bool failed = false;

	bOk = false;
	DWORD dwMask = 0;
	bool bHead = false;

	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
	dsbdesc.dwSize  = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;

	if (! g.s.qbaDXOutput.isEmpty()) {
		LPGUID lpguid = reinterpret_cast<LPGUID>(g.s.qbaDXOutput.data());
		if (FAILED(hr = DirectSoundCreate8(lpguid, &pDS, NULL))) {
			failed = true;
		}
	}

	if (! pDS && FAILED(hr = DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback, &pDS, NULL))) {
		qWarning("DXAudioOutput: DirectSoundCreate failed: hr=0x%08lx", hr);
		goto cleanup;
	} else if (FAILED(hr = pDS->SetCooperativeLevel(g.mw->winId(), DSSCL_PRIORITY))) {
		qWarning("DXAudioOutput: SetCooperativeLevel failed: hr=0x%08lx", hr);
		goto cleanup;
	} else if (FAILED(hr = pDS->CreateSoundBuffer(&dsbdesc, &pDSBPrimary, NULL))) {
		qWarning("DXAudioOutput: CreateSoundBuffer (Primary) failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	pDS->GetSpeakerConfig(&dwSpeakerConfig);


	switch (DSSPEAKER_CONFIG(dwSpeakerConfig)) {
		case DSSPEAKER_HEADPHONE:
			dwMask = KSAUDIO_SPEAKER_STEREO;
			bHead = true;
			break;
		case DSSPEAKER_MONO:
			dwMask = KSAUDIO_SPEAKER_MONO;
			break;
		case DSSPEAKER_QUAD:
			dwMask = KSAUDIO_SPEAKER_QUAD;
			break;
		case DSSPEAKER_STEREO:
			dwMask = KSAUDIO_SPEAKER_STEREO;
			break;
		case DSSPEAKER_SURROUND:
			dwMask = KSAUDIO_SPEAKER_SURROUND;
			break;
		case DSSPEAKER_5POINT1:
			dwMask = KSAUDIO_SPEAKER_5POINT1;
			break;
		case DSSPEAKER_7POINT1:
			dwMask = KSAUDIO_SPEAKER_7POINT1;
			break;
		case DSSPEAKER_7POINT1_SURROUND:
			dwMask = KSAUDIO_SPEAKER_7POINT1_SURROUND;
			break;
		case DSSPEAKER_5POINT1_SURROUND:
			dwMask = KSAUDIO_SPEAKER_5POINT1_SURROUND;
			break;
		default:
			dwMask = 0;
			break;
	}

	if (! g.s.doPositionalAudio())
		dwMask = KSAUDIO_SPEAKER_MONO;

	for (int i=0;i<32;i++) {
		if (dwMask & (1 << i)) {
//.........这里部分代码省略.........
开发者ID:FreshLeaf8865,项目名称:mumble,代码行数:101,代码来源:DirectSound.cpp

示例14: init

bool DirectSound::init(long sampleRate)
{
	HRESULT hr;
	DWORD freq;
	DSBUFFERDESC dsbdesc;
	int i;

	hr = CoCreateInstance( CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound8, (LPVOID *)&pDirectSound );
	if( hr != S_OK ) {
		systemMessage( IDS_CANNOT_CREATE_DIRECTSOUND, NULL, hr );
		return false;
	}

	pDirectSound->Initialize( &DSDEVID_DefaultPlayback );
	if( hr != DS_OK ) {
		systemMessage( IDS_CANNOT_CREATE_DIRECTSOUND, NULL, hr );
		return false;
	}

	if( FAILED( hr = pDirectSound->SetCooperativeLevel( theApp.m_pMainWnd->GetSafeHwnd(), DSSCL_EXCLUSIVE ) ) ) {
		systemMessage( IDS_CANNOT_SETCOOPERATIVELEVEL, _T("Cannot SetCooperativeLevel %08x"), hr );
		return false;
	}


	// Create primary sound buffer
	ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) );
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	if( dsoundDisableHardwareAcceleration ) {
		dsbdesc.dwFlags |= DSBCAPS_LOCSOFTWARE;
	}

	if( FAILED( hr = pDirectSound->CreateSoundBuffer( &dsbdesc, &dsbPrimary, NULL ) ) ) {
		systemMessage(IDS_CANNOT_CREATESOUNDBUFFER, _T("Cannot CreateSoundBuffer %08x"), hr);
		return false;
	}

	freq = sampleRate;
	// calculate the number of samples per frame first
	// then multiply it with the size of a sample frame (16 bit * stereo)
	soundBufferLen = ( freq / 60 ) * 4;
	soundBufferTotalLen = soundBufferLen * 10;
	soundNextPosition = 0;

	ZeroMemory( &wfx, sizeof(WAVEFORMATEX) );
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = freq;
	wfx.wBitsPerSample = 16;
	wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

	if( FAILED( hr = dsbPrimary->SetFormat( &wfx ) ) ) {
		systemMessage( IDS_CANNOT_SETFORMAT_PRIMARY, _T("CreateSoundBuffer(primary) failed %08x"), hr );
		return false;
	}


	// Create secondary sound buffer
	ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) );
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GLOBALFOCUS;
	if( dsoundDisableHardwareAcceleration ) {
		dsbdesc.dwFlags |= DSBCAPS_LOCSOFTWARE;
	}
	dsbdesc.dwBufferBytes = soundBufferTotalLen;
	dsbdesc.lpwfxFormat = &wfx;

	if( FAILED( hr = pDirectSound->CreateSoundBuffer( &dsbdesc, &dsbSecondary, NULL ) ) ) {
		systemMessage( IDS_CANNOT_CREATESOUNDBUFFER, _T("CreateSoundBuffer(secondary) failed %08x"), hr );
		return false;
	}

	if( FAILED( hr = dsbSecondary->SetCurrentPosition( 0 ) ) ) {
		systemMessage( 0, _T("dsbSecondary->SetCurrentPosition failed %08x"), hr );
		return false;
	}


	if( SUCCEEDED( hr = dsbSecondary->QueryInterface( IID_IDirectSoundNotify8, (LPVOID*)&dsbNotify ) ) ) {
		dsbEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
		DSBPOSITIONNOTIFY notify[10];
		for( i = 0; i < 10; i++ ) {
			notify[i].dwOffset = i * soundBufferLen;
			notify[i].hEventNotify = dsbEvent;
		}

		if( FAILED( dsbNotify->SetNotificationPositions( 10, notify ) ) ) {
			dsbNotify->Release();
			dsbNotify = NULL;
			CloseHandle(dsbEvent);
			dsbEvent = NULL;
		}
	}


	// Play primary buffer
	if( FAILED( hr = dsbPrimary->Play( 0, 0, DSBPLAY_LOOPING ) ) ) {
		systemMessage( IDS_CANNOT_PLAY_PRIMARY, _T("Cannot Play primary %08x"), hr );
//.........这里部分代码省略.........
开发者ID:MrSwiss,项目名称:visualboyadvance-m,代码行数:101,代码来源:DirectSound.cpp

示例15: DS_CreateBuffers

/*
** DS_CreateBuffers
*/
static int DS_CreateBuffers( void )
{
	DSBUFFERDESC	dsbuf;
	DSBCAPS			dsbcaps;
	WAVEFORMATEX	pformat, format;
	DWORD			dwWrite;

	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
    format.nChannels = dma.channels;
    format.wBitsPerSample = dma.samplebits;
    format.nSamplesPerSec = dma.speed;
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
    format.cbSize = 0;
    format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; 

	Com_Printf( "Creating DirectSound 8 buffers\n" );

	Com_Printf("...setting PRIORITY coop level: " );
#ifdef QDSNDCOMPILERHACK
	if ( DS_OK != pDS->lpVtbl->SetCooperativeLevel( pDS, cl_hwnd, DSSCL_PRIORITY ) )
#else
	if ( DS_OK != pDS->SetCooperativeLevel( cl_hwnd, DSSCL_PRIORITY ) )
#endif
	{
		Com_Printf ("failed\n");
		FreeSound ();
		return 0;
	}
	Com_Printf("ok\n" );

// get access to the primary buffer, if possible, so we can set the
// sound hardware format
	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);
	dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER; // | DSBCAPS_CTRL3D;
	dsbuf.dwBufferBytes = 0;
	dsbuf.lpwfxFormat = NULL;

	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);
	primary_format_set = 0;
	
	if (!pDSPBuf)
	{
		Com_Printf( "...creating primary buffer: " );
#ifdef QDSNDCOMPILERHACK
		if (DS_OK == pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSPBuf, NULL))
#else
		if (DS_OK == pDS->CreateSoundBuffer(&dsbuf, &pDSPBuf, NULL))
#endif
		{
			pformat = format;

			Com_Printf( "ok\n" );
#ifdef QDSNDCOMPILERHACK
			if (DS_OK != pDSPBuf->lpVtbl->SetFormat (pDSPBuf, &pformat))
#else
			if (DS_OK != pDSPBuf->SetFormat (&pformat))
#endif
			{
				if (snd_firsttime)
					Com_Printf ("...setting primary sound format: failed\n");
			}
			else
			{
				if (snd_firsttime)
					Com_Printf ("...setting primary sound format: ok\n");

				primary_format_set = 1;
			}
		}
		else
			Com_Printf( "failed\n" );
	}

	if ( !primary_format_set || !s_primary->value)
	{
		// create the secondary buffer we'll actually work with
		memset (&dsbuf, 0, sizeof(DSBUFFERDESC));
		dsbuf.dwSize = sizeof(DSBUFFERDESC);
		dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE; //| DSBCAPS_MUTE3DATMAXDISTANCE; // | DSBCAPS_CTRL3D;	
		//dsbuf.dwFlags |= DSBCAPS_CTRLVOLUME;			// Allow volume control
		//dsbuf.dwBufferBytes = format.nAvgBytesPerSec * SECONDARY_BUFFER_LEN_SECONDS;
		dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE * s_buffersize->value;
		dsbuf.lpwfxFormat = &format;
		//dsbuf.guid3DAlgorithm = DS3DALG_DEFAULT;
		//dsbuf.guid3DAlgorithm = DS3DALG_HRTF_FULL;	// Use high quality 3D processing

		memset(&dsbcaps, 0, sizeof(dsbcaps));
		dsbcaps.dwSize = sizeof(dsbcaps);

		Com_Printf( "...creating secondary buffer: " );

		//pDSPBuf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) pDSBuf);
		//myDirectSoundIID = &IID_IDirectSoundBuffer8;
		//pDSPBuf->lpVtbl->QueryInterface(pDSPBuf, myDirectSoundIID, &pDSBuf);
//.........这里部分代码省略.........
开发者ID:Jaegermeiste,项目名称:quake2_322,代码行数:101,代码来源:snd_win.c


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