⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soundinstance.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 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_Valid = false;
}

CSoundInstance::~CSoundInstance()
{
  UnInit();
}

void CSoundInstance::Init(CSound *sound)
{
  // use the supplied sound as a template for this instance
  // currently nothing to set, but this will grow in later chapters.

  GetAudioManager()->GetPerformance()->PlaySegmentEx(sound->GetSegment(), NULL, NULL,
    DMUS_SEGF_SECONDARY, 0, 
    (IDirectMusicSegmentState **)&m_SegmentState, 
    NULL, NULL);

  m_Valid = true;
}

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);
}

}; // namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -