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

📄 sound.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 CPP
字号:
// AudioEngineSound.cpp: implementation of the CSound class.
//
//////////////////////////////////////////////////////////////////////

#include "Sound.h"
#include "AudioManager.h"

#include <sstream>

using namespace std;

namespace AudioEngine {

CSoundPtr::CSoundPtr(CSound* p) : CRefCountPtr<CSound>(p) 
{ 
  stringstream str;
  if (p) {
    str << "CSoundPtr::CSoundPtr: constructed for pointer " << p << 
      " (count = " << itsCounter->count << ")..." << endl;
    OutputDebugString(str.str().c_str());
  }
  
}

void CSoundPtr::Release()
{
  stringstream str;
  if (itsCounter) {
    str << "CSoundPtr::Release(): pointer " << itsCounter->ptr << 
      " (count = " << itsCounter->count << ")..." << endl;
    OutputDebugString(str.str().c_str());
  }
}


CSound::CSound(CAudioManager *mgr)
{
  m_Manager = mgr;
  m_Segment = NULL;
  m_SegmentState = NULL;
  m_OriginalData = NULL;
}

CSound::~CSound()
{
  if (NULL != m_Segment && m_Manager->GetPerformance()) {
    m_Segment->Unload(m_Manager->GetPerformance());
  }

  SAFE_RELEASE(m_Segment);
  SAFE_RELEASE(m_SegmentState);

  SAFE_DELETE(m_OriginalData);
}

/****************************************************************************
 *
 * CSound::IsPlaying: returns true if the sound is playing, false otherwise.
 *
 ****************************************************************************/
bool CSound::IsPlaying()
{
  if (NULL == m_Segment) return(false);
  if (NULL == m_Manager) return(false);

  return(m_Manager->GetPerformance()->IsPlaying(NULL, m_SegmentState) == S_OK);
}

/****************************************************************************
 *
 * CSound::IsPlaying: Plays a sound.  Returns true if the sound plays.
 *
 ****************************************************************************/
bool CSound::Play()
{
  if (NULL == m_Segment) return(false);
  if (NULL == m_Manager) return(false);

  m_Segment->Download(m_Manager->GetPerformance());
  m_Manager->GetPerformance()->PlaySegmentEx(m_Segment, NULL, NULL,
    DMUS_SEGF_SECONDARY, 0, (IDirectMusicSegmentState **)&m_SegmentState, 
    NULL, NULL);
  return(true);
}

}; // namespace

⌨️ 快捷键说明

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