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


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

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


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

示例1: FindAlternateSampleFormat

static BOOL FindAlternateSampleFormat()
{
    const uint32_t aFormatOrder[]={
        44216, 44116, 44208, 44108, 22216, 22116, 22208, 22108,
    11216, 11116, 11208, 11108, 8216, 8116, 8208, 8108, 0};

    int nCurFormat = 0;
	HRESULT hr;
    do
    {
        uint32_t
        dwFormat = aFormatOrder[nCurFormat++],
        dwFreq = dwFormat/1000;
        g_cDSPCMOutFormat.nSamplesPerSec = (dwFreq==8)? 8000:(dwFreq/11)*11025;
        g_cDSPCMOutFormat.wBitsPerSample = (uint16_t)(dwFormat%100);
        g_cDSPCMOutFormat.nChannels = (uint16_t)((dwFormat%1000)/100);
        g_cDSPCMOutFormat.nBlockAlign = (uint16_t)(g_cDSPCMOutFormat.nChannels   * (g_cDSPCMOutFormat.wBitsPerSample>>3));
        g_cDSPCMOutFormat.nAvgBytesPerSec = (uint32_t)g_cDSPCMOutFormat.nBlockAlign * (uint32_t)g_cDSPCMOutFormat.nSamplesPerSec;
        hr = SYS_DXTRACE(g_lpPrimaryBuffer->SetFormat(&g_cDSPCMOutFormat));
    }while( (hr!=DS_OK) && (nCurFormat!=16));

    if ( (nCurFormat==16) && (hr!=DS_OK) )
    {
        SYS_DXTRACE(g_lpPrimaryBuffer->SetFormat(&g_cDSPCMOutFormat));
        return TRUE;
    }
	return 0;
}
开发者ID:cbxbiker61,项目名称:nogravity,代码行数:28,代码来源:snd_ds6.cpp

示例2: create_buffer

		// directsound_audio_stream::create_buffer()
		void directsound_audio_stream::create_buffer(directsound_instance& instance, audio_format const& format) {
			WAVEFORMATEX waveFormat;
			waveFormat.wFormatTag = WAVE_FORMAT_PCM;
			waveFormat.nChannels = format.channels();
			waveFormat.nSamplesPerSec = format.frequency();
			waveFormat.nAvgBytesPerSec = format.bytes_per_second();
			waveFormat.nBlockAlign = static_cast<WORD>(format.bytes_per_frame());
			waveFormat.wBitsPerSample = format.bits_per_sample();
			waveFormat.cbSize = 0;

			DSBUFFERDESC bufferDesc;
			bufferDesc.dwSize = sizeof(DSBUFFERDESC);
			bufferDesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
			bufferDesc.dwReserved = 0;
			bufferDesc.dwBufferBytes = static_cast<DWORD>( BufferSize_seconds.count() * format.bytes_per_second() );
			bufferDesc.guid3DAlgorithm = DS3DALG_DEFAULT;
			bufferDesc.lpwfxFormat = &waveFormat;
			LPDIRECTSOUNDBUFFER ptr = nullptr;
			if( FAILED(instance.ptr()->CreateSoundBuffer(&bufferDesc, &ptr, nullptr)) ) {
				throw directsound_exception{};
			}
			ptr->SetFormat(&waveFormat);
			_buffer = buffer_ptr{ ptr };

			clear_entire_buffer();
			_state = audio_stream_state::ready;
		}
开发者ID:fr00b0,项目名称:chirp,代码行数:28,代码来源:directsound_backend.cpp

示例3: Init

