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


C++ LPDIRECTSOUND类代码示例

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


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

示例1: ds_Create

//-----------------------------------------------------------------------------
//	Создание Direct Sound объекта
// на входе    :  window		 - идентификатор окна
//  			  clsid_direct   - идентификатор Direct Sound
//  			  device		 - идентификатор устройства воспроизведения
//  			  level 		 - уровень кооперации
// на выходе   :	указатель на созданный Direct Sound объект, если значение
//  			  равно 0 значит создание не состоялось
//-----------------------------------------------------------------------------
LPDIRECTSOUND ds_Create(HWND window, REFCLSID clsid_direct, LPGUID device,
	int level)
{
	// установка переменных
	LPDIRECTSOUND direct = 0;

	// Инициализация COM
	CoInitialize(NULL);

	// Создание Direct Sound обьекта
	if (CoCreateInstance(clsid_direct,
			NULL,
			CLSCTX_INPROC_SERVER,
			IID_IDirectSound,
			(void * *) &direct) != DS_OK)
		return false;

	// инициализация устройства воспроизведения
	if (direct->Initialize(device) != DS_OK)
		return false;

	// установка приоритетного режима
	if (direct->SetCooperativeLevel(window, level) != DS_OK)
		return false;

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

示例2: CreateDSBuffer

AUI_ERRCODE aui_DirectSound::CreateDSBuffer() 
{ 
	PCMWAVEFORMAT pcmwf; 
	DSBUFFERDESC dsbdesc; 
	LPDIRECTSOUND	dsHandle; 

	aui_DirectAudioManager *audioManager =
		(aui_DirectAudioManager *)(void *)g_ui->TheAudioManager();

  
  memset(&pcmwf, 0, sizeof(PCMWAVEFORMAT)); 
  pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM; 
  pcmwf.wf.nChannels = 1; 
  pcmwf.wf.nSamplesPerSec = 22050; 
  pcmwf.wf.nBlockAlign = 1; 
  pcmwf.wf.nAvgBytesPerSec = pcmwf.wf.nSamplesPerSec * pcmwf.wf.nBlockAlign; 
  pcmwf.wBitsPerSample = 8; 

  memset(&dsbdesc, 0, sizeof(DSBUFFERDESC)); 
  dsbdesc.dwSize = sizeof(DSBUFFERDESC); 
  dsbdesc.dwFlags =   DSBCAPS_STATIC;
  dsbdesc.dwBufferBytes = m_size; 
  dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf; 

	dsHandle = audioManager->GetdDSHandle();
	
	if (dsHandle->CreateSoundBuffer( &dsbdesc, &dsb, NULL) < DS_OK)
		return AUI_ERRCODE_MEMALLOCFAILED;

	return AUI_ERRCODE_OK;
}
开发者ID:talentlesshack,项目名称:C2P2,代码行数:31,代码来源:aui_directsound.cpp

示例3: DOUT

// 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

示例4: CreateDSBuffer

//===========================================================================
// CreateDSBuffer
//===========================================================================
int CreateDSBuffer(DWORD flags, int samples, int freq, int bits, int channels, 
				   LPDIRECTSOUNDBUFFER *bufAddr)
{
	DSBUFFERDESC	bufd;
	WAVEFORMATEX	form;
	DWORD			dataBytes = samples * bits/8 * channels;
	
	// Prepare the buffer description.
	memset(&bufd, 0, sizeof(bufd));
	bufd.dwSize = sizeof(bufd);
	bufd.dwFlags = flags;
	bufd.dwBufferBytes = dataBytes;
	bufd.lpwfxFormat = &form;

	// Prepare the format description.
	memset(&form, 0, sizeof(form));
	form.wFormatTag = WAVE_FORMAT_PCM;
	form.nChannels = channels;
	form.nSamplesPerSec = freq;
	form.nBlockAlign = channels * bits/8;
	form.nAvgBytesPerSec = form.nSamplesPerSec * form.nBlockAlign;
	form.wBitsPerSample = bits;

	return dsound->CreateSoundBuffer(&bufd, bufAddr, NULL);
}
开发者ID:amitahire,项目名称:development,代码行数:28,代码来源:driver_sndcmp.cpp

示例5: CreateSoundBuffer

BOOL CDSBuffer::CreateSoundBuffer(LPDIRECTSOUND lpDS, DWORD dwFlags, DWORD dwBufSize, DWORD dwFreq, DWORD dwBitsPerSample, DWORD dwBlkAlign, BOOL bStereo)
{
	PCMWAVEFORMAT pcmwf;
	DSBUFFERDESC dsbdesc;
	
	// Set up wave format structure.
	memset( &pcmwf, 0, sizeof(PCMWAVEFORMAT) );
	pcmwf.wf.wFormatTag         = WAVE_FORMAT_PCM;      
	pcmwf.wf.nChannels          = bStereo ? 2 : 1;
	pcmwf.wf.nSamplesPerSec     = dwFreq;
	pcmwf.wf.nBlockAlign        = (WORD)dwBlkAlign;
	pcmwf.wf.nAvgBytesPerSec    = pcmwf.wf.nSamplesPerSec * pcmwf.wf.nBlockAlign;
	pcmwf.wBitsPerSample        = (WORD)dwBitsPerSample;
	
	// Set up DSBUFFERDESC structure.
	memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));  // Zero it out. 
	dsbdesc.dwSize              = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags             = dwFlags;
	dsbdesc.dwBufferBytes       = dwBufSize; 
	dsbdesc.lpwfxFormat         = (LPWAVEFORMATEX)&pcmwf;
	
	if (DS_OK != lpDS->CreateSoundBuffer(&dsbdesc, &m_lpDSBuffer, NULL))
	{
		MessageBox(g_hWnd,"Error - DS - CreateSoundBuffer","Error",MB_OK);
		return FALSE;
	}
	
	return TRUE;
}
开发者ID:codedhead,项目名称:ra2td,代码行数:29,代码来源:DSBuffer.cpp

