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


C++ LPDIRECTSOUND::GetSpeakerConfig方法代码示例

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


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

示例1: sizeof

/*
===============
idAudioHardwareWIN32::SetPrimaryBufferFormat
Set primary buffer to a specified format
For example, to set the primary buffer format to 22kHz stereo, 16-bit
then:   dwPrimaryChannels = 2
        dwPrimaryFreq     = 22050,
        dwPrimaryBitRate  = 16
===============
*/
void idAudioHardwareWIN32::SetPrimaryBufferFormat(dword dwPrimaryFreq, dword dwPrimaryBitRate, dword dwSpeakers)
{
	HRESULT             hr;

	if (m_pDS == NULL) {
		return;
	}

	ulong cfgSpeakers;
	m_pDS->GetSpeakerConfig(&cfgSpeakers);

	DSCAPS dscaps;
	dscaps.dwSize = sizeof(DSCAPS);
	m_pDS->GetCaps(&dscaps);

	if (dscaps.dwFlags & DSCAPS_EMULDRIVER) {
		return;
	}

	// Get the primary buffer
	DSBUFFERDESC dsbd;
	ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
	dsbd.dwSize        = sizeof(DSBUFFERDESC);
	dsbd.dwFlags       = DSBCAPS_PRIMARYBUFFER;
	dsbd.dwBufferBytes = 0;
	dsbd.lpwfxFormat   = NULL;

	// Obtain write-primary cooperative level.
	if (FAILED(hr = m_pDS->SetCooperativeLevel(win32.hWnd, DSSCL_PRIORITY))) {
		DXTRACE_ERR(TEXT("SetPrimaryBufferFormat"), hr);
		return;
	}

	if (FAILED(hr = m_pDS->CreateSoundBuffer(&dsbd, &pDSBPrimary, NULL))) {
		return;
	}

	if (dwSpeakers == 6 && (cfgSpeakers == DSSPEAKER_5POINT1 || cfgSpeakers == DSSPEAKER_SURROUND)) {
		WAVEFORMATEXTENSIBLE 	waveFormatPCMEx;
		ZeroMemory(&waveFormatPCMEx, sizeof(WAVEFORMATEXTENSIBLE));

		waveFormatPCMEx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
		waveFormatPCMEx.Format.nChannels = 6;
		waveFormatPCMEx.Format.nSamplesPerSec = dwPrimaryFreq;
		waveFormatPCMEx.Format.wBitsPerSample  = (WORD) dwPrimaryBitRate;
		waveFormatPCMEx.Format.nBlockAlign = waveFormatPCMEx.Format.wBitsPerSample / 8 * waveFormatPCMEx.Format.nChannels;
		waveFormatPCMEx.Format.nAvgBytesPerSec = waveFormatPCMEx.Format.nSamplesPerSec * waveFormatPCMEx.Format.nBlockAlign;
		waveFormatPCMEx.dwChannelMask = KSAUDIO_SPEAKER_5POINT1;
		// SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT |
		// SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY |
		// SPEAKER_BACK_LEFT  | SPEAKER_BACK_RIGHT
		waveFormatPCMEx.SubFormat =  KSDATAFORMAT_SUBTYPE_PCM;  // Specify PCM
		waveFormatPCMEx.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
		waveFormatPCMEx.Samples.wValidBitsPerSample = 16;

		if (FAILED(hr = pDSBPrimary->SetFormat((WAVEFORMATEX *)&waveFormatPCMEx))) {
			DXTRACE_ERR(TEXT("SetPrimaryBufferFormat"), hr);
			return;
		}

		numSpeakers = 6;		// force it to think 5.1
		blockAlign = waveFormatPCMEx.Format.nBlockAlign;
	} else {
		if (dwSpeakers == 6) {
			common->Printf("sound: hardware reported unable to use multisound, defaulted to stereo\n");
		}

		WAVEFORMATEX wfx;
		ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
		wfx.wFormatTag      = WAVE_FORMAT_PCM;
		wfx.nChannels       = 2;
		wfx.nSamplesPerSec  = dwPrimaryFreq;
		wfx.wBitsPerSample  = (WORD) dwPrimaryBitRate;
		wfx.nBlockAlign     = wfx.wBitsPerSample / 8 * wfx.nChannels;
		wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
		wfx.cbSize = sizeof(WAVEFORMATEX);

		if (FAILED(hr = pDSBPrimary->SetFormat(&wfx))) {
			return;
		}

		numSpeakers = 2;		// force it to think stereo
		blockAlign = wfx.nBlockAlign;
	}

	byte *speakerData;
	bufferSize = MIXBUFFER_SAMPLES * sizeof(word) * numSpeakers * ROOM_SLICES_IN_BUFFER;
	speakerData = (byte *)Mem_Alloc(bufferSize);
	memset(speakerData, 0, bufferSize);

//.........这里部分代码省略.........
开发者ID:AreaScout,项目名称:dante-doom3-odroid,代码行数:101,代码来源:win_snd.cpp

示例2: GetSpeakerConfig

HRESULT STDMETHODCALLTYPE DirectSound::GetSpeakerConfig(LPDWORD pdwSpeakerConfig)
{
	return m_ds->GetSpeakerConfig(pdwSpeakerConfig);
}
开发者ID:ThrDev,项目名称:dsbridge,代码行数:4,代码来源:DirectSound.cpp


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