本文整理汇总了C++中LPDIRECTSOUND8类的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUND8类的具体用法?C++ LPDIRECTSOUND8怎么用?C++ LPDIRECTSOUND8使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPDIRECTSOUND8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateBaseBuffer
//get the DIRECTSOUNDBUFFER8 interface
HRESULT CreateBaseBuffer(LPDIRECTSOUND8 lpDirectSound, LPDIRECTSOUNDBUFFER8 * ppDsb8){
WAVEFORMATEX wfx;
DSBUFFERDESC dsbdesc;
LPDIRECTSOUNDBUFFER pDsb = NULL;
HRESULT hr;
//set up WAV buffer format
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = 22050;
wfx.nBlockAlign = 4;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.wBitsPerSample = 16;
//set up DSBUFFERDESC structure
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
//the rule of using following flags is that use only what you will control
dsbdesc.dwFlags =
DSBCAPS_CTRLPAN |
DSBCAPS_CTRLVOLUME | //IDirectSound::SetVolume() is success only if this flag was set
DSBCAPS_CTRLFREQUENCY |
DSBCAPS_GLOBALFOCUS; //ensure that even if the window is in the backgroud,that mean you can hear the sound when you lose the focus of the window
dsbdesc.dwBufferBytes = 3 * wfx.nAvgBytesPerSec;//create a buffer that is big enough to hold 3 seconds of streaming data
dsbdesc.lpwfxFormat = &wfx;//if the was not specified, ds will place it in hardware-controlled memory.
//you can check the location of the buffer by using GetCaps() function,
//create buffer
hr = lpDirectSound->CreateSoundBuffer(&dsbdesc, &pDsb, NULL);
if (SUCCEEDED(hr)){
hr = pDsb->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)ppDsb8);
pDsb->Release();
}
//the created buffer owned by device object,and released when device object release the resources
//you can also create multiple buffer by using function IDirectSound8::DuplicateSoundBuffer(),but the memory is share with original buffer,so if one buffer changed,others will be reflected.
return hr;
}
示例2: sizeof
// Create
// create 'empty' sound buffer into the memory
HRESULT CSoundWave::Create( CSoundEngine& soundEngine,
DWORD dwFrequency,
DWORD dwBitsPerSample,
DWORD dwChannels,
DWORD dwBytes,
DWORD dwDuplicates,
DWORD dwFlags)
{
// set original freq
m_OriginalFrequency = dwFrequency;
HRESULT hres;
WAVEFORMATEX wfx;
DSBUFFERDESC desc;
// init the wave format
::memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = (WORD)dwChannels;
wfx.nSamplesPerSec = dwFrequency;
wfx.wBitsPerSample = (WORD)dwBitsPerSample;
wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
// init the buffer desc
::memset(&desc, 0, sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = dwFlags;
desc.dwBufferBytes = dwBytes;
desc.lpwfxFormat = &wfx;
// create sound buffer(s)...
LPDIRECTSOUND8 pDS = soundEngine.GetDirectSound();
m_ppDSB = new LPDIRECTSOUNDBUFFER8[dwDuplicates + 1];
if (!m_ppDSB)
{
return E_OUTOFMEMORY;
}
// set pointers in array to NULL
::memset(m_ppDSB, 0, sizeof(LPDIRECTSOUNDBUFFER8) * (dwDuplicates + 1));
m_dwBufferCount = dwDuplicates + 1;
// create the first sound buffer
// first sound buffer is special one,
// it is the only one that actually contains
// any sound data. The duplicate buffers have only
// separate play positions, pointing into the data
// in first buffer
LPDIRECTSOUNDBUFFER pDSB = NULL;
hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
if (FAILED(hres))
{
Release();
return hres;
}
// query the latest sound buffer interface
hres = pDSB->QueryInterface( IID_IDirectSoundBuffer8,
(void**)&m_ppDSB[0]);
pDSB->Release();
if (FAILED(hres))
{
Release();
return hres;
}
// create the duplicates
DWORD i;
for (i=0; i<dwDuplicates; i++)
{
if ((dwFlags & DSBCAPS_CTRLFX))
{
// real time effects required, all duplicate buffers
// must have their own wave data
hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
}
else
{
// no real time effect required, use duplicate buffers
// to save memory
hres = pDS->DuplicateSoundBuffer(m_ppDSB[0], &pDSB);
}
if (SUCCEEDED(hres))
{
hres = pDSB->QueryInterface( IID_IDirectSoundBuffer8,
(void**)&m_ppDSB[i + 1]);
pDSB->Release();
if (FAILED(hres))
{
Release();
return hres;
}
}
else
//.........这里部分代码省略.........
示例3: create_buffers
/**
* @brief Creates the primary buffer and the secondary buffers.
* @param[in] p_direct_sound_8 pointer to the IDirectSound8 interface. This interface is a factory for creating both the primary buffer and the secondary buffers.
* @param[out] pp_primary_buffer pointer to the memory location which will be written with the primary buffer interface pointer.
* @param[out] pp_secondary_buffer pointer to the memory location which will be written with the secondary buffer interface pointer.
* @param[in] p_wfe pointer to the WAVEFORMATEX structure. This parameter defines the buffer format (number of samples per second, how many bytes per sample and so on).
* @param[in] single_buffer_size size of the single play buffer
* @return
*/
static HRESULT create_buffers(LPDIRECTSOUND8 p_ds,
WAVEFORMATEX * p_wfex,
size_t number_of_chunks,
size_t single_buffer_size,
LPDIRECTSOUNDBUFFER * pp_primary_sound_buffer,
LPDIRECTSOUNDBUFFER8 * pp_secondary_sound_buffer)
{
HRESULT hr;
DSBUFFERDESC bufferDesc;
LPDIRECTSOUNDBUFFER lpDSB = NULL;
if (NULL != *pp_primary_sound_buffer || NULL != *pp_secondary_sound_buffer)
{
debug_outputln("%s %4.4u : %p %p", __FILE__, __LINE__, *pp_primary_sound_buffer, *pp_secondary_sound_buffer);
return E_INVALIDARG;
}
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
bufferDesc.dwSize = sizeof(bufferDesc);
bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
bufferDesc.guid3DAlgorithm = DS3DALG_DEFAULT;
/* All others must be null for primary buffer */
hr = p_ds->CreateSoundBuffer(&bufferDesc, pp_primary_sound_buffer, NULL);
if (FAILED(hr))
{
debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr);
goto error;
}
hr = (*pp_primary_sound_buffer)->SetFormat(p_wfex);
if (FAILED(hr))
{
debug_outputln("%s %4.4u : %8.8x", __FILE__, __LINE__, hr);
goto error;
}
get_buffer_caps("Primary: ", *pp_primary_sound_buffer);
/* Secondary buffer */
bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME /* The buffer has volume control capability. */
| DSBCAPS_CTRLPAN /* The buffer has pan control capability. */
| DSBCAPS_CTRLFREQUENCY /* The buffer has frequency control capability. */
| DSBCAPS_GLOBALFOCUS /* With this flag set, an application using DirectSound can continue to play its buffers if the user switches focus to another application, even if the new application uses DirectSound. */
| DSBCAPS_CTRLPOSITIONNOTIFY; /* The buffer has position notification capability. */
/* double buffering - one buffer being played, whereas the other is being filled in */
bufferDesc.dwBufferBytes = number_of_chunks * single_buffer_size;
bufferDesc.lpwfxFormat = p_wfex;
hr = p_ds->CreateSoundBuffer(&bufferDesc, &lpDSB, NULL);
if (FAILED(hr))
{
debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr);
goto error;
}
hr = lpDSB->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)pp_secondary_sound_buffer);
if (FAILED(hr))
{
debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr);
goto error;
}
get_buffer_caps("Secondary: ", *pp_secondary_sound_buffer);
if (NULL != lpDSB)
{
lpDSB->Release();
lpDSB = NULL;
}
return hr;
error:
if (NULL != *pp_secondary_sound_buffer)
{
(*pp_secondary_sound_buffer)->Release();
*pp_secondary_sound_buffer = NULL;
}
if (NULL != *pp_primary_sound_buffer)
{
(*pp_primary_sound_buffer)->Release();
*pp_primary_sound_buffer = NULL;
}
if (NULL != lpDSB)
{
lpDSB->Release();
lpDSB = NULL;
}
return hr;
}
示例4: tbLoadWAVFile
// ******************************************************************
// Laden einer WAV-Datei
LPDIRECTSOUNDBUFFER tbLoadWAVFile(LPDIRECTSOUND8 pDSound,
tbVFile* pVFile,
DWORD dwFlags,
GUID GUID3DAlgorithm)
{
HRESULT hResult;
tbRIFFHeader RIFFHeader;
tbWAVChunkHeader ChunkHeader;
BOOL bFormatChunkRead = FALSE;
BOOL bDataChunkRead = FALSE;
DWORD dwNumBytesToRead;
WAVEFORMATEX WaveFormat;
void* pSoundData = NULL;
DSBUFFERDESC BufferDesc;
LPDIRECTSOUNDBUFFER pSoundBuffer;
void* pSoundBufferData;
DWORD dwSoundBufferDataSize;
// Parameter prüfen
if(pDSound == NULL) TB_ERROR_NULL_POINTER("pDSound", NULL);
if(pVFile == NULL) TB_ERROR_NULL_POINTER("pVFile", NULL);
// RIFF-Header lesen und prüfen
if(pVFile->Read(sizeof(tbRIFFHeader), &RIFFHeader)) TB_ERROR("Fehler beim Lesen des RIFF-Headers!", NULL);
if(strnicmp(RIFFHeader.acRIFF, "RIFF", 4)) TB_ERROR("RIFF-Signatur nicht gefunden!", NULL);
if(strnicmp(RIFFHeader.acFormat, "WAVE", 4)) TB_ERROR("WAVE-Signatur nicht gefunden - die Datei ist keine WAV-Datei!", NULL);
// ------------------------------------------------------------------
// WAV-Chunks einlesen
while(TRUE)
{
// Chunk-Header lesen. Bei einem Lesefehler haben wir das Dateiende erreicht.
if(pVFile->Read(sizeof(tbWAVChunkHeader), &ChunkHeader)) break;
if(!strnicmp(ChunkHeader.acType, "fmt ", 4))
{
// Es ist der Format-Chunk!
// Prüfen, ob die Größe der Daten in Ordnung ist. Wenn sie größer ist als
// die Größe der WAVEFORMATEX-Struktur, dann lassen wir die restlichen Bytes weg.
dwNumBytesToRead = TB_MIN(ChunkHeader.dwDataSize, sizeof(WAVEFORMATEX));
if(pVFile->Read(dwNumBytesToRead, &WaveFormat)) TB_ERROR("Fehler beim Lesen des Soundformats!", NULL);
bFormatChunkRead = TRUE;
}
else if(!strnicmp(ChunkHeader.acType, "data", 4))
{
// Es ist der Daten-Chunk!
// Genügend Speicher reservieren und dann die Daten lesen.
pSoundData = tbMemAlloc(ChunkHeader.dwDataSize);
if(pSoundData == NULL) TB_ERROR_OUT_OF_MEMORY(NULL);
if(pVFile->Read(ChunkHeader.dwDataSize, pSoundData)) TB_ERROR("Fehler beim Lesen der Sounddaten!", NULL);
bDataChunkRead = TRUE;
}
else
{
// Unbekannter Chunk - überspringen
pVFile->Seek(TB_VFSO_CURSOR, ChunkHeader.dwDataSize);
}
}
// Prüfen, ob alle wichtigen Chunks vorhanden waren
if(!(bFormatChunkRead && bDataChunkRead))
{
// Fehler!
TB_SAFE_MEMFREE(pSoundData);
TB_ERROR("Die Chunks \"fmt \" und \"data\" müssen beide vorhanden sein!", NULL);
}
// ------------------------------------------------------------------
// DSBUFFERDESC-Struktur ausfüllen
BufferDesc.dwSize = sizeof(DSBUFFERDESC);
BufferDesc.dwFlags = dwFlags;
BufferDesc.dwBufferBytes = tbMemGetSize(pSoundData);
BufferDesc.dwReserved = 0;
BufferDesc.lpwfxFormat = &WaveFormat;
BufferDesc.guid3DAlgorithm = GUID3DAlgorithm;
// Puffer erstellen
if(FAILED(hResult = pDSound->CreateSoundBuffer(&BufferDesc,
&pSoundBuffer,
NULL)))
{
// Fehler!
TB_ERROR_DIRECTX("pDSound->CreateSoundBuffer", hResult, NULL);
}
// ------------------------------------------------------------------
// Puffer komplett sperren
hResult = pSoundBuffer->Lock(0, 0, &pSoundBufferData, &dwSoundBufferDataSize, NULL, NULL, DSBLOCK_ENTIREBUFFER);
if(FAILED(hResult))
{
// Fehler!
TB_SAFE_MEMFREE(pSoundData);
TB_SAFE_RELEASE(pSoundBuffer);
//.........这里部分代码省略.........
示例5: DS_addDeviceRef
bool DS_addDeviceRef(signed int deviceID)
{
HWND ownerWindow;
HRESULT res = DS_OK;
LPDIRECTSOUND8 devPlay;
LPDIRECTSOUNDCAPTURE8 devCapture;
LPGUID lpGuid = NULL;
if (g_audioDeviceCache[deviceID].dev == NULL)
{
/* Create DirectSound */
//TRACE1("Creating DirectSound object for device %d\n", deviceID);
lpGuid = &(g_audioDeviceCache[deviceID].guid);
if (isEqualGUID(lpGuid, NULL))
{
lpGuid = NULL;
}
if (g_audioDeviceCache[deviceID].isSource)
{
#if 0
//CoInitialize(NULL);
res = DirectSoundCreate8(lpGuid, &devPlay, NULL); //生成DirectSound接口对象
#else
res = CoInitializeEx(NULL, 0);
res = CoCreateInstance(CLSID_DirectSound8,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectSound8,
(LPVOID*)&devPlay);
devPlay->Initialize(NULL);
#endif
g_audioDeviceCache[deviceID].dev = (void*) devPlay;
}
else
{
res = DirectSoundCaptureCreate8(lpGuid, &devCapture, NULL);
g_audioDeviceCache[deviceID].dev = (void*) devCapture;
}
g_audioDeviceCache[deviceID].refCount = 0;
if (FAILED(res))
{
ERROR1("DS_addDeviceRef: ERROR: Failed to create DirectSound: %s", TranslateDSError(res));
g_audioDeviceCache[deviceID].dev = NULL;
return false;
}
if (g_audioDeviceCache[deviceID].isSource)
{
ownerWindow = GetForegroundWindow();
if (ownerWindow == NULL)
{
ownerWindow = GetDesktopWindow();
}
//TRACE0("DS_addDeviceRef: Setting cooperative level\n");
res = devPlay->SetCooperativeLevel(ownerWindow, DSSCL_PRIORITY); //设置应用程序对声音设备的合作级别
if (FAILED(res))
{
ERROR1("DS_addDeviceRef: ERROR: Failed to set cooperative level: %s", TranslateDSError(res));
return false;
}
}
}
g_audioDeviceCache[deviceID].refCount++;
return true;
}
示例6: 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)) {
//.........这里部分代码省略.........
示例7: main
int main()
{
using namespace flamenco;
LPDIRECTSOUND8 directSound;
// Создаем интерфейс DirectSound.
check_directx(DirectSoundCreate8(&GUID_NULL, &directSound, NULL));
check_directx(directSound->SetCooperativeLevel(GetForegroundWindow(), DSSCL_PRIORITY));
// Получаем первичный буфер.
LPDIRECTSOUNDBUFFER primaryBuffer = NULL;
DSBUFFERDESC descr;
ZeroMemory(&descr, sizeof(DSBUFFERDESC));
descr.dwSize = sizeof(DSBUFFERDESC);
descr.dwFlags = DSBCAPS_PRIMARYBUFFER;
descr.lpwfxFormat = NULL;
check_directx(directSound->CreateSoundBuffer(&descr, &primaryBuffer, NULL));
// Изменяем формат первичного буфера.
WAVEFORMATEX wfx;
ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
wfx.cbSize = sizeof(WAVEFORMATEX);
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = FREQUENCY;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
wfx.nAvgBytesPerSec = (u32)wfx.nSamplesPerSec * wfx.nBlockAlign;
check_directx(primaryBuffer->SetFormat(&wfx));
primaryBuffer->Release();
// Формат буфера микшера.
const u32 MIXER_BUFFER_SIZE_IN_BYTES = MIXER_BUFFER_SIZE_IN_SAMPLES * sizeof(s16);
// Размер звукового буфера должен быть больше 100 ms, иначе GetCurrentPosition()
// будет выдавать неправильные данные.
const u32 SOUND_BUFFER_SIZE_IN_BYTES = 10 * MIXER_BUFFER_SIZE_IN_BYTES;
DSBUFFERDESC desc;
ZeroMemory(&desc, sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
desc.dwBufferBytes = SOUND_BUFFER_SIZE_IN_BYTES;
desc.guid3DAlgorithm = DS3DALG_DEFAULT;
desc.lpwfxFormat = &wfx;
// Создаем буфер.
LPDIRECTSOUNDBUFFER soundBuffer = NULL;
check_directx(directSound->CreateSoundBuffer(&desc, &soundBuffer, NULL));
//reference<stream<ogg_decoder> > sound = stream<ogg_decoder>::create(std::auto_ptr<source>(new file_source("input.ogg")));
// Инициализация flamenco.
mixer & mixer = mixer::singleton();
reference<sound_stream_base> sound = stream<wavpack_decoder>::create(std::auto_ptr<source>(new file_source("input.wv")));
//assert(!src.get());
mixer.attach(sound);
/*
reference<pin> sine = sine::create(400);
reference<ogg> wave = ogg::create("input.ogg");
reference<pin> noise = noise::create();
reference<volume_pan> vp = volume_pan::create(sound, 1.0f, 0.0f);
//mixer.attach(sine);
mixer.attach(vp);
//mixer.attach(noise);
*/
// Заполнение звукового буфера.
s16 * bufferPtr;
u32 bufferSize;
check_directx(soundBuffer->Lock(0, 0, reinterpret_cast<void **>(&bufferPtr), &bufferSize,
NULL, NULL, DSBLOCK_ENTIREBUFFER));
// Заполняем обе половинки буфера.
mixer.mix(bufferPtr);
mixer.mix(bufferPtr + MIXER_BUFFER_SIZE_IN_SAMPLES);
check_directx(soundBuffer->Unlock(bufferPtr, bufferSize, NULL, 0));
// Проигрываем звук и дописываем данные по ходу.
soundBuffer->Play(0, 0, DSBPLAY_LOOPING);
u32 writeOffset = MIXER_BUFFER_SIZE_IN_BYTES * 2;
while (true)
{
u32 cursorPos;
soundBuffer->GetCurrentPosition(&cursorPos, NULL);
// Определяем, нужно ли дописать очередную порцию данных.
u32 offset = (SOUND_BUFFER_SIZE_IN_BYTES + writeOffset - cursorPos) % SOUND_BUFFER_SIZE_IN_BYTES;
if (offset > MIXER_BUFFER_SIZE_IN_BYTES)
{
check_directx(soundBuffer->Lock(writeOffset, MIXER_BUFFER_SIZE_IN_BYTES,
reinterpret_cast<void **>(&bufferPtr), &bufferSize,
NULL, NULL, 0));
mixer.mix(bufferPtr);
check_directx(soundBuffer->Unlock(bufferPtr, bufferSize, NULL, 0));
writeOffset = (writeOffset + MIXER_BUFFER_SIZE_IN_BYTES) % SOUND_BUFFER_SIZE_IN_BYTES;
}
//.........这里部分代码省略.........
示例8: ReleaseDXSound
BOOL COggDlg::ReleaseDXSound(void)
{
if(m_ds){
Closeds();
if(m_dsb3d != NULL){m_dsb3d->Release();m_dsb3d =NULL;}
if(m_dsb != NULL) {m_dsb->Release();m_dsb=NULL;}
if (m_dsb1 != NULL) { m_dsb1->Release(); m_dsb1 = NULL; }
if(m_lpDS3DBuffer != NULL){m_lpDS3DBuffer->Release();}
m_dsb =NULL;
m_lpDS3DBuffer= NULL;
if(m_p!=NULL){m_p->Release();m_p=NULL;}
if(m_ds){
m_ds->Release();
m_ds = NULL;
}
}
return TRUE;
}
示例9: 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;
}
示例10: 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;
}
示例11: SNDDMA_InitDirect
/*
==================
SNDDMA_InitDirect
Direct-Sound support
==================
*/
sndinitstat SNDDMA_InitDirect (void)
{
DSCAPS dscaps;
HRESULT hresult;
dma.channels = CHANNELS;
dma.samplebits = SAMPLEBITS;
Com_Printf( "Initializing DirectSound 8\n");
if ( !hInstDS )
{
Com_Printf( "...loading dsound.dll: " );
hInstDS = LoadLibrary("dsound.dll");
if (hInstDS == NULL)
{
Com_Printf ("failed\n");
return SIS_FAILURE;
}
Com_Printf ("ok\n");
pDirectSoundCreate8 = GetProcAddress(hInstDS,"DirectSoundCreate8");
if (!pDirectSoundCreate8)
{
Com_Printf ("*** couldn't get DirectSound 8 process address ***\n");
return SIS_FAILURE;
}
}
Com_Printf( "...creating DirectSound 8 object: " );
while ( ( hresult = pDirectSoundCreate8( NULL, &pDS, NULL ) ) != DS_OK )
{
if (hresult != DSERR_ALLOCATED)
{
Com_Printf( "failed\n" );
return SIS_FAILURE;
}
if (MessageBox (NULL,
"The sound hardware is in use by another application.\n\n"
"Select Retry to try to start sound again or Cancel to run with no sound.",
"Sound not available",
MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
{
Com_Printf ("failed, hardware already in use\n" );
return SIS_NOTAVAIL;
}
}
Com_Printf( "ok\n" );
dscaps.dwSize = sizeof(dscaps);
#ifdef QDSNDCOMPILERHACK
if ( DS_OK != pDS->lpVtbl->GetCaps( pDS, &dscaps ) )
#else
if ( DS_OK != pDS->GetCaps( &dscaps ) )
#endif
{
Com_Printf ("*** couldn't get DirectSound 8 caps ***\n");
}
if ( dscaps.dwFlags & DSCAPS_EMULDRIVER )
{
Com_Printf ("...no DirectSound 8 driver found\n" );
FreeSound();
return SIS_FAILURE;
}
if ( !DS_CreateBuffers() )
return SIS_FAILURE;
dsound_init = 1;
Com_Printf("...completed successfully\n" );
return SIS_SUCCESS;
}
示例12: FreeSound
/*
==================
FreeSound
==================
*/
void FreeSound (void)
{
int i;
Com_Printf( "Shutting down sound system\n" );
if ( pDS )
DS_DestroyBuffers();
if ( hWaveOut )
{
Com_Printf( "...resetting waveOut\n" );
waveOutReset (hWaveOut);
if (lpWaveHdr)
{
Com_Printf( "...unpreparing headers\n" );
for (i=0 ; i< WAV_BUFFERS ; i++)
waveOutUnprepareHeader (hWaveOut, lpWaveHdr+i, sizeof(WAVEHDR));
}
Com_Printf( "...closing waveOut\n" );
waveOutClose (hWaveOut);
if (hWaveHdr)
{
Com_Printf( "...freeing WAV header\n" );
GlobalUnlock(hWaveHdr);
GlobalFree(hWaveHdr);
}
if (hData)
{
Com_Printf( "...freeing WAV buffer\n" );
GlobalUnlock(hData);
GlobalFree(hData);
}
}
if ( pDS )
{
Com_Printf( "...releasing DirectSound 8 object\n" );
#ifdef QDSNDCOMPILERHACK
pDS->lpVtbl->Release(pDS);
#else
pDS->Release();
#endif
}
if ( hInstDS )
{
Com_Printf( "...freeing dsound.dll\n" );
FreeLibrary( hInstDS );
hInstDS = NULL;
}
pDS = NULL;
pDSBuf = NULL;
pDSPBuf = NULL;
hWaveOut = 0;
hData = 0;
hWaveHdr = 0;
lpData = NULL;
lpWaveHdr = NULL;
dsound_init = 0;
wav_init = 0;
}
示例13: 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);
//.........这里部分代码省略.........
示例14: KillDSound
void KillDSound()
{
ds8->Release();
}
示例15: SNDDXInit
int SNDDXInit(int buffersize)
{
DSBUFFERDESC dsbdesc;
WAVEFORMATEX wfx;
HRESULT ret;
char tempstr[512];
if (FAILED(ret = DirectSoundCreate8(NULL, &lpDS8, NULL)))
{
sprintf(tempstr, "DirectSound8Create error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
return -1;
}
if (FAILED(ret = lpDS8->SetCooperativeLevel(MainWindow->getHWnd(), DSSCL_PRIORITY)))
{
sprintf(tempstr, "IDirectSound8_SetCooperativeLevel error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
return -1;
}
memset(&dsbdesc, 0, sizeof(dsbdesc));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbdesc.dwBufferBytes = 0;
dsbdesc.lpwfxFormat = NULL;
if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB, NULL)))
{
sprintf(tempstr, "Error when creating primary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
return -1;
}
soundbufsize = buffersize * 2; // caller already multiplies buffersize by 2
soundoffset = 0;
memset(&wfx, 0, sizeof(wfx));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = DESMUME_SAMPLE_RATE;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
if (FAILED(ret = lpDSB->SetFormat(&wfx)))
{
sprintf(tempstr, "IDirectSoundBuffer8_SetFormat error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
return -1;
}
memset(&dsbdesc, 0, sizeof(dsbdesc));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS |
DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
DSBCAPS_LOCHARDWARE;
dsbdesc.dwBufferBytes = soundbufsize;
dsbdesc.lpwfxFormat = &wfx;
if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)))
{
if (ret == DSERR_CONTROLUNAVAIL ||
ret == DSERR_INVALIDCALL ||
ret == E_FAIL ||
ret == E_NOTIMPL)
{
// Try using a software buffer instead
dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS |
DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
DSBCAPS_LOCSOFTWARE;
if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)))
{
sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
return -1;
}
}
else
{
sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
return -1;
}
}
lpDSB2->Play(0, 0, DSBPLAY_LOOPING);
if ((stereodata16 = new s16[soundbufsize / sizeof(s16)]) == NULL)
return -1;
memset(stereodata16, 0, soundbufsize);
soundvolume = DSBVOLUME_MAX;
issoundmuted = 0;
doterminate = false;
terminated = false;
CreateThread(0,0,SNDDXThread,0,0,0);
//.........这里部分代码省略.........