本文整理汇总了C++中IDirectSoundBuffer8类的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer8类的具体用法?C++ IDirectSoundBuffer8怎么用?C++ IDirectSoundBuffer8使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDirectSoundBuffer8类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AppDebugAssert
void SoundLibrary3dDirectSound::DisableDspFX( int _channel )
{
int errCode;
AppDebugAssert(GetNumFilters(_channel) > 0);
DirectSoundChannel *channel;
if (_channel == m_musicChannelId) channel = m_musicChannel;
else channel = &m_channels[_channel];
IDirectSoundBuffer8 *buffer = (IDirectSoundBuffer8 *) channel->m_bufferInterface;
//
// Stop the channel
errCode = buffer->Stop();
SOUNDASSERT( errCode, "Direct sound couldn't stop a secondary buffer" );
//
// Shut down the filters
int numDxFilters = 0;
for (int i = 0; i < NUM_FILTERS; ++i)
{
SoundLibFilter *filter = &channel->m_dspFX[i];
if (filter->m_userFilter != NULL)
{
delete filter->m_userFilter;
filter->m_userFilter = NULL;
}
else if (filter->m_dxFilter)
{
numDxFilters++;
}
filter->m_dxFilter = false;
}
if (numDxFilters > 0)
{
errCode = buffer->SetFX( 0, NULL, NULL );
SOUNDASSERT( errCode, "Direct sound couldn't set fx" );
}
//
// Restart the channel
errCode = buffer->Play( 0, 0, DSBPLAY_LOOPING );
SOUNDASSERT( errCode, "Direct sound couldn't play a secondary buffer" );
}
示例2: fopen_s
// must be 44.1k 16bit Stereo PCM Wave
Sound DSound::CreateSound( char* wavFileName )
{
int error;
FILE* filePtr;
unsigned int count;
WaveHeaderType waveFileHeader;
WAVEFORMATEX waveFormat;
DSBUFFERDESC bufferDesc;
HRESULT result;
IDirectSoundBuffer* tempBuffer;
IDirectSoundBuffer8* pSecondaryBuffer;
unsigned char* waveData;
unsigned char* bufferPtr;
unsigned long bufferSize;
// Open the wave file in binary.
error = fopen_s( &filePtr,wavFileName,"rb" );
assert( error == 0 );
// Read in the wave file header.
count = fread( &waveFileHeader,sizeof( waveFileHeader ),1,filePtr );
assert( count == 1 );
// Check that the chunk ID is the RIFF format.
assert( (waveFileHeader.chunkId[0] == 'R') &&
(waveFileHeader.chunkId[1] == 'I') &&
(waveFileHeader.chunkId[2] == 'F') &&
(waveFileHeader.chunkId[3] == 'F') );
// Check that the file format is the WAVE format.
assert( (waveFileHeader.format[0] == 'W') &&
(waveFileHeader.format[1] == 'A') &&
(waveFileHeader.format[2] == 'V') &&
(waveFileHeader.format[3] == 'E') );
// Check that the sub chunk ID is the fmt format.
assert( (waveFileHeader.subChunkId[0] == 'f') &&
(waveFileHeader.subChunkId[1] == 'm') &&
(waveFileHeader.subChunkId[2] == 't') &&
(waveFileHeader.subChunkId[3] == ' ') );
// Check that the audio format is WAVE_FORMAT_PCM.
assert( waveFileHeader.audioFormat == WAVE_FORMAT_PCM );
// Check that the wave file was recorded in stereo format.
assert( waveFileHeader.numChannels == 2 );
// Check that the wave file was recorded at a sample rate of 44.1 KHz.
assert( waveFileHeader.sampleRate == 44100 );
// Ensure that the wave file was recorded in 16 bit format.
assert( waveFileHeader.bitsPerSample == 16 );
// Check for the data chunk header.
assert( (waveFileHeader.dataChunkId[0] == 'd') &&
(waveFileHeader.dataChunkId[1] == 'a') &&
(waveFileHeader.dataChunkId[2] == 't') &&
(waveFileHeader.dataChunkId[3] == 'a') );
// Set the wave format of secondary buffer that this wave file will be loaded onto.
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nSamplesPerSec = 44100;
waveFormat.wBitsPerSample = 16;
waveFormat.nChannels = 2;
waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8) * waveFormat.nChannels;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
waveFormat.cbSize = 0;
// Set the buffer description of the secondary sound buffer that the wave file will be loaded onto.
bufferDesc.dwSize = sizeof(DSBUFFERDESC);
bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
bufferDesc.dwBufferBytes = waveFileHeader.dataSize;
bufferDesc.dwReserved = 0;
bufferDesc.lpwfxFormat = &waveFormat;
bufferDesc.guid3DAlgorithm = GUID_NULL;
// Create a temporary sound buffer with the specific buffer settings.
result = pDirectSound->CreateSoundBuffer( &bufferDesc,&tempBuffer,NULL );
assert( !FAILED( result ) );
// Test the buffer format against the direct sound 8 interface and create the secondary buffer.
result = tempBuffer->QueryInterface( IID_IDirectSoundBuffer8,(void**)&pSecondaryBuffer );
assert( !FAILED( result ) );
// Release the temporary buffer.
tempBuffer->Release();
tempBuffer = 0;
// Move to the beginning of the wave data which starts at the end of the data chunk header.
fseek( filePtr,sizeof(WaveHeaderType),SEEK_SET );
// Create a temporary buffer to hold the wave file data.
waveData = new unsigned char[ waveFileHeader.dataSize ];
assert( waveData );
// Read in the wave file data into the newly created buffer.
count = fread( waveData,1,waveFileHeader.dataSize,filePtr );
assert( count == waveFileHeader.dataSize);
//.........这里部分代码省略.........
示例3: Init
s32 Init()
{
numBuffers = Config_DSoundOut.NumBuffers;
//
// Initialize DSound
//
GUID cGuid;
try
{
if( Config_DSoundOut.Device.empty() )
throw std::runtime_error( "screw it" );
// Convert from unicode to ANSI:
char guid[256];
sprintf_s( guid, "%S", Config_DSoundOut.Device.c_str() );
if( (FAILED(GUIDFromString( guid, &cGuid ))) ||
FAILED( DirectSoundCreate8(&cGuid,&dsound,NULL) ) )
throw std::runtime_error( "try again?" );
}
catch( std::runtime_error& )
{
// if the GUID failed, just open up the default dsound driver:
if( FAILED(DirectSoundCreate8(NULL,&dsound,NULL) ) )
throw std::runtime_error( "DirectSound failed to initialize!" );
}
if( FAILED(dsound->SetCooperativeLevel(GetDesktopWindow(),DSSCL_PRIORITY)) )
throw std::runtime_error( "DirectSound Error: Cooperative level could not be set." );
// Determine the user's speaker configuration, and select an expansion option as needed.
// FAIL : Directsound doesn't appear to support audio expansion >_<
DWORD speakerConfig = 2;
//dsound->GetSpeakerConfig( &speakerConfig );
IDirectSoundBuffer* buffer_;
DSBUFFERDESC desc;
// Set up WAV format structure.
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nSamplesPerSec = SampleRate;
wfx.nChannels = (WORD)speakerConfig;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = 2*(WORD)speakerConfig;
wfx.nAvgBytesPerSec = SampleRate * wfx.nBlockAlign;
wfx.cbSize = 0;
uint BufferSizeBytes = BufferSize * wfx.nBlockAlign;
// Set up DSBUFFERDESC structure.
memset(&desc, 0, sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY;// _CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
desc.dwBufferBytes = BufferSizeBytes * numBuffers;
desc.lpwfxFormat = &wfx;
desc.dwFlags |= DSBCAPS_LOCSOFTWARE;
desc.dwFlags |= DSBCAPS_GLOBALFOCUS;
if( FAILED(dsound->CreateSoundBuffer(&desc,&buffer_,0) ) )
throw std::runtime_error( "DirectSound Error: Interface could not be queried." );
if( FAILED(buffer_->QueryInterface(IID_IDirectSoundBuffer8,(void**)&buffer)) )
throw std::runtime_error( "DirectSound Error: Interface could not be queried." );
buffer_->Release();
verifyc( buffer->QueryInterface(IID_IDirectSoundNotify8,(void**)&buffer_notify) );
DSBPOSITIONNOTIFY not[MAX_BUFFER_COUNT];
for(u32 i=0;i<numBuffers;i++)
{
// [Air] note: wfx.nBlockAlign modifier was *10 -- seems excessive to me but maybe
// it was needed for some quirky driver? Theoretically we want the notification as soon
// as possible after the buffer has finished playing.
buffer_events[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
not[i].dwOffset = (wfx.nBlockAlign + BufferSizeBytes*(i+1)) % desc.dwBufferBytes;
not[i].hEventNotify = buffer_events[i];
}
buffer_notify->SetNotificationPositions(numBuffers,not);
LPVOID p1=0,p2=0;
DWORD s1=0,s2=0;
verifyc(buffer->Lock(0,desc.dwBufferBytes,&p1,&s1,&p2,&s2,0));
assert(p2==0);
memset(p1,0,s1);
verifyc(buffer->Unlock(p1,s1,p2,s2));
//Play the buffer !
verifyc(buffer->Play(0,0,DSBPLAY_LOOPING));
//.........这里部分代码省略.........
示例4: Init
s32 Init()
{
CoInitializeEx( NULL, COINIT_MULTITHREADED );
//
// Initialize DSound
//
GUID cGuid;
try
{
if( m_Device.empty() )
throw std::runtime_error( "screw it" );
// Convert from unicode to ANSI:
char guid[256];
sprintf_s( guid, "%S", m_Device.c_str() );
if( (FAILED(GUIDFromString( guid, &cGuid ))) ||
FAILED( DirectSoundCreate8(&cGuid,&dsound,NULL) ) )
throw std::runtime_error( "try again?" );
}
catch( std::runtime_error& )
{
// if the GUID failed, just open up the default dsound driver:
if( FAILED(DirectSoundCreate8(NULL,&dsound,NULL) ) )
throw std::runtime_error( "DirectSound failed to initialize!" );
}
if( FAILED(dsound->SetCooperativeLevel(GetDesktopWindow(),DSSCL_PRIORITY)) )
throw std::runtime_error( "DirectSound Error: Cooperative level could not be set." );
// Determine the user's speaker configuration, and select an expansion option as needed.
// FAIL : Directsound doesn't appear to support audio expansion >_<
DWORD speakerConfig = 2;
//dsound->GetSpeakerConfig( &speakerConfig );
IDirectSoundBuffer* buffer_;
DSBUFFERDESC desc;
// Set up WAV format structure.
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nSamplesPerSec = SampleRate;
wfx.nChannels = (WORD)speakerConfig;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = 2*(WORD)speakerConfig;
wfx.nAvgBytesPerSec = SampleRate * wfx.nBlockAlign;
wfx.cbSize = 0;
uint BufferSizeBytes = BufferSize * wfx.nBlockAlign;
// Set up DSBUFFERDESC structure.
memset(&desc, 0, sizeof(DSBUFFERDESC));
desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY;
desc.dwBufferBytes = BufferSizeBytes * m_NumBuffers;
desc.lpwfxFormat = &wfx;
// Try a hardware buffer first, and then fall back on a software buffer if
// that one fails.
desc.dwFlags |= m_UseHardware ? DSBCAPS_LOCHARDWARE : DSBCAPS_LOCSOFTWARE;
desc.dwFlags |= m_DisableGlobalFocus ? DSBCAPS_STICKYFOCUS : DSBCAPS_GLOBALFOCUS;
if( FAILED(dsound->CreateSoundBuffer(&desc, &buffer_, 0) ) )
{
if( m_UseHardware )
{
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_LOCSOFTWARE;
desc.dwFlags |= m_DisableGlobalFocus ? DSBCAPS_STICKYFOCUS : DSBCAPS_GLOBALFOCUS;
if( FAILED(dsound->CreateSoundBuffer(&desc, &buffer_, 0) ) )
throw std::runtime_error( "DirectSound Error: Buffer could not be created." );
}
throw std::runtime_error( "DirectSound Error: Buffer could not be created." );
}
if( FAILED(buffer_->QueryInterface(IID_IDirectSoundBuffer8,(void**)&buffer)) || buffer == NULL )
throw std::runtime_error( "DirectSound Error: Interface could not be queried." );
buffer_->Release();
verifyc( buffer->QueryInterface(IID_IDirectSoundNotify8,(void**)&buffer_notify) );
DSBPOSITIONNOTIFY not[MAX_BUFFER_COUNT];
for(uint i=0;i<m_NumBuffers;i++)
{
buffer_events[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
not[i].dwOffset = (wfx.nBlockAlign + BufferSizeBytes*(i+1)) % desc.dwBufferBytes;
not[i].hEventNotify = buffer_events[i];
}
buffer_notify->SetNotificationPositions(m_NumBuffers,not);
LPVOID p1=0,p2=0;
DWORD s1=0,s2=0;
//.........这里部分代码省略.........
示例5: SOUNDASSERT
SoundLibrary3dDirectSound::~SoundLibrary3dDirectSound()
{
int errCode;
//
// Release secondary buffers
if( m_channels )
{
for( int i = 0; i < m_numChannels; ++i )
{
IDirectSoundBuffer8 *buffer = (IDirectSoundBuffer8 *) m_channels[i].m_bufferInterface;
if( buffer )
{
errCode = buffer->Stop();
SOUNDASSERT( errCode, "DirectSound failed to stop secondary buffer" );
// errCode = buffer->SetFX(0, NULL, NULL);
// SOUNDASSERT( errCode, "DirectSound failed to remove FX from secondary buffer" );
errCode = buffer->Release();
SOUNDASSERT( errCode, "DirectSound failed to release secondary buffer" );
}
}
delete m_channels;
}
//
// Release music channel
if( m_musicChannel )
{
IDirectSoundBuffer8 *buffer = (IDirectSoundBuffer8 *)m_musicChannel->m_bufferInterface;
if( buffer )
{
errCode = buffer->Stop();
SOUNDASSERT( errCode, "DirectSound failed to shutdown secondary buffer" );
errCode = buffer->Release();
SOUNDASSERT( errCode, "DirectSound failed to shutdown secondary buffer" );
}
}
//
// Release primary buffer
if( m_directSound->m_primaryBuffer )
{
errCode = m_directSound->m_primaryBuffer->Stop();
SOUNDASSERT( errCode, "DirectSound failed to shutdown primary buffer" );
errCode = m_directSound->m_primaryBuffer->Release();
SOUNDASSERT( errCode, "DirectSound failed to shutdown primary buffer" );
}
//
// Release Direct Sound Device
if( m_directSound->m_device )
{
errCode = m_directSound->m_device->Release();
SOUNDASSERT( errCode, "DirectSound failed to shutdown device" );
}
delete m_directSound;
}
示例6: AppReleaseAssert
void SoundLibrary3dDirectSound::EnableDspFX(int _channel, int _numFilters, int const *_filterTypes)
{
AppReleaseAssert( _numFilters > 0, "Bad argument passed to EnableFilters" );
AppDebugAssert(_channel >= 0 && _channel < m_numChannels);
DirectSoundChannel *channel;
if (_channel == m_musicChannelId) channel = m_musicChannel;
else channel = &m_channels[_channel];
int errCode;
IDirectSoundBuffer8 *buffer = (IDirectSoundBuffer8 *) channel->m_bufferInterface;
if (GetNumFilters(_channel) > 0)
{
DisableDspFX(_channel);
}
//
// Prepare the sound descriptions
DSEFFECTDESC desc[DSP_DSOUND_WAVESREVERB];
int numDSoundFilters = 0;
for( int i = 0; i < _numFilters; ++i )
{
if (_filterTypes[i] <= DSP_DSOUND_WAVESREVERB)
{
ZeroMemory( &desc[numDSoundFilters], sizeof(DSEFFECTDESC) );
desc[numDSoundFilters].dwSize = sizeof( DSEFFECTDESC );
desc[numDSoundFilters].dwFlags = DSFX_LOCSOFTWARE;
desc[numDSoundFilters].guidDSFXClass = *s_dxDescriptors[ _filterTypes[i] ].m_sfxClass;
AppDebugAssert(
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_CHORUS ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_COMPRESSOR ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_DISTORTION ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_ECHO ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_FLANGER ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_GARGLE ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_I3DL2REVERB ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_STANDARD_PARAMEQ ||
desc[numDSoundFilters].guidDSFXClass == GUID_DSFX_WAVES_REVERB
);
++numDSoundFilters;
}
}
unsigned long results[NUM_FILTERS];
if (numDSoundFilters > 0)
{
//
// Stop the channel
errCode = buffer->Stop();
SOUNDASSERT( errCode, "Direct sound couldn't stop a secondary buffer from playing" );
//
// Set up the filters
errCode = buffer->SetFX( numDSoundFilters, desc, results );
SOUNDASSERT( errCode, "Direct sound couldn't set fx" );
//
// Restart the channel
errCode = buffer->Play( 0, 0, DSBPLAY_LOOPING );
SOUNDASSERT( errCode, "Direct sound couldn't play a secondary buffer" );
}
for( int i = 0; i < _numFilters; ++i )
{
AppDebugAssert(_filterTypes[i] >= 0);
if (_filterTypes[i] <= DSP_DSOUND_WAVESREVERB)
{
AppReleaseAssert( results[i] == DSFXR_LOCSOFTWARE, "DirectSound couldn't enable filter" );
channel->m_dspFX[i].m_dxFilter = true;
}
switch (_filterTypes[i])
{
case DSP_RESONANTLOWPASS:
channel->m_dspFX[_filterTypes[i]].m_userFilter = new DspResLowPass(m_sampleRate);
break;
case DSP_BITCRUSHER:
channel->m_dspFX[_filterTypes[i]].m_userFilter = new DspBitCrusher(m_sampleRate);
break;
case DSP_GARGLE:
channel->m_dspFX[_filterTypes[i]].m_userFilter = new DspGargle(m_sampleRate);
break;
case DSP_ECHO:
channel->m_dspFX[_filterTypes[i]].m_userFilter = new DspEcho(m_sampleRate);
break;
case DSP_SIMPLE_REVERB:
channel->m_dspFX[_filterTypes[i]].m_userFilter = new DspReverb(m_sampleRate);
break;
//.........这里部分代码省略.........
示例7: Thread
DWORD CALLBACK Thread()
{
static const int BufferSizeBytes = BufferSize * sizeof( T );
while( dsound_running )
{
u32 rv = WaitForMultipleObjects(numBuffers,buffer_events,FALSE,200);
T* p1, *oldp1;
LPVOID p2;
DWORD s1,s2;
u32 poffset = BufferSizeBytes * rv;
if( FAILED(buffer->Lock(poffset,BufferSizeBytes,(LPVOID*)&p1,&s1,&p2,&s2,0) ) )
{
assert( 0 );
fputs( " * SPU2 : Directsound Warning > Buffer lock failure. You may need to increase\n\tyour configured DSound buffer count.\n", stderr );
continue;
}
oldp1 = p1;
for(int p=0; p<PacketsPerBuffer; p++, p1+=SndOutPacketSize )
SndBuffer::ReadSamples( p1 );
buffer->Unlock( oldp1, s1, p2, s2 );
// Set the write pointer to the beginning of the next block.
myLastWrite = (poffset + BufferSizeBytes) & ~BufferSizeBytes;
}
return 0;
}
示例8: WaitForMultipleObjects
DWORD DSound51_Driver::WorkerThread()
{
while( dsound_running )
{
u32 rv = WaitForMultipleObjects(numBuffers,buffer_events,FALSE,200);
s16* p1, *oldp1;
LPVOID p2;
DWORD s1,s2;
u32 poffset = DSound51::BufferSizeBytes * rv;
#ifdef _DEBUG
verifyc(buffer->Lock(poffset,DSound51::BufferSizeBytes,(LPVOID*)&p1,&s1,&p2,&s2,0));
#else
if( FAILED(buffer->Lock(poffset,DSound51::BufferSizeBytes,(LPVOID*)&p1,&s1,&p2,&s2,0) ) )
{
fputs( " * SPU2 : Directsound Warning > Buffer lock failure. You may need to increase the DSound buffer count.\n", stderr );
continue;
}
#endif
oldp1 = p1;
for(int p=0; p<DSound51::PacketsPerBuffer; p++, p1+=SndOutPacketSize )
{
s32 temp[SndOutPacketSize];
s32* s = temp;
s16* t = p1;
buff->ReadSamples( temp );
for(int j=0;j<SndOutPacketSize/2;j++)
{
// DPL2 code here: inputs s[0] and s[1]. outputs t[0] to t[5]
dpl2.Convert( t, s[0], s[1] );
t+=6;
s+=2;
}
}
#ifndef PUBLIC
verifyc(buffer->Unlock(oldp1,s1,p2,s2));
#else
buffer->Unlock(oldp1,s1,p2,s2);
#endif
// Set the write pointer to the beginning of the next block.
myLastWrite = (poffset + DSound51::BufferSizeBytes) % (DSound51::BufferSizeBytes*numBuffers);
}
return 0;
}
示例9: Close
void Close()
{
// Stop Thread
fprintf(stderr," * SPU2: Waiting for DSound thread to finish...");
dsound_running=false;
WaitForSingleObject(thread,INFINITE);
CloseHandle(thread);
fprintf(stderr," Done.\n");
//
// Clean up
//
if( buffer != NULL )
{
buffer->Stop();
for(u32 i=0;i<numBuffers;i++)
{
if( buffer_events[i] != NULL )
CloseHandle(buffer_events[i]);
buffer_events[i] = NULL;
}
SAFE_RELEASE( buffer_notify );
SAFE_RELEASE( buffer );
}
SAFE_RELEASE( dsound );
}
示例10:
void VDAudioOutputDirectSoundW32::StopPlayback() {
if (mbDSBufferPlaying) {
if (mpDSBuffer)
mpDSBuffer->Stop();
mbDSBufferPlaying = false;
}
}
示例11:
int DSound51_Driver::GetEmptySampleCount() const
{
DWORD play, write;
buffer->GetCurrentPosition( &play, &write );
// Note: Dsound's write cursor is bogus. Use our own instead:
int empty = play - myLastWrite;
if( empty < 0 )
empty = -empty;
return empty / 6;
}