bool WindowsSound::Init()
{
    HRESULT hr;

    //create the sound device
    hr = DirectSoundCreate8(NULL, &(this->directSoundDevice), NULL);
    if(FAILED(hr))
        return false;

    //set cooperative level to PRIORITY (=high)
    HWND hwndC = GetConsoleWindow() ;
    hr = this->directSoundDevice->SetCooperativeLevel(hwndC, DSSCL_PRIORITY);
    if(FAILED(hr))
        return false;

    //create an output wave format
    WAVEFORMATEX waveFormat;
    memset(&waveFormat, 0, sizeof(WAVEFORMATEX));
    waveFormat.wFormatTag = WAVE_FORMAT_PCM;
    waveFormat.nChannels = CHANNELS_NUMBER;
    waveFormat.nSamplesPerSec = SAMPLE_RATE;
    waveFormat.wBitsPerSample = BITS_PER_SAMPLE;
    waveFormat.nBlockAlign = BLOCK_ALIGN;
    waveFormat.nAvgBytesPerSec = AVERAGE_BYTES_PER_SECOND; //msdn recommendation for PCM format

    //Primary sound buffer
    DSBUFFERDESC bufferDesc;
    memset(&bufferDesc, 0, sizeof(DSBUFFERDESC));
    bufferDesc.dwSize = sizeof(DSBUFFERDESC);
    bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER|DSBCAPS_STICKYFOCUS;
    bufferDesc.dwBufferBytes = 0;
    bufferDesc.lpwfxFormat = NULL;

    LPDIRECTSOUNDBUFFER primaryDirectSoundBuffer;
    hr = this->directSoundDevice->CreateSoundBuffer(&bufferDesc, &primaryDirectSoundBuffer, NULL);
    if(FAILED(hr))
        return false;
    hr = primaryDirectSoundBuffer->SetFormat(&waveFormat);
    if(FAILED(hr))
        return false;

    //set up a buffer description
    DSBUFFERDESC soundBufferDescription;
    memset(&soundBufferDescription, 0, sizeof(DSBUFFERDESC));
    soundBufferDescription.dwSize = sizeof(DSBUFFERDESC);
    //DSBCAPS_STICKYFOCUS: allows to play sound even if we don't have have focus.
    //DSBCAPS_GETCURRENTPOSITION2: tells DirectSound we'll use the GetPosition method later on that sound buffer.
    soundBufferDescription.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS;
    soundBufferDescription.dwBufferBytes = BUFFER_LENGTH_IN_BYTES;
    soundBufferDescription.lpwfxFormat = &waveFormat;

    //create the sound buffer
    hr = this->directSoundDevice->CreateSoundBuffer(&soundBufferDescription, &(this->directSoundBuffer), NULL);
    if(FAILED(hr))
        return false;

    return true;

}
开发者ID:moleculext,项目名称:bicyclette,代码行数:59,代码来源:WindowsSound.cpp

示例4: CreateDSBuffer

HRESULT CMpcAudioRenderer::CreateDSBuffer()
{
	if (! m_pWaveFileFormat) return E_POINTER;

	HRESULT					hr				= S_OK;
	LPDIRECTSOUNDBUFFER		pDSBPrimary		= NULL;
	DSBUFFERDESC			dsbd;
	DSBUFFERDESC			cDSBufferDesc;
	DSBCAPS					bufferCaps;
	DWORD					dwDSBufSize		= m_pWaveFileFormat->nAvgBytesPerSec * 4;

	ZeroMemory(&bufferCaps, sizeof(bufferCaps));
	ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));

	dsbd.dwSize        = sizeof(DSBUFFERDESC);
	dsbd.dwFlags       = DSBCAPS_PRIMARYBUFFER;
	dsbd.dwBufferBytes = 0;
	dsbd.lpwfxFormat   = NULL;
	if (SUCCEEDED (hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL )))
	{
		hr = pDSBPrimary->SetFormat(m_pWaveFileFormat);
		ATLASSERT(SUCCEEDED(hr));
		SAFE_RELEASE (pDSBPrimary);
	}


	SAFE_RELEASE (m_pDSBuffer);
	cDSBufferDesc.dwSize			= sizeof (DSBUFFERDESC);
	cDSBufferDesc.dwFlags			= DSBCAPS_GLOBALFOCUS			| 
									  DSBCAPS_GETCURRENTPOSITION2	| 
									  DSBCAPS_CTRLVOLUME 			|
									  DSBCAPS_CTRLPAN				|
									  DSBCAPS_CTRLFREQUENCY; 
	cDSBufferDesc.dwBufferBytes		= dwDSBufSize; 
	cDSBufferDesc.dwReserved		= 0; 
	cDSBufferDesc.lpwfxFormat		= m_pWaveFileFormat; 
   	cDSBufferDesc.guid3DAlgorithm	= GUID_NULL; 

	hr = m_pDS->CreateSoundBuffer (&cDSBufferDesc,  &m_pDSBuffer, NULL);

	m_nDSBufSize = 0;
	if (SUCCEEDED(hr))
	{
		bufferCaps.dwSize = sizeof(bufferCaps);
		hr = m_pDSBuffer->GetCaps(&bufferCaps);
	}
	if (SUCCEEDED (hr))
	{
		m_nDSBufSize = bufferCaps.dwBufferBytes;
		hr = ClearBuffer();
		m_pDSBuffer->SetFrequency ((long)(m_pWaveFileFormat->nSamplesPerSec * m_dRate));
	}

	return hr;
}
开发者ID:Fluffiest,项目名称:splayer,代码行数:55,代码来源:MpcAudioRenderer.cpp

