soundinstance.cpp
来自「游戏音频程序设计-Beginning.Game.Audio.Programmin」· C++ 代码 · 共 61 行
CPP
61 行
// 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_Valid = false;
}
CSoundInstance::~CSoundInstance()
{
UnInit();
}
void CSoundInstance::Init(CSound *sound)
{
HRESULT hr;
// use the supplied sound as a template for this instance
// currently nothing to set, but this will grow in later chapters.
m_Valid = true;
hr = GetAudioManager()->GetPerformance()->PlaySegmentEx(sound->GetSegment(), NULL, NULL,
DMUS_SEGF_SECONDARY, 0,
(IDirectMusicSegmentState **)&m_SegmentState,
NULL, NULL);
ThrowIfFailed(hr, "CSoundInstance::Init: PlaySegmentEx failed.");
}
void CSoundInstance::UnInit()
{
SAFE_RELEASE(m_SegmentState);
m_Valid = false;
}
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 + =
减小字号Ctrl + -
显示快捷键?