示例6: DSUtil_LoadSoundBuffer

//-----------------------------------------------------------------------------
// Name: DSUtil_LoadSoundBuffer()
// Desc:
//-----------------------------------------------------------------------------
LPDIRECTSOUNDBUFFER DSUtil_LoadSoundBuffer( LPDIRECTSOUND pDS, LPCTSTR strName )
{
    LPDIRECTSOUNDBUFFER pDSB = NULL;
    DSBUFFERDESC        dsbd;
    BYTE*               pbWaveData;

    ZeroMemory( &dsbd, sizeof(dsbd) );
    dsbd.dwSize  = sizeof(dsbd);
    dsbd.dwFlags = DSBCAPS_STATIC|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|
                   DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPOSITIONNOTIFY;

    if( SUCCEEDED( DSUtil_GetWaveResource( NULL, strName, &dsbd.lpwfxFormat,
                                           &pbWaveData, &dsbd.dwBufferBytes ) ) )
    {

        if( SUCCEEDED( pDS->CreateSoundBuffer( &dsbd, &pDSB, NULL ) ) )
        {
            if( FAILED( DSUtil_FillSoundBuffer( pDSB, pbWaveData,
                                                dsbd.dwBufferBytes ) ) )
            {
                pDSB->Release();
                pDSB = NULL;
            }
        }
        else
        {
            pDSB = NULL;
        }
    }

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

示例7: ds_TestAlgorithm

//-----------------------------------------------------------------------------
//	Проверка возможности использования алгоритма трехмерного звука
// на входе    :  direct   - указатель интерфейс Direct Sound
//  			  alg      - тестируемый алгорим
// на выходе   :	успешность использования
//-----------------------------------------------------------------------------
int ds_TestAlgorithm(LPDIRECTSOUND direct, int alg)
{
	// объявление переменных
	int ret;
	DSBUFFERDESC dsbd;
	WAVEFORMATEX wfx;
	LPDIRECTSOUNDBUFFER buffer;

	// заполним структуру с форматом
	wfx.wFormatTag = 1;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = 44100;
	wfx.wBitsPerSample = 16;
	wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample) >> 3;
	wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
	wfx.cbSize = 0;

	// проверка наличия объекта воспроизведения
	if (direct) {
		// занесение данных вторичного буфера
		ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
		dsbd.dwSize = sizeof(DSBUFFERDESC);
		dsbd.dwFlags = DSBCAPS_STATIC |
			DSBCAPS_CTRLFREQUENCY |
			DSBCAPS_CTRLVOLUME |
			DSBCAPS_GLOBALFOCUS |
			DSBCAPS_CTRL3D |
			DSBCAPS_MUTE3DATMAXDISTANCE;
		dsbd.dwBufferBytes = 128;
		dsbd.lpwfxFormat = &wfx;
		/* !!! убрать !!!
					// подбор способа общета трехмерного звука
					switch(alg)
				  {
						case 0x0:
						dsbd.guid3DAlgorithm = DS3DALG_DEFAULT;
						break;
						case 0x1:
						dsbd.guid3DAlgorithm = DS3DALG_NO_VIRTUALIZATION;
						break;
						case 0x2:
						dsbd.guid3DAlgorithm = DS3DALG_HRTF_FULL;
						break;
						case 0x3:
						dsbd.guid3DAlgorithm = DS3DALG_HRTF_LIGHT;
						break;
					}*/

		// Создание вторичного буфера
		ret = (direct->CreateSoundBuffer(&dsbd, & buffer, NULL) == DS_OK) ?
			true :
			false;
		if (ret)
			buffer->Release();
	}

	// вернем результат
	return ret;
}
开发者ID:doveiya,项目名称:isilme,代码行数:65,代码来源:DirectSound.cpp