示例5: initializeImpl

// initialize
bool sspDSDeviceGroup::initializeImpl(LPVOID hWnd)
{
	if (m_pDS.size() > 0) return TRUE;	// Already initialized

    if (hWnd == NULL)
    {
        // Error, invalid hwnd
        DOUT (_T("ERROR: Invalid parameters, unable to initialize services\n\r"));
        return FALSE;
    }
	m_hApp = (HWND) hWnd;
    setBufferFormat(2);
	m_pDS.reserve(m_nDevices.size());
	m_pDSBuf.reserve(m_nDevices.size());
	for (unsigned int i=0; i<m_nDevices.size(); i++) {
		// Create DirectSound object
		LPDIRECTSOUND ds;
		HRESULT nResult = DirectSoundCreate(m_dsInfo[m_nDevices[i]]->lpGuid, &ds, NULL);
		if (nResult == DS_OK) {
			nResult = ds->SetCooperativeLevel(m_hApp, DSSCL_PRIORITY);
			if (nResult == DS_OK) {
				LPDIRECTSOUNDBUFFER dsbuf;
				nResult = ds->CreateSoundBuffer(&m_dsBufDesc, &dsbuf, NULL);
				if (nResult == DS_OK) {
					nResult = dsbuf->SetFormat(&m_pcmWf);
					if (nResult == DS_OK) {
						DOUT (_T("SUCCESS: DirectSound created and formatted\n\r"));
					}
					else {
						DOUT(_T("ERROR: Unable to set DirectSound format\n\r"));
						return FALSE;
					}
				m_pDSBuf.push_back(dsbuf);
				}
				else {
					DOUT(_T("ERROR: Unable to create DirectSound buffer\n\r"));
					return FALSE;
				}
			}
			else {
				DOUT(_T("ERROR: Unable to set DirectSound cooperative level\n\r"));
				return FALSE;
			}
			m_pDS.push_back(ds);
		}
		else {
			// Error
			DOUT(_T("ERROR: Unable to create DirectSound object\n\r"));
			return FALSE;
		}
	}
    return TRUE;
}
开发者ID:ssaue,项目名称:soundspace,代码行数:54,代码来源:sspDirectSoundDevice.cpp

示例6: return

    // ////////////////////////////////////////////////////////////////////
    //
    // ////////////////////////////////////////////////////////////////////
    HRESULT DirectSound8Audio::SetPrimaryBufferFormat(
        DWORD dwPrimaryChannels,
        DWORD dwPrimaryFreq,
        DWORD dwPrimaryBitRate)
    {
        // !WARNING! - Setting the primary buffer format and then using this
        // it for DirectMusic messes up DirectMusic!
        //
        // If you want your primary buffer format to be 22kHz stereo, 16-bit
        // call with these parameters:  SetPrimaryBufferFormat(2, 22050, 16);

        HRESULT             hr;
        LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

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

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

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

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

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

        Release(pDSBPrimary);

        return (S_OK);
    }
开发者ID:pjohalloran,项目名称:gameframework,代码行数:50,代码来源:DirectSoundAudio.cpp

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

示例8: SetPrimaryBufferFormat

