当前位置: 首页>>代码示例>>C++>>正文


C++ IDirectSoundBuffer::Restore方法代码示例

本文整理汇总了C++中IDirectSoundBuffer::Restore方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::Restore方法的具体用法?C++ IDirectSoundBuffer::Restore怎么用?C++ IDirectSoundBuffer::Restore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDirectSoundBuffer的用法示例。


在下文中一共展示了IDirectSoundBuffer::Restore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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" );
	}
}
开发者ID:gene9,项目名称:Darwinia-and-Multiwinia-Source-Code,代码行数:32,代码来源:sound_library_3d_dsound.cpp

示例2: Stream

void DirectSoundStreamer::Stream( void const *pSamples )
{
    // Verify buffer availability
    DWORD play, write;
    if( FAILED( m_pDirectSoundBuffer->GetCurrentPosition( &play, &write ) ) )
        return;
    if( write < play )
        write += DWORD( m_physical );
    std::size_t begin( m_begin );
    if( begin < play )
        begin += m_physical;
    if( begin < write )
        begin = std::size_t( write );
    std::size_t end( begin + m_stream );
    if( play + m_virtual < end )
        return;
    begin %= m_physical;

    // Copy samples to buffer
    void *ps[ 2 ];
    DWORD sizes[ 2 ];
    HRESULT hResult( m_pDirectSoundBuffer->Lock( DWORD( begin ), DWORD( m_stream ), &ps[ 0 ], &sizes[ 0 ], &ps[ 1 ], &sizes[ 1 ], 0 ) );
    if( FAILED( hResult ) )
    {
        if( hResult != DSERR_BUFFERLOST )
            return;
        m_pDirectSoundBuffer->Restore();
        if( FAILED( m_pDirectSoundBuffer->Lock( DWORD( begin ), DWORD( m_stream ), &ps[ 0 ], &sizes[ 0 ], &ps[ 1 ], &sizes[ 1 ], 0 ) ) )
            return;
    }
    using std::memcpy;
    memcpy( ps[ 0 ], pSamples, std::size_t( sizes[ 0 ] ) );
    if( ps[ 1 ] )
        memcpy( ps[ 1 ], static_cast< char const * >( pSamples ) + sizes[ 0 ], std::size_t( sizes[ 1 ] ) );
    m_pDirectSoundBuffer->Unlock( ps[ 0 ], sizes[ 0 ], ps[ 1 ], sizes[ 1 ] );

    // Select next buffer
    m_begin = end % m_physical;
}
开发者ID:fesh0r,项目名称:beebem,代码行数:39,代码来源:beebsound.cpp


注:本文中的IDirectSoundBuffer::Restore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。