本文整理汇总了C++中LPDIRECTSOUNDBUFFER::SetVolume方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUNDBUFFER::SetVolume方法的具体用法?C++ LPDIRECTSOUNDBUFFER::SetVolume怎么用?C++ LPDIRECTSOUNDBUFFER::SetVolume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTSOUNDBUFFER
的用法示例。
在下文中一共展示了LPDIRECTSOUNDBUFFER::SetVolume方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SNDDXSetVolume
void SNDDXSetVolume(int volume)
{
if (!lpDSB2) return ; //might happen when changing sounddevice on the fly, caused a gpf
if(volume==0)
soundvolume = DSBVOLUME_MIN;
else
{
float attenuate = 1000 * (float)log(100.0f/volume);
soundvolume = -(int)attenuate;
}
if (!issoundmuted)
lpDSB2->SetVolume(soundvolume);
}
示例2: PlaySoundLoop
// Sound wiederholt abspielen (Letzter Paramter: true = starten, false = stoppen)
void PlaySoundLoop(LPDIRECTSOUNDBUFFER lpDSB, int pan, int vol, BOOL bStartStop)
{
DWORD ret;
lpDSB->GetStatus(&ret);
if( (lpDSB) && (bStartStop) )
{
if(ret != DSBSTATUS_LOOPING)
{
lpDSB->SetPan(pan);
lpDSB->SetVolume(vol);
lpDSB->Play(0,0,DSBPLAY_LOOPING);
}
}
else if(lpDSB)
lpDSB->Stop();
}
示例3: 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;
LPDIRECTSOUNDBUFFER 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 );
}
示例4: DXTRACE_ERR
//-----------------------------------------------------------------------------
// Name: CDSSound::Play3D()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CDSSound::Play3D(LPDS3DBUFFER p3DBuffer, DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, DWORD& outIndex)
{
HRESULT hr;
BOOL bRestored;
DWORD dwBaseFrequency;
if (!m_apDSBuffer) return CO_E_NOTINITIALIZED;
LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer(outIndex);
if (!pDSB) 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)
if (FAILED(hr = FillBufferWithSound(pDSB, FALSE)))
return DXTRACE_ERR(TEXT("FillBufferWithSound"), hr);
if (m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY)
{
pDSB->GetFrequency(&dwBaseFrequency);
pDSB->SetFrequency(dwBaseFrequency + lFrequency);
}
if (m_dwCreationFlags & DSBCAPS_CTRLVOLUME) pDSB->SetVolume(lVolume);
// QI for the 3D buffer
LPDIRECTSOUND3DBUFFER pDS3DBuffer;
hr = pDSB->QueryInterface(IID_IDirectSound3DBuffer, (VOID**) &pDS3DBuffer);
if (SUCCEEDED(hr))
{
hr = pDS3DBuffer->SetAllParameters(p3DBuffer, DS3D_IMMEDIATE);
if (SUCCEEDED(hr))
{
hr = pDSB->SetCurrentPosition(0);
hr = pDSB->Play(0, dwPriority, dwFlags);
}
pDS3DBuffer->Release();
}
return hr;
}
示例5: VStop
// ////////////////////////////////////////////////////////////////////
//
// ////////////////////////////////////////////////////////////////////
bool DirectSound8AudioBuffer::VPlay(const I32 volume, const bool looping)
{
VStop();
// Set base class attributs.
AudioBuffer::VSetVolume(volume);
AudioBuffer::VSetLooping(looping);
// Get DirectSound buffer.
LPDIRECTSOUNDBUFFER pDSB = static_cast<LPDIRECTSOUNDBUFFER>(VGet());
if(!pDSB) {
GF_LOG_TRACE_ERR("DirectSound8AudioBuffer::VPlay()", "Failed to cast the buffer to a DirectSound buffer");
return (false);
}
// Set the buffers volume and play it.
pDSB->SetVolume(volume);
DWORD dwFlags = looping ? DSBPLAY_LOOPING : 0L;
return (S_OK == pDSB->Play(0, 0, dwFlags));
}
示例6: DS_Set
//===========================================================================
// DS_Set
// SFXBP_VOLUME (if negative, interpreted as attenuation)
// SFXBP_FREQUENCY
// SFXBP_PAN (-1..1)
// SFXBP_MIN_DISTANCE
// SFXBP_MAX_DISTANCE
// SFXBP_RELATIVE_MODE
//===========================================================================
void DS_Set(sfxbuffer_t *buf, int property, float value)
{
unsigned int f;
LPDIRECTSOUNDBUFFER sound = DSBuf(buf);
if(!sound) return;
switch(property)
{
case SFXBP_VOLUME:
// Use logarithmic attenuation.
sound->SetVolume(value <= 0? (-1-value) * 10000
: LinLog(value)); // Linear volume.
break;
case SFXBP_FREQUENCY:
f = unsigned int(buf->rate * value);
// Don't set redundantly.
if(f != buf->freq) sound->SetFrequency(buf->freq = f);
break;
case SFXBP_PAN:
sound->SetPan(LogPan(value));
break;
case SFXBP_MIN_DISTANCE:
if(!DSBuf3(buf)) return;
DSBuf3(buf)->SetMinDistance(value, DS3D_DEFERRED);
break;
case SFXBP_MAX_DISTANCE:
if(!DSBuf3(buf)) return;
DSBuf3(buf)->SetMaxDistance(value, DS3D_DEFERRED);
break;
case SFXBP_RELATIVE_MODE:
if(!DSBuf3(buf)) return;
DSBuf3(buf)->SetMode(value? DS3DMODE_HEADRELATIVE : DS3DMODE_NORMAL,
DS3D_DEFERRED);
break;
}
}
示例7: VSetVolume
// *******************************************************************************************************************
void cDirectSoundAudioBuffer::VSetVolume(uint16 volume)
{
SP_ASSERT(volume <= 100)(volume).SetCustomMessage("Volume must be between 0 and 100");
Clamp<uint16>(volume, 0, 100);
LPDIRECTSOUNDBUFFER pDSBuffer = GetSoundBuffer();
SP_ASSERT(pDSBuffer != NULL).SetCustomMessage("Could not get Sound Buffer");
if (pDSBuffer)
{
return;
}
float cCoeff = static_cast<float>(volume) / 100.0f;
float logarithmicProportion = cCoeff > 0.1f ? 1 + log10(cCoeff) : 0;
float range = (DSBVOLUME_MAX - DSBVOLUME_MIN);
float adjustedVolume = (range * logarithmicProportion) + DSBVOLUME_MIN;
m_Volume = static_cast<unsigned int>(adjustedVolume);
pDSBuffer->SetVolume(m_Volume);
}
示例8:
/*
===============
idAudioBufferWIN32::SetVolume
===============
*/
void idAudioBufferWIN32::SetVolume(float x)
{
if (m_apDSBuffer) {
m_apDSBuffer->SetVolume(x);
}
}
示例9: SNDDXUnMuteAudio
void SNDDXUnMuteAudio()
{
issoundmuted = 0;
lpDSB2->SetVolume(soundvolume);
}
示例10: SNDDXMuteAudio
void SNDDXMuteAudio()
{
issoundmuted = 1;
lpDSB2->SetVolume(DSBVOLUME_MIN);
}
示例11: ChannelSetVolume
/*------------------------------------------------------------------------
*
* PROTOTYPE : void ChannelSetVolume(int chan, int volume)
*
* DESCRIPTION : Modify a channel volume
*
*/
void ChannelSetVolume(int chan, float volume)
{
LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[chan].pbuffer;
if (!pDS) return;
pDS->SetVolume(GetVol(volume));
}
示例12: OnSliderChanged
//-----------------------------------------------------------------------------
// Name: OnSliderChanged()
// Desc: Called when the dialog's slider bars are changed by the user, or need
// updating
//-----------------------------------------------------------------------------
VOID OnSliderChanged( HWND hDlg )
{
TCHAR strBuffer[10];
// Get handles to dialog items
HWND hFreqSlider = GetDlgItem( hDlg, IDC_FREQUENCY_SLIDER );
HWND hPanSlider = GetDlgItem( hDlg, IDC_PAN_SLIDER );
HWND hVolumeSlider = GetDlgItem( hDlg, IDC_VOLUME_SLIDER );
// Get the position of the sliders
LONG lFrequency = (LONG)SendMessage( hFreqSlider, TBM_GETPOS, 0, 0 ) * 1L;
LONG lPan = (LONG)SendMessage( hPanSlider, TBM_GETPOS, 0, 0 ) * 500L;
LONG lVolume = (LONG)SendMessage( hVolumeSlider, TBM_GETPOS, 0, 0 ) * 100L;
// Set the static text boxes
wsprintf( strBuffer, TEXT("%ld"), lFrequency );
SetWindowText( GetDlgItem( hDlg, IDC_FREQUENCY ), strBuffer );
wsprintf( strBuffer, TEXT("%ld"), lPan );
SetWindowText( GetDlgItem( hDlg, IDC_PAN ), strBuffer );
wsprintf( strBuffer, TEXT("%ld"), lVolume );
SetWindowText( GetDlgItem( hDlg, IDC_VOLUME ), strBuffer );
// Set the options in the DirectSound buffer
if( g_pSound )
{
LPDIRECTSOUNDBUFFER pDSB = g_pSound->GetBuffer( 0 );
if( pDSB )
{
if( FAILED( pDSB->SetFrequency( lFrequency ) ) )
{
DSCAPS dscaps;
ZeroMemory( &dscaps, sizeof(DSCAPS) );
dscaps.dwSize = sizeof(DSCAPS);
g_pSoundManager->GetDirectSound()->GetCaps( &dscaps );
DSBCAPS dsbcaps;
ZeroMemory( &dsbcaps, sizeof(DSBCAPS) );
dsbcaps.dwSize = sizeof(DSBCAPS);
pDSB->GetCaps( &dsbcaps );
// Try to guess why it failed
if( (dsbcaps.dwFlags & DSBCAPS_LOCHARDWARE) &&
(DWORD)lFrequency > dscaps.dwMaxSecondarySampleRate )
{
// Hardware buffers don't support >dwMaxSecondarySampleRate
SetDlgItemText( hDlg, IDC_STATUS, TEXT("Hardware buffers don't support greater")
TEXT("than dscaps.dwMaxSecondarySampleRate") );
}
else if( lFrequency > 100000 )
{
// Some platforms (pre-WinXP SP1) do not support
// >100k Hz so they will fail when setting it higher
SetDlgItemText( hDlg, IDC_STATUS, TEXT("Some OS platforms do not support >100k Hz") );
}
else
{
SetDlgItemText( hDlg, IDC_STATUS, TEXT("Set frequency failed") );
}
// Reset to the last valid freq
pDSB->SetFrequency( g_dwLastValidFreq );
PostMessage( hFreqSlider, TBM_SETPOS, TRUE, g_dwLastValidFreq );
}
else
{
g_dwLastValidFreq = lFrequency;
}
pDSB->SetPan( lPan );
pDSB->SetVolume( lVolume );
}
}
}