//--------------------------------------------------------------------
//Function: SetPrimaryBufferFormat
//Parameters: dwPrimaryChannels - The number of voice channel
//            dwPrimaryFreq     - Sample frequency
//            dwPrimaryBitRate  - The number of bits of sampling
//Description: Set primary buffer to a specified format
//Note: Setting the primary buffer format and then using this
//      same DSound object for DirectMusic messes up DirectMusic
//Example: to set the primary buffer format to 22kHz stereo, 16-bit
//         dwPrimaryChannels = 2
//         dwPrimaryFreq     = 22050
//         dwPrimaryBitRate  = 16
//--------------------------------------------------------------------
HRESULT CSoundManager::SetPrimaryBufferFormat(DWORD dwPrimaryChannels, 
                                              DWORD dwPrimaryFreq, 
                                              DWORD dwPrimaryBitRate)
{
    HRESULT             hr;
    LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

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

    // Get the primary buffer 
    DSBUFFERDESC dsbd;
    ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
    dsbd.dwSize        = sizeof(DSBUFFERDESC);
    dsbd.dwFlags       = DSBCAPS_PRIMARYBUFFER;
    dsbd.dwBufferBytes = 0;
    dsbd.lpwfxFormat   = NULL;
       
    if(FAILED(hr = m_pDS->CreateSoundBuffer(&dsbd, &pDSBPrimary, NULL)))
	{
        return DXTRACE_ERR(TEXT("CreateSoundBuffer"), hr);
	}

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

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

    SAFE_RELEASE(pDSBPrimary);

    return S_OK;
}
开发者ID:ningmenglive,项目名称:NineLine,代码行数:56,代码来源:SoundManager.cpp

示例9: Initialize

static int Initialize(void *hwnd)
{
    DSBUFFERDESC primaryDesc;
    if (!g_lpDSDevice) return TRUE;
    sysMemZero(&primaryDesc, sizeof(DSBUFFERDESC));
    primaryDesc.dwSize = sizeof(DSBUFFERDESC);
    primaryDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
    if (RLX.Audio.Config & RLXAUDIO_Use3D)
		primaryDesc.dwFlags|= DSBCAPS_CTRL3D;

	if (SYS_DXTRACE(g_lpDSDevice->SetCooperativeLevel((HWND)hwnd, DSSCL_EXCLUSIVE)) != DS_OK)
		return -1;

	if (SYS_DXTRACE(g_lpDSDevice->CreateSoundBuffer(&primaryDesc, &g_lpPrimaryBuffer, NULL))!=DS_OK )
		return 0;
    else
    {
		HRESULT hr;
		sysMemZero(&g_cDSPCMOutFormat, sizeof(WAVEFORMATEX));
		g_cDSPCMOutFormat.wFormatTag = WAVE_FORMAT_PCM;
		g_cDSPCMOutFormat.wBitsPerSample = 16;
		g_cDSPCMOutFormat.nChannels = 2;
		g_cDSPCMOutFormat.nSamplesPerSec = 44100;
		g_cDSPCMOutFormat.nBlockAlign = (uint16_t)(g_cDSPCMOutFormat.nChannels   *  (g_cDSPCMOutFormat.wBitsPerSample>>3));
		g_cDSPCMOutFormat.nAvgBytesPerSec = (uint32_t)g_cDSPCMOutFormat.nBlockAlign *  (uint32_t)g_cDSPCMOutFormat.nSamplesPerSec;
		hr = g_lpPrimaryBuffer->SetFormat(&g_cDSPCMOutFormat);
		if ( hr != DS_OK )
			FindAlternateSampleFormat();

        if (RLX.Audio.Config & RLXAUDIO_Use3D)
        {
			hr = SYS_DXTRACE(g_lpPrimaryBuffer->QueryInterface(IID_IDirectSound3DListener, (void**)&g_lpDS3DListener));
            if (hr== DS_OK)
				hr = g_lpDS3DListener->SetAllParameters(&Listener3dProps, DS3D_IMMEDIATE);
        }
    }
    return 0; // no problemo.
}
开发者ID:cbxbiker61,项目名称:nogravity,代码行数:38,代码来源:snd_ds6.cpp

示例10: SetPrimaryBufferFormat

HRESULT DirectSoundAudio::SetPrimaryBufferFormat(
	AUINT32 u32PrimaryChannels,
	AUINT32 u32PrimaryFreq,
	AUINT32 u32PrimaryBitRate )
{
	HRESULT hr;
	LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

	if (!m_pDS)
		return CO_E_NOTINITIALIZED;

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

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

	WAVEFORMATEX wfx;
	ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
	wfx.wFormatTag = (WORD)WAVE_FORMAT_PCM;
	wfx.nChannels = (WORD)u32PrimaryChannels;
	wfx.nSamplesPerSec = (DWORD)u32PrimaryFreq;
	wfx.wBitsPerSample = (WORD)u32PrimaryBitRate;
	wfx.nBlockAlign = (WORD)(wfx.wBitsPerSample / 8 * wfx.nChannels);
	wfx.nAvgBytesPerSec = (DWORD)(wfx.nSamplesPerSec * wfx.nBlockAlign);

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

	SAFE_RELEASE(pDSBPrimary);

	return S_OK;
}
开发者ID:Solidstatewater,项目名称:Anubis-Engine,代码行数:38,代码来源:DirectAudio.cpp

