本文整理汇总了C++中LPDIRECTSOUNDBUFFER::SetPan方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUNDBUFFER::SetPan方法的具体用法?C++ LPDIRECTSOUNDBUFFER::SetPan怎么用?C++ LPDIRECTSOUNDBUFFER::SetPan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTSOUNDBUFFER
的用法示例。
在下文中一共展示了LPDIRECTSOUNDBUFFER::SetPan方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlayExtended
HRESULT CSBuffer::PlayExtended( DWORD dwFlags, int Pan, int Volume, DWORD freq )
{
HRESULT rval;
LPDIRECTSOUNDBUFFER Buffer = NULL;
if( m_pDS==NULL ) return DSERR_UNINITIALIZED;
if( m_pDS->GetSoundOn( ) ) return DS_OK;
Buffer=GetFreeBuffer();
if(Buffer==NULL) return DSERR_ALLOCATED;
rval=Buffer->SetPan(Pan);
if(FAILED(rval)) return rval;
rval=Buffer->SetVolume(Volume);
if(FAILED(rval)) return rval;
rval=Buffer->SetFrequency(freq);
if(FAILED(rval)) return rval;
if(m_Streamed)
{
m_sLoop=dwFlags;
dwFlags=DSBPLAY_LOOPING;
}
m_dwLastUseTime = timeGetTime();
rval=Buffer->Play(0, 0, dwFlags);
if(FAILED(rval)) return rval;
return DS_OK;
}
示例2: Play
//-----------------------------------------------------------------------------
// Name: CDSSound::Play()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CDSSound::Play(DWORD dwPriority, DWORD dwFlags, LONG lVolume, LONG lFrequency, LONG lPan, DWORD& outIndex)
{
HRESULT hr;
BOOL bRestored;
if (m_apDSBuffer == NULL)
return CO_E_NOTINITIALIZED;
LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer(outIndex);
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);
pDSB->SetCurrentPosition(0);
return pDSB->Play(0, dwPriority, dwFlags);
}
示例3: Play
BOOL CSoundBuffer::Play(BOOL bLoop, long lPan, int iVol)
{
HRESULT rval;
LPDIRECTSOUNDBUFFER Buffer = NULL;
if(m_lpDS == NULL) return FALSE;
Buffer = GetIdleBuffer();
if(Buffer == NULL) return FALSE;
SetVolume(iVol);
if (lPan < DSBPAN_LEFT) lPan = DSBPAN_LEFT;
else if (lPan > DSBPAN_RIGHT) lPan = DSBPAN_RIGHT;
Buffer->SetPan(lPan);
m_bIsLooping = bLoop;
if (bLoop == FALSE)
rval = Buffer->Play(0, 0, 0);
else rval = Buffer->Play(0, 0, DSBPLAY_LOOPING );
if(rval != DS_OK) return FALSE;
return TRUE;
}
示例4: ChannelPlay
/*------------------------------------------------------------------------
*
* PROTOTYPE : int ChannelPlay(int channel, int freq, float volume, int pan, V3XA_HANDLE *sam)
*
* DESCRIPTION : Play a sound in a given channel, sampling rate, volume, pan
*
*/
int ChannelPlay(int channel, int freq, float volume, float pan, V3XA_HANDLE *sam)
{
ULONG lpStatus;
HRESULT hr;
int ret=FALSE;
if (!g_lpDSDevice)
return FALSE;
if ((DSS_DuplicateHandle(sam, channel)>=0) || DSS_RegisterHandle(sam, channel))
{
LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[channel].pbuffer;
if (pDS)
if (SYS_DXTRACE(pDS->GetStatus(&lpStatus)) == DS_OK)
{
hr = SYS_DXTRACE(pDS->Play(0, 0, sam->loopend ? DSBPLAY_LOOPING : 0));
if (hr == DS_OK)
{
SYS_DXTRACE(pDS->SetFrequency(freq));
SYS_DXTRACE(pDS->SetVolume(GetVol(volume)));
SYS_DXTRACE(pDS->SetPan(GetPan(pan)));
ret = TRUE;
}
}
}
return ret;
}
示例5: ChannelSetPanning
/*------------------------------------------------------------------------
*
* PROTOTYPE : void ChannelSetPanning(int chan, int pan)
*
* DESCRIPTION : Set panning (only with 2D buffers)
*
*/
static void ChannelSetPanning(int chan, float pan)
{
LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[chan].pbuffer;
if (!pDS)
return;
SYS_DXTRACE(pDS->SetPan(GetPan(pan)));
}
示例6: PlaySoundOnce
// Sound einmal abspielen
void PlaySoundOnce(LPDIRECTSOUNDBUFFER lpDSB, int pan, int vol)
{
if(lpDSB)
{
lpDSB->SetPan(pan);
lpDSB->SetVolume(vol);
lpDSB->Play(0,0,0);
}
}
示例7: DSUtil_PlayPannedSound
//-----------------------------------------------------------------------------
// Name: DSUtil_PlayPannedSound()
// Desc: Play a sound, but first set the panning according to where the
// object is on the screen. fScreenXPos is between -1.0f (left) and
// 1.0f (right).
//-----------------------------------------------------------------------------
VOID DSUtil_PlayPannedSound( SoundObject* pSound, FLOAT fScreenXPos )
{
LPDIRECTSOUNDBUFFER pDSB = DSUtil_GetFreeSoundBuffer( pSound );
if( pDSB )
{
pDSB->SetPan( (LONG)( 10000L * fScreenXPos ) );
pDSB->Play( 0, 0, 0 );
}
}
示例8: 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();
}
示例9: 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;
}
}
示例10: 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 );
}
}
}