本文整理汇总了C++中LPDIRECTSOUNDBUFFER::SetFrequency方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUNDBUFFER::SetFrequency方法的具体用法?C++ LPDIRECTSOUNDBUFFER::SetFrequency怎么用?C++ LPDIRECTSOUNDBUFFER::SetFrequency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTSOUNDBUFFER
的用法示例。
在下文中一共展示了LPDIRECTSOUNDBUFFER::SetFrequency方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: StreamStart
int StreamStart(V3XA_STREAM handle)
{
DS_stream *pStr = g_pDSStreams + handle;
LPDIRECTSOUNDBUFFER pSrc = g_pDSHandles[pStr->channel].pbuffer;
SYS_ASSERT(pSrc);
SYS_ASSERT(pStr->nState & 1);
if (((pStr->nState&1)==0)||(!pSrc))
{
return 0;
}
if (SYS_DXTRACE(pSrc->Play(0, 0, DSBPLAY_LOOPING))!=DS_OK)
return 0;
SYS_DXTRACE(pSrc->SetCurrentPosition( 0 ));
SYS_DXTRACE(pSrc->SetFrequency( pStr->sample.samplingRate ));
pStr->m_nPreviousPosition = 0;
pStr->m_nUploadedBytes = 0;
pStr->m_nWritePosition = 0;
pStr->m_nStreamState = 1;
pStr->m_nTotalBytes = 0;
pStr->m_nUploadedBytes = 0;
pStr->m_nWriteBytes = 0;
return 0;
}
示例5: DXUT_ERR
//-----------------------------------------------------------------------------
// Name: CSound::Play3D()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CSound::Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority, DWORD dwFlags, LONG lFrequency )
{
HRESULT hr;
BOOL bRestored;
DWORD dwBaseFrequency;
if( m_apDSBuffer == NULL )
return CO_E_NOTINITIALIZED;
LPDIRECTSOUNDBUFFER pDSB = GetFreeBuffer();
if( pDSB == NULL )
return DXUT_ERR( L"GetFreeBuffer", E_FAIL );
// Restore the buffer if it was lost
if( FAILED( hr = RestoreBuffer( pDSB, &bRestored ) ) )
return DXUT_ERR( L"RestoreBuffer", hr );
if( bRestored )
{
// The buffer was restored, so we need to fill it with new data
if( FAILED( hr = FillBufferWithSound( pDSB, FALSE ) ) )
return DXUT_ERR( L"FillBufferWithSound", hr );
}
if( m_dwCreationFlags & DSBCAPS_CTRLFREQUENCY )
{
pDSB->GetFrequency( &dwBaseFrequency );
pDSB->SetFrequency( dwBaseFrequency + lFrequency );
}
// 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->Play( 0, dwPriority, dwFlags );
}
pDS3DBuffer->Release();
}
return hr;
}
示例6: 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;
}
示例7: 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;
}
}
示例8: ChannelSetSamplingRate
/*------------------------------------------------------------------------
*
* PROTOTYPE : void ChannelSetSamplingRate(int chan, int freq)
*
* DESCRIPTION : Set frequency.
*
*/
static void ChannelSetSamplingRate(int chan, int freq)
{
LPDIRECTSOUNDBUFFER pDS = g_pDSHandles[chan].pbuffer;
if (!pDS) return;
pDS->SetFrequency(freq);
}
示例9: 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 );
}
}
}