示例11: ds_ConfigurePrimary

//-----------------------------------------------------------------------------
//	Конфигурирование первичного буфера
// на входе    :  primary  - указатель на первичный буфер
//  			  rate     - частота дискретизации
//  			  bits     - количество бит на выборку
//  			  channels - количество каналов
// на выходе   :	успешность конфигурирования первичного буфер
//-----------------------------------------------------------------------------
int ds_ConfigurePrimary(LPDIRECTSOUNDBUFFER primary, int rate, int bits,
	int channels)
{
	WAVEFORMATEX wfx;

	if (!primary)
		return false;

	// занесение данных о формате первичного звукового буфера
	ZeroMemory(&wfx, sizeof(WAVEFORMATEX)); 
	wfx.wFormatTag = WAVE_FORMAT_PCM; 
	wfx.nChannels = channels;
	wfx.nSamplesPerSec = rate;
	wfx.wBitsPerSample = bits;
	wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

	// форматирование первичного буфера
	if (primary->SetFormat(&wfx) != DS_OK)
		return false;

	return true;
}
开发者ID:doveiya,项目名称:isilme,代码行数:31,代码来源:DirectSound.cpp

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

示例13: content_error

CDxSound::CDxSound()
{
	maxSounds=ConfigHandler::GetInstance().GetInt("MaxSounds",16);
	if (maxSounds <= 0) {
		throw content_error("Internal error, (maxSounds <= 0) in CDxSound");
	}

	curThreshhold=0.1f;
	wantedSounds=maxSounds*0.75f;
	globalVolume=1.0f;

	m_pDS  = NULL;
	m_hWnd = NULL;

	HRESULT hr;

	LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

	// Get window from SDL
	SDL_SysWMinfo wmInfo;
	SDL_VERSION(&wmInfo.version);
	if (SDL_GetWMInfo (&wmInfo) != 1) {
		throw "DxSound: Could not get window from SDL";
	}
	m_hWnd = wmInfo.window;
	
	// Initialize COM
	hr = CoInitialize( NULL );
	if( hr!=S_OK && hr!=S_FALSE){
		throw "DxSound: Could not initialize com";
	}
	
	// Create IDirectSound using the primary sound device
	if( FAILED( hr = DirectSoundCreate( NULL, &m_pDS, NULL ) ) ){
		throw "DxSound: Could not create direct sound object";
	}

    // Set coop level to DSSCL_PRIORITY
	if( FAILED( hr = m_pDS->SetCooperativeLevel( m_hWnd, DSSCL_PRIORITY ) ) ){
		throw "DxSound: Could not set cooperative level";
	}
	
	// Get the primary buffer 
	DSBUFFERDESC dsbd;
	ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
	dsbd.dwSize        = sizeof(DSBUFFERDESC);
	dsbd.dwFlags       = DSBCAPS_PRIMARYBUFFER;
	dsbd.dwBufferBytes = 0;
	dsbd.lpwfxFormat   = NULL;
	
	if( FAILED( hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL ) ) ){
		throw "DxSound: Could not create primary sound buffer";
	}
	
	// Set primary buffer format to 22kHz and 16-bit output.
	WAVEFORMATEX wfx;
	ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); 
	wfx.wFormatTag      = WAVE_FORMAT_PCM; 
	wfx.nChannels       = 2; 
	wfx.nSamplesPerSec  = 22050; 
	wfx.wBitsPerSample  = 16; 
	wfx.nBlockAlign     = wfx.wBitsPerSample / 8 * wfx.nChannels;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
	
	if( FAILED( hr = pDSBPrimary->SetFormat(&wfx) ) ){
		throw "DxSound: Could not initialize primary sound format";
	}
	
	SAFE_RELEASE( pDSBPrimary );
	waveid[""]=0;
	SoundInfo* si=SAFE_NEW SoundInfo;
	loadedSounds.push_back(si);
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:73,代码来源:DxSound.cpp

示例14: Init

