📄 soundinstance.cpp
字号:
// SoundInstance.cpp: implementation of the CSoundInstance class.
//
//////////////////////////////////////////////////////////////////////
#include "SoundInstance.h"
#include "Sound.h"
#include "AudioManager.h"
#include <assert.h>
namespace AudioEngine {
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSoundInstance::CSoundInstance()
{
m_SegmentState = NULL;
m_AudioPath = NULL;
m_Valid = false;
}
CSoundInstance::~CSoundInstance()
{
UnInit();
}
void CSoundInstance::Init(CDirectMusicSegment *seg, IDirectMusicAudioPath8 *path)
{
HRESULT hr;
m_AudioPath = path;
m_Valid = true;
// set volume based on sound's volume
SetVolume(seg->GetVolume());
// now that everything's set, go ahead and play it.
hr = GetAudioManager()->GetPerformance()->PlaySegmentEx(seg->GetSegment(), NULL, NULL,
DMUS_SEGF_SECONDARY, 0,
(IDirectMusicSegmentState **)&m_SegmentState,
NULL, path);
ThrowIfFailed(hr, "CSoundInstance::Init: PlaySegmentEx failed.");
}
void CSoundInstance::UnInit()
{
SAFE_RELEASE(m_SegmentState);
SAFE_RELEASE(m_AudioPath);
m_Valid = false;
}
void CSoundInstance::SetVolume(const CVolume &vol, int fadeoverms)
{
assert(IsValid()); if (!IsValid()) { return; }
m_AudioPath->SetVolume(vol.ToDirectMusic(), fadeoverms);
}
bool CSoundInstance::IsPlaying()
{
assert(IsValid()); if (!IsValid()) { return(false); }
return(GetAudioManager()->GetPerformance()->IsPlaying(NULL, m_SegmentState) == S_OK);
}
bool CSoundInstance::Stop(MUSIC_TIME time, DWORD flags)
{
return(SUCCEEDED(GetAudioManager()->GetPerformance()->Stop(NULL, m_SegmentState, time, flags)));
}
}; // namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -