本文整理汇总了C++中IDirectSoundBuffer::SetVolume方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::SetVolume方法的具体用法?C++ IDirectSoundBuffer::SetVolume怎么用?C++ IDirectSoundBuffer::SetVolume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectSoundBuffer
的用法示例。
在下文中一共展示了IDirectSoundBuffer::SetVolume方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void SoundLibrary3dDirectSound::SetChannelVolume( int _channel, float _volume )
{
DirectSoundChannel *channel;
if (_channel == m_musicChannelId)
channel = m_musicChannel;
else channel = &m_channels[_channel];
if (!NearlyEquals(_volume, channel->m_volume) || m_forceVolumeUpdate )
{
AppDebugAssert(_volume >= 0.0f && _volume <= 10.0f);
channel->m_volume = _volume;
// long calculatedVolume = expf(10.0f - _volume);
// calculatedVolume += m_masterVolume;
// calculatedVolume *= -1.0f;
float calculatedVolume = -(5.0f - _volume * 0.5f);
calculatedVolume *= 1000.0f;
calculatedVolume += m_masterVolume;
if( calculatedVolume < -10000.0f ) calculatedVolume = -10000.0f;
if( calculatedVolume > 0.0f ) calculatedVolume = 0.0f;
IDirectSoundBuffer *buffer = channel->m_bufferInterface;
int errCode = buffer->SetVolume( calculatedVolume );
if (errCode == DSERR_BUFFERLOST)
buffer->Restore();
else
SOUNDASSERT( errCode, "Direct sound couldn't set buffer volume" );
}
}
示例2: Play
//-----------------------------------------------------------------------------
// Name: CSound::Play()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play( DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, LONG lPan )
{
HRESULT hr;
BOOL bRestored;
if( m_apDSBuffer == NULL )
return CO_E_NOTINITIALIZED;
IDirectSoundBuffer* pDSB = GetFreeBuffer();
if( pDSB == NULL )
return DXTRACE_ERR( TEXT("GetFreeBuffer"), E_FAIL );
// Restore the buffer if it was lost
if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
return DXTRACE_ERR( TEXT("RestoreBuffer"), hr );
if( bRestored )
{
// The buffer was restored, so we need to fill it with new data
if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
return DXTRACE_ERR( TEXT("FillBufferWithSound"), hr );
}
if( m_dwCreationFlags & DSBCAPS_CTRLVOLUME )
{
pDSB->SetVolume( lVolume );
}
if( lFrequency != -1 &&
(m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY) )
{
pDSB->SetFrequency( lFrequency );
}
if( m_dwCreationFlags & DSBCAPS_CTRLPAN )
{
pDSB->SetPan( lPan );
}
return pDSB->Play( 0, dwPriority, dwFlags );
}
示例3: play
int CSoundResource::play( int sndID, DWORD priority, DWORD flags, LONG volume, LONG freq, LONG pan )
{
assert( mDSBuffers );
int bufferIdx = getFreeBufferIndex();
IDirectSoundBuffer* buffer = mDSBuffers[bufferIdx];
if( !restoreBufferAndFill( buffer, false ) )
return -1;
if( mCreationFlags & DSBCAPS_CTRLVOLUME )
buffer->SetVolume( volume );
if( freq != -1 && (mCreationFlags & DSBCAPS_CTRLFREQUENCY) )
buffer->SetFrequency( freq );
if( mCreationFlags & DSBCAPS_CTRLPAN )
buffer->SetPan( pan );
mPlayingIDs[bufferIdx] = sndID;
buffer->Play( 0, priority, flags );
return bufferIdx;
}
示例4: toear
int CSoundResource::play3D( int sndID, const DS3DBUFFER& props3D, DWORD priority, DWORD flags, LONG volume, LONG freq )
{
HRESULT hr;
DWORD baseFreq;
assert( mDSBuffers );
// cull the sound if too far
const SVector3& earPos = G_AUDIOCTX->getListener().transform.getOrigin();
SVector3 toear( earPos.x - props3D.vPosition.x, earPos.y - props3D.vPosition.y, earPos.z - props3D.vPosition.z );
if( toear.lengthSq() >= props3D.flMaxDistance * props3D.flMaxDistance )
return 0;
int bufferIdx = getFreeBufferIndex();
IDirectSoundBuffer* buffer = mDSBuffers[bufferIdx];
if( !restoreBufferAndFill( buffer, false ) )
return -1;
if( mCreationFlags & DSBCAPS_CTRLVOLUME )
buffer->SetVolume( volume );
if( mCreationFlags & DSBCAPS_CTRLFREQUENCY ) {
buffer->GetFrequency( &baseFreq );
buffer->SetFrequency( baseFreq + freq );
}
IDirectSound3DBuffer* buf3D;
hr = buffer->QueryInterface( IID_IDirectSound3DBuffer, (void**)&buf3D );
if( SUCCEEDED( hr ) ) {
hr = buf3D->SetAllParameters( &props3D, DS3D_IMMEDIATE );
if( SUCCEEDED( hr ) ) {
mPlayingIDs[bufferIdx] = sndID;
hr = buffer->Play( 0, priority, flags );
}
buf3D->Release();
}
return bufferIdx;
}
示例5: WinMain
//.........这里部分代码省略.........
}
if (mmResult != MMSYSERR_NOERROR)
{
MessageBox(hWnd, TEXT("brak karty dzwiekowej o wymaganych parametrach"), TEXT("ERROR"), MB_OK);
return mmResult;
}
*/
IDirectSound8 *DS8;
DirectSoundCreate8(nullptr, &DS8, nullptr);
if (DS8 == nullptr)
{
MessageBox(nullptr, TEXT("nie mozna utworzyc direktsound"), TEXT("ERROR"), MB_OK);
}
if (DS8->SetCooperativeLevel(hWnd, DSSCL_NORMAL) != DS_OK)
MessageBox(nullptr, TEXT("nie mozna ustawic wymaganego trybu pracy"), TEXT("ERROR"), MB_OK);
//przygotowanie probek do odtworzenia
WAVEHDR whdr;
ZeroMemory(&whdr, sizeof(WAVEHDR));
whdr.lpData = new char[pcmWaveFormat.nAvgBytesPerSec * 10]; //ilosc bajtwo na sekunde
whdr.dwBufferLength = pcmWaveFormat.nAvgBytesPerSec * 10; //razy ilosc sekund
whdr.dwUser = 0;
whdr.dwFlags = 0;
whdr.dwLoops = 0;
whdr.dwBytesRecorded = 0;
whdr.lpNext = nullptr;
//wypelnienei buffora probek probkami sygnalu ao czestoliwosci 880hz
for (int i = 0; i < whdr.dwBufferLength; i++)
{
whdr.lpData[i] = 128 * sin(i*80.0 / static_cast<double>(pcmWaveFormat.nSamplesPerSec)) + 128;
}
/*
waveOutSetVolume(hwo, 0xFFFFFFFF);
mmResult = waveOutPrepareHeader(hwo, &whdr, sizeof(WAVEHDR)); //wyslanie naglowska
if (mmResult != MMSYSERR_NOERROR) //przygotowanie urzadzenia
{
MessageBox(hWnd, TEXT("nie mozna zainisjowac karty"), TEXT("ERROR"), MB_OK);
return mmResult;
}
mmResult = waveOutWrite(hwo, &whdr, sizeof(WAVEHDR)); //wyslanie probek do urzadzenia
if (mmResult != MMSYSERR_NOERROR)
{
MessageBox(hWnd, TEXT("nie idzie zaladowac probek"), TEXT("error"), MB_OK);
return mmResult;
}
while ((whdr.dwFlags&WHDR_DONE) != WHDR_DONE)Sleep(100);//czekanie na koniec
//zamkniecie urzadzenia
mmResult = waveOutUnprepareHeader(hwo, &whdr, sizeof(WAVEHDR));
mmResult = waveOutClose(hwo);
*/
IDirectSoundBuffer *DSB;
DSBUFFERDESC DSBD;
memset(&DSBD, 0, sizeof(DSBUFFERDESC));
DSBD.dwSize = sizeof(DSBD);
DSBD.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
DSBD.dwBufferBytes = whdr.dwBufferLength;
DSBD.lpwfxFormat = &pcmWaveFormat;
if (DS8->CreateSoundBuffer(&DSBD, &DSB, nullptr) != DS_OK)
{
MessageBox(nullptr, TEXT("nie mozna utworzy direktosoundbuffer"), TEXT("ERROR"), MB_OK);
};
DSB->SetVolume(0xFFF0);//ustawienie glosnosci
void *ptr1, *ptr2;
DWORD l1, l2;
DSB->Lock(0, whdr.dwBufferLength, &ptr1, &l1, &ptr2, &l2, DSBLOCK_ENTIREBUFFER);