void TSoundsManager::Init(HWND hWnd)
{

    First = NULL;
    Count = 0;
    pDS = NULL;
    pDSNotify = NULL;

    HRESULT hr; //=222;
    LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

    //    strcpy(Directory, NDirectory);

    // Create IDirectSound using the primary sound device
    hr = DirectSoundCreate(NULL, &pDS, NULL);
    if (hr != DS_OK)
    {

        if (hr == DSERR_ALLOCATED)
            return;
        if (hr == DSERR_INVALIDPARAM)
            return;
        if (hr == DSERR_NOAGGREGATION)
            return;
        if (hr == DSERR_NODRIVER)
            return;
        if (hr == DSERR_OUTOFMEMORY)
            return;

        //  hr=0;
    };
    //    return ;

    // Set coop level to DSSCL_PRIORITY
    //    if( FAILED( hr = pDS->SetCooperativeLevel( hWnd, DSSCL_PRIORITY ) ) );
    //      return ;
    pDS->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);

    // Get the primary buffer
    DSBUFFERDESC dsbd;
    ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
    dsbd.dwSize = sizeof(DSBUFFERDESC);
    dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
    if (!Global::bInactivePause) // jeœli prze³¹czony w t³o ma nadal dzia³aæ
        dsbd.dwFlags |= DSBCAPS_GLOBALFOCUS; // to dŸwiêki maj¹ byæ równie¿ s³yszalne
    dsbd.dwBufferBytes = 0;
    dsbd.lpwfxFormat = NULL;

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

    // Set primary buffer format to 22kHz and 16-bit output.
    WAVEFORMATEX wfx;
    ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
    wfx.wFormatTag = WAVE_FORMAT_PCM;
    wfx.nChannels = 2;
    wfx.nSamplesPerSec = 44100;
    wfx.wBitsPerSample = 16;
    wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
    wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

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

    SAFE_RELEASE(pDSBPrimary);
};
开发者ID:shaxbee,项目名称:maszyna,代码行数:66,代码来源:Sound.cpp

示例15: init

	bool sound_manager::init()
	{
		window_.invisible().create();	// 透明ウィンドウにしておくこと

		HRESULT hr;

		// IDirectSound8インターフェイスの取得
		hr = DirectSoundCreate8(NULL, &dxs, NULL);
		if (FAILED(hr))
		{
			fw::popup("IDirectSound8インターフェイスの取得に失敗");
			return false;
		}

		//ここで協調レベルを設定
		hr = dxs->SetCooperativeLevel(window_.myhandle(), DSSCL_PRIORITY);
		if (FAILED(hr))
		{
			// 協調レベルの設定に失敗
			fw::popup("協調レベルの設定に失敗");
			return false;
		}

		// プライマリ・バッファの作成
		// DSBUFFERDESC構造体を設定
		DSBUFFERDESC dsbdesc;
		ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
		dsbdesc.dwSize = sizeof(DSBUFFERDESC);
		// プライマリ・バッファを指定
		dsbdesc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_PRIMARYBUFFER;
		dsbdesc.dwBufferBytes = 0;
		dsbdesc.lpwfxFormat = NULL;

		// バッファを作る
		LPDIRECTSOUNDBUFFER primarysb;
		hr = dxs->CreateSoundBuffer(&dsbdesc, &primarysb, NULL);
		if (FAILED(hr))
		{
			// バッファの作成に失敗
			fw::popup("プライマリ・バッファの作成に失敗");
			return false;
		}

		// プライマリ・バッファのWaveフォーマットを設定
		//    優先協調レベル以上の協調レベルが設定されている必要があります.
		WAVEFORMATEX pcmwf;
		ZeroMemory(&pcmwf, sizeof(WAVEFORMATEX));
		pcmwf.wFormatTag = WAVE_FORMAT_PCM;
		pcmwf.nChannels = 2;			// 2チャンネル(ステレオ)
		pcmwf.nSamplesPerSec = 44100;	// サンプリング・レート 44.1kHz
		pcmwf.nBlockAlign = 4;
		pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
		pcmwf.wBitsPerSample = 16;		// 16ビット
		hr = primarysb->SetFormat(&pcmwf);
		if (FAILED(hr))
		{
			fw::popup("プライマリ・バッファのフォーマット設定に失敗");
			return false;
		}

		return true;
	}
开发者ID:yuni-net,项目名称:simplect,代码行数:62,代码来源:sound_manager.cpp


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