示例8: memset

BOOL LC3Sound::AppCreateWritePrimaryBuffer(
    LPDIRECTSOUND lpDirectSound,
    LPDIRECTSOUNDBUFFER *lplpDsb,
    HWND hwnd)
{
    DSBUFFERDESC dsbdesc;
    HRESULT hr;
    WAVEFORMATEX pcmwf;

    // Set up wave format structure.
    memset(&pcmwf, 0, sizeof(WAVEFORMATEX));
    pcmwf.wFormatTag 		= WAVE_FORMAT_PCM;
    
    pcmwf.nChannels = 1;
    pcmwf.nSamplesPerSec		= 22050;
    pcmwf.wBitsPerSample		= 8;
    pcmwf.nBlockAlign			= pcmwf.nChannels * (pcmwf.wBitsPerSample/8);
    pcmwf.nAvgBytesPerSec		= pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
    
    // Set up DSBUFFERDESC structure.
    memset(&dsbdesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
    dsbdesc.dwSize = sizeof(DSBUFFERDESC);
    dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;	//;	//DSBCAPS_GLOBALFOCUS;	//;
    dsbdesc.dwBufferBytes = 0; // Buffer size is determined
                               // by sound hardware.
    dsbdesc.lpwfxFormat = NULL; // Must be NULL for primary buffers.
    // Obtain write-primary cooperative level.
    hr = lpDirectSound->SetCooperativeLevel(hwnd, DSSCL_PRIORITY);
    if(DS_OK == hr)
    {
        // Succeeded! Try to create buffer.
        hr = lpDirectSound->CreateSoundBuffer(
            &dsbdesc, lplpDsb, NULL);
        if(DS_OK == hr) {
            // Succeeded! Set primary buffer to desired format.
            hr = (*lplpDsb)->SetFormat(&pcmwf);
            (*lplpDsb)->Play(0, 0, DSBPLAY_LOOPING);
            return TRUE;
        }
    }
    // If we got here, then we failed SetCooperativeLevel.
    // CreateSoundBuffer, or SetFormat.
    *lplpDsb = NULL;
    return FALSE;
}
开发者ID:MaddTheSane,项目名称:lc3tonegenerator,代码行数:45,代码来源:SoundHandler.cpp

示例9: ds_Release

//-----------------------------------------------------------------------------
//	Освобождение Direct Sound объекта
// на входе    :  direct   - указатель на Direct Sound объект
// на выходе   :	*
//-----------------------------------------------------------------------------
void ds_Release(LPDIRECTSOUND direct)
{
	// удаление объекта воспроизведения
	if (direct)
		direct->Release();

	// Освобождение COM
	CoUninitialize();
}
开发者ID:doveiya,项目名称:isilme,代码行数:14,代码来源:DirectSound.cpp

示例10: idWaveFile

/*
===============
idAudioHardwareWIN32::Create
===============
*/
int idAudioHardwareWIN32::Create(idAudioBuffer **ppSound,
                                 const char *strWaveFileName,
                                 dword dwCreationFlags)
{
	int hr;
	LPDIRECTSOUNDBUFFER   apDSBuffer     = NULL;
	dword                 dwDSBufferSize = NULL;
	idWaveFile          *pWaveFile      = NULL;

	if (m_pDS == NULL)
		return -1;

	if (strWaveFileName == NULL || ppSound == NULL)
		return -1;

	pWaveFile = new idWaveFile();

	pWaveFile->Open(strWaveFileName, NULL);

	if (pWaveFile->GetOutputSize() == 0)     {
		// Wave is blank, so don't create it.
		hr = E_FAIL;
		goto LFail;
	}

	// Make the DirectSound buffer the same size as the wav file
	dwDSBufferSize = pWaveFile->GetOutputSize();

	// Create the direct sound buffer, and only request the flags needed
	// since each requires some overhead and limits if the buffer can
	// be hardware accelerated
	DSBUFFERDESC dsbd;
	memset(&dsbd, 0, sizeof(DSBUFFERDESC));
	dsbd.dwSize          = sizeof(DSBUFFERDESC);
	dsbd.dwFlags         = dwCreationFlags;
	dsbd.dwBufferBytes   = dwDSBufferSize;
	dsbd.guid3DAlgorithm = GUID_NULL;
	dsbd.lpwfxFormat     = (WAVEFORMATEX *)&pWaveFile->mpwfx;

	// DirectSound is only guarenteed to play PCM data.  Other
	// formats may or may not work depending the sound card driver.
	if (FAILED(hr = m_pDS->CreateSoundBuffer(&dsbd, &apDSBuffer, NULL)))
		return -1;

	// Create the sound
	*ppSound = new idAudioBufferWIN32(apDSBuffer, dwDSBufferSize, pWaveFile);

	pWaveFile->Close();

	return 0;

LFail:
	// Cleanup
	SAFE_DELETE(pWaveFile);
	return -1;
}
开发者ID:AreaScout,项目名称:dante-doom3-odroid,代码行数:61,代码来源:win_snd.cpp

示例11: Open

int audioStreamer_ds::Open(int iswrite, int srate, int nch, int bps, int sleep, int nbufs, int bufsize, GUID *device)
{
  // todo: use device
  m_sleep = sleep >= 0 ? sleep : 0;

  GUID zero={0,};
  if (!memcmp(device,&zero,sizeof(zero))) device=NULL;

  m_nch = nch;
  m_srate=srate;
  m_bps=bps;

  int fmt_align=(bps>>3)*nch;
  int fmt_mul=fmt_align*srate;
  WAVEFORMATEX wfx={
		WAVE_FORMAT_PCM,
		nch,
		srate,
		fmt_mul,
		fmt_align,
		bps,
		0
	};
  m_totalbufsize=nbufs*bufsize;

  if (iswrite)
  {
      DirectSoundCreate(device,&m_lpds,NULL);

      if (m_lpds)
      {
        HWND hWnd = GetForegroundWindow();
        if (hWnd == NULL) hWnd = GetDesktopWindow();
        m_lpds->SetCooperativeLevel(hWnd,DSSCL_PRIORITY);

        // create a secondary buffer for now
        DSBUFFERDESC ds={sizeof(ds),DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_GLOBALFOCUS,m_totalbufsize,0,&wfx, };
        m_lpds->CreateSoundBuffer(&ds,&m_outbuf,NULL);
        
      }

  }
  else
  {
    DirectSoundCaptureCreate(device,&m_lpcap,NULL);
    if (m_lpcap)
    {
      DSCBUFFERDESC ds={sizeof(ds),0,m_totalbufsize,0,&wfx, };
      m_lpcap->CreateCaptureBuffer(&ds,&m_inbuf,NULL);
    }
  }

  m_bufsize=bufsize;


  return 0;
}
开发者ID:libninjam,项目名称:libninjam-win,代码行数:57,代码来源:audiostream_win32.cpp

示例12: DSUtil_InitDirectSound

//-----------------------------------------------------------------------------
// Name: DSUtil_InitDirectSound()
// Desc: 
//-----------------------------------------------------------------------------
HRESULT DSUtil_InitDirectSound( HWND hWnd )
{
    if( FAILED( DirectSoundCreate( NULL, &g_pDS, NULL ) ) )
        return E_FAIL;

    if( FAILED( g_pDS->SetCooperativeLevel( hWnd, DSSCL_NORMAL ) ) )
    {
        g_pDS->Release();
        g_pDS = NULL;
        return E_FAIL;
    }

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

示例13: dsound_kill

void sound_direct_sound::dsound_kill()
{
	// release the object
	if (m_dsound)
		m_dsound->Release();
	m_dsound = nullptr;
}
开发者ID:bradhugh,项目名称:mame,代码行数:7,代码来源:direct_sound.cpp

示例14: ReplicateSound

int ReplicateSound(int source_id)
{
    if (source_id != -1) {
        // duplicate the sound buffer
        // first hunt for an open id
        for (int id = 0; id < MAX_SOUNDS; id++) {
            // is this sound open?
            if (sound_fx[id].state == SOUND_NULL) {
                // first make an identical copy
                sound_fx[id] = sound_fx[source_id];
                
                // now actually replicate the directsound buffer
                if (lpDS->DuplicateSoundBuffer(sound_fx[source_id].dsbuffer, &sound_fx[id].dsbuffer) != DS_OK) {
                    // reset sound to NULL
                    sound_fx[id].dsbuffer = NULL;
                    sound_fx[id].state    = SOUND_NULL;
                    // return error
                    return(-1);
                }
                
                // now fix up id
                sound_fx[id].id = id;
                // return replicated sound
                return(id);
            }
        }
    } else {
        return(-1);
    }
    
    // else failure
    return(-1);
}
开发者ID:mreiferson,项目名称:hajiworld,代码行数:33,代码来源:hwdsound.cpp

示例15: DSS_DuplicateHandle

/*------------------------------------------------------------------------
*
* PROTOTYPE  :  static int DSS_RegisterHandle(V3XA_HANDLE *sam, int channel)
*
* DESCRIPTION :  Try to duplicate the sample.
*
*/
static int DSS_DuplicateHandle(V3XA_HANDLE *sam, int channel)
{

	HRESULT  hr;
    int i;
    DS_handle *hnd = g_pDSHandles + channel;
    for  (i=0;i<RLX.Audio.ChannelToMix;i++)
    {
        DS_handle *p = g_pDSHandles + i ;
        if ((i!=channel)&&(p->sample == sam))
        {
            // Same on a different channel
            hnd->sample = sam;
            hr = g_lpDSDevice->DuplicateSoundBuffer(p->pbuffer, &hnd->pbuffer);
            if (SYS_DXTRACE(hr))
            {
                return -1;
            }
            DS_Register3D(sam, hnd, 0);
            sam->sampleFormat&=~V3XA_FMTVOLATILE;
            return i;
        }
    }
    return -1;
}
开发者ID:cbxbiker61,项目名称:nogravity,代码行数:32,代码来源:snd_ds6.cpp


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