Example #1
0
//-----------------------------------------------------------------------------
//	Создание 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;
}
Example #2
0
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;
}
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;
}
// 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;
}
Example #5
0
//-----------------------------------------------------------------------------
// 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;
}
Example #6
0
//===========================================================================
// 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);
}
Example #7
0
void sound_direct_sound::dsound_kill()
{
	// release the object
	if (m_dsound)
		m_dsound->Release();
	m_dsound = nullptr;
}
Example #8
0
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);
}
Example #9
0
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;
}
Example #10
0
//-----------------------------------------------------------------------------
// 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;
}
Example #11
0
/*------------------------------------------------------------------------
*
* 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;
}
Example #12
0
/*------------------------------------------------------------------------
*
* PROTOTYPE  :  uint16_t static DS_AllocBuffer(uint32_t size, uint32_t nSamplesPerSec, uint16_t nBitsPerSample, uint16_t nChannels, uint16_t channel, DWORD smode)
*
* DESCRIPTION :  Allocate a DirectSound secondary buffer.
*
*/
static uint16_t DS_AllocBuffer(uint32_t size, uint32_t nSamplesPerSec, uint16_t nBitsPerSample, uint16_t nChannels, short channel, DWORD smode)
{
	HRESULT  hr;
    PCMWAVEFORMAT   pwf;
    DS_handle      *hnd = channel>=0  ? g_pDSHandles + channel : &DS_SecBuffer;
    // Initialize
    sysMemZero(&pwf, sizeof(PCMWAVEFORMAT));
    pwf.wBitsPerSample =  nBitsPerSample;
    pwf.wf.nChannels =  nChannels;
    // Format Tag should be the same as the Primary (Compatiblity with some non certified drivers).
    pwf.wf.wFormatTag =  g_cDSPCMOutFormat.wFormatTag;
    pwf.wf.nSamplesPerSec  =  g_cDSPCMOutFormat.nSamplesPerSec ? g_cDSPCMOutFormat.nSamplesPerSec : nSamplesPerSec ;
    pwf.wf.nBlockAlign =  (uint16_t)(pwf.wf.nChannels *  (pwf.wBitsPerSample>>3));
    pwf.wf.nAvgBytesPerSec =  (uint32_t)pwf.wf.nSamplesPerSec * (uint32_t)pwf.wf.nBlockAlign;
    // Initialisation de la structure buffer
    sysMemZero(&DS_BufferDesc, sizeof(DSBUFFERDESC));
    DS_BufferDesc.dwSize =  sizeof(DSBUFFERDESC);
    DS_BufferDesc.dwFlags  =  smode;
    DS_BufferDesc.dwBufferBytes =  size;
    DS_BufferDesc.lpwfxFormat =  (LPWAVEFORMATEX) &pwf;
    // Creation du buffer son
    hr = g_lpDSDevice->CreateSoundBuffer( &DS_BufferDesc, &hnd->pbuffer, NULL);
    if (SYS_DXTRACE(hr))
    {
		return 0;
    }
    return (hr != DS_OK) ? (uint16_t)0 : channel<0 ? (uint16_t)0xff : (uint16_t)(channel+1);
}
Example #13
0
/*
==================
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" );
			// FIXME JA was DSSCL_NORMAL and Q3 says DSSCL_PRIORITY but the printf says setting normal
			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 = qfalse;
	memset ((void *)&dma, 0, sizeof (dma));
	CoUninitialize( );
}
Example #14
0
//-----------------------------------------------------------------------------
//	Проверка возможности использования алгоритма трехмерного звука
// на входе    :  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;
}
Example #15
0
static uint32_t DriverGetMemory(void)
{
    DSCAPS caps;
    sysMemZero(&caps, sizeof(DSCAPS));
    caps.dwSize = sizeof(DSCAPS);
    g_lpDSDevice->GetCaps(&caps);
    return caps.dwMaxContigFreeHwMemBytes;
}
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;
}
Example #17
0
//-----------------------------------------------------------------------------
//	Освобождение Direct Sound объекта
// на входе    :  direct   - указатель на Direct Sound объект
// на выходе   :	*
//-----------------------------------------------------------------------------
void ds_Release(LPDIRECTSOUND direct)
{
	// удаление объекта воспроизведения
	if (direct)
		direct->Release();

	// Освобождение COM
	CoUninitialize();
}
Example #18
0
// ==============================  INITIALIZE FORM =======================================
void TsounEditForm::DoFormInitialize()
{
	TTagEditForm::DoFormInitialize();

#if OPT_WINOS
	if( lpDirectSound )
		lpDirectSound->SetCooperativeLevel( GetWindow()->GetHWND(), DSSCL_NORMAL );
#endif
}
Example #19
0
ULONG STDMETHODCALLTYPE DirectSound::Release()
{
	ULONG result = m_ds->Release();
	if (!result)
	{
		delete this;
	}
	return result;
}
Example #20
0
/*
===============
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;
}
Example #21
0
		HRESULT create(LPDIRECTSOUND dsound)
		{
			assert(!m_buffer);
			DSBUFFERDESC desc;
			memset(&desc, 0, sizeof(desc));
			desc.dwSize = sizeof(desc);
			desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2;
			desc.lpwfxFormat = nullptr;
			return dsound->CreateSoundBuffer(&desc, &m_buffer, nullptr);
		}
Example #22
0
/*
=================
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 ();
	}
}
Example #23
0
static BRESULT dsoundcreate(HWND hWnd)
{
	// DirectSoundの初期化
	if (FAILED(DirectSoundCreate(0, &pDSound, 0))) {
		goto dscre_err;
	}
	if (FAILED(pDSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY)))
	{
		if (FAILED(pDSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL)))
		{
			goto dscre_err;
		}
	}
	return(SUCCESS);

dscre_err:
	RELEASE(pDSound);
	return(FAILURE);
}
Example #24
0
void SNDDMA_Activate() {
	if ( !pDS ) {
		return;
	}

	if ( DS_OK != pDS->SetCooperativeLevel( GMainWindow, DSSCL_PRIORITY ) ) {
		common->Printf( "sound SetCooperativeLevel failed\n" );
		SNDDMA_Shutdown();
	}
}
Example #25
0
// Secondary SoundBuffer erstellen und Wave-Daten aus der Datei fileName in den Buffer laden
int	MakeSoundBuffer(const char *fileName, LPDIRECTSOUNDBUFFER *lpDSB)
{
	DSBUFFERDESC         dsbd;          // SB Description
	BYTE                *pDSBuffData;   // SB Daten Adresse
	WAVEFORMATEX         waveFormat;    // Wave Format
	DWORD                dwDataLength;  // Länge der Wave Daten
	PBYTE                pbyWaveDaten;  // Eigentliche Wave Daten
	HRESULT              dsrval;        // Rückgabewert

	pbyWaveDaten = NULL;

	if(LoadWave(fileName, &waveFormat, &dwDataLength, &pbyWaveDaten))
	{
		MessageBox(NULL, "Error", "LoadWave()", NULL);
		return 1;
	}

	ZeroMemory(&dsbd,sizeof(DSBUFFERDESC));
	dsbd.dwSize = sizeof(DSBUFFERDESC);
	dsbd.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME |
				  DSBCAPS_CTRLFREQUENCY | DSBCAPS_STATIC;
	dsbd.dwBufferBytes = dwDataLength;	//Länge der Wave-Daten
	dsbd.lpwfxFormat = &waveFormat;		//Format der Wave-Daten

	dsrval = lpDS->CreateSoundBuffer(&dsbd, lpDSB, NULL);
	if (FAILED(dsrval))
	{
		MessageBox(NULL, "Error", "CreateSoundBuffer()", NULL);
		return 1;
	}

	// Sound Buffer verriegeln um Daten zu speichern
	dsrval = (*lpDSB)->Lock(0,dwDataLength,(LPVOID *)&pDSBuffData,
						   &dwDataLength,NULL,0,0);
	if (FAILED(dsrval))
	{
		MessageBox(NULL, "Error", "Lock()", NULL);
		return 1;
	}

	// Kopieren der Sounddaten in den Sound Buffer
	memcpy(pDSBuffData,pbyWaveDaten,dwDataLength);
	// Freigeben der Sounddaten (Werden jetzt nicht mehr gebraucht)
	free(pbyWaveDaten);

	// Sound Buffer entriegeln
	dsrval = (*lpDSB)->Unlock(pDSBuffData,dwDataLength,NULL,0);
	if (FAILED(dsrval))
	{
		MessageBox(NULL, "Error", "Unlock()", NULL);
		return 1;
	}

	return 0;
}
Example #26
0
bool Audio::PlayDuplicateWavFile(LPDIRECTSOUND lpDS,Audio* a) {
    if(lpDSB!=NULL)return false;
    lpDS->DuplicateSoundBuffer(a->GetWavBuffer(),&lpDSB);
    if(a->ex==true)
    {
        lpDSB->QueryInterface(IID_IDirectSound3DBuffer,(void **)&lp3D);
        lp3D->SetPosition(x,0.0f,y,DS3D_IMMEDIATE);
    }
    lpDSB->Play(0,0,0);
    return true;
}
Example #27
0
//-----------------------------------------------------------------------------
//	Получение параметров устройства воспроизведения
// на входе    :  direct   - указатель интерфейс Direct Sound
//  			  caps     - указатель на структуру описывающую параметры
//  						 устройства воспроизведения
// на выходе   :	успешность получения информации
//-----------------------------------------------------------------------------
int ds_GetCaps(LPDIRECTSOUND direct, LPDSCAPS caps)
{
	// проверка наличия объекта
	if (direct) {
		caps->dwSize = sizeof(DSCAPS);
		// получение свойств объекта
		if (direct->GetCaps(caps) == DS_OK)
			return true;
	}
	return false;
}
Example #28
0
LPDIRECTSOUNDBUFFER TSoundContainer::GetUnique(LPDIRECTSOUND pDS)
{
    if (!DSBuffer)
        return NULL;
    // jeœli siê dobrze zainicjowa³o
    LPDIRECTSOUNDBUFFER buff;
    pDS->DuplicateSoundBuffer(DSBuffer, &buff);
    if (buff)
        DSBuffers.push(buff);
    return DSBuffers.top();
};
Example #29
0
		HRESULT create(LPDIRECTSOUND dsound, DWORD size, WAVEFORMATEX &format)
		{
			assert(!m_buffer);
			DSBUFFERDESC desc;
			memset(&desc, 0, sizeof(desc));
			desc.dwSize = sizeof(desc);
			desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
			desc.dwBufferBytes = size;
			desc.lpwfxFormat = &format;
			m_size = size;
			return dsound->CreateSoundBuffer(&desc, &m_buffer, nullptr);
		}
int DSound_Init(void)
{
    // this function initializes the sound system
    static int first_time = 1; // used to track the first time the function
    // is entered

    // test for very first time
    if (first_time)
    {		
        // clear everything out
        memset(sound_fx,0,sizeof(pcm_sound)*MAX_SOUNDS);

        // reset first time
        first_time = 0;

        // create a directsound object
        if (FAILED(DirectSoundCreate(NULL, &lpds, NULL)))
            return(0);

        // set cooperation level
        if (FAILED(lpds->SetCooperativeLevel((HWND)main_window_handle,DSSCL_NORMAL)))
            return(0);

    } // end if

    // initialize the sound fx array
    for (int index=0; index<MAX_SOUNDS; index++)
    {
        // test if this sound has been loaded
        if (sound_fx[index].dsbuffer)
        {
            // stop the sound
            sound_fx[index].dsbuffer->Stop();

            // release the buffer
            sound_fx[index].dsbuffer->Release();

        } // end if

        // clear the record out
        memset(&sound_fx[index],0,sizeof(pcm_sound));

        // now set up the fields
        sound_fx[index].state = SOUND_NULL;
        sound_fx[index].id    = index;

    } // end for index

    // return sucess
    return(1);

} // end DSound_Init