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

📄 openalsource.cpp

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

#pragma warning(disable: 4786)
#include <sstream>

#ifdef WIN32
#include <windows.h>
#endif

#include "OpenALSource.h"
#include "ErrorHandling.h"

using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace AudioEngine {

COpenALSource::COpenALSource()
{
  m_ID = -1;
}

COpenALSource::~COpenALSource()
{
  // it's possible this source is no more, if OpenAL has already been
  // uninit'd.
  if (alIsSource(m_ID) == AL_TRUE) {
    alDeleteSources(1, &m_ID);
  }
}

void COpenALSource::LinkToBuffer(COpenALBufferPtr linkto)
{
  alSourcei(m_ID, AL_BUFFER, linkto->GetID());
  if (alGetError() != AL_NO_ERROR) {
    Throw("COpenALSource::LinkToBuffer: error linking to OpenAL buffer.");
  }
  m_Buffer = linkto;
}

void COpenALSource::Play()
{
  if (alIsSource(m_ID) == AL_TRUE) {
    alSourcePlay(m_ID);  
  }
}
void COpenALSource::Pause()
{
  if (alIsSource(m_ID) == AL_TRUE) {
    alSourcePause(m_ID);  
  }
}

void COpenALSource::Stop()
{
  if (alIsSource(m_ID) == AL_TRUE) {
    alSourceStop(m_ID);  
  }
}

void COpenALSource::Rewind()
{
  if (alIsSource(m_ID) == AL_TRUE) {
    alSourceRewind(m_ID);  
  }
}




COpenALSourcePtr::COpenALSourcePtr(COpenALSource* p) : CRefCountPtr<COpenALSource>(p) 
{ 
#ifdef WIN32
  stringstream str;
  if (p) {
    str << "COpenALSourcePtr::COpenALSourcePtr: constructed for pointer " << p 
      << " (count = " << itsCounter->count << ")..." << endl;
    OutputDebugString(str.str().c_str());
  }
#endif
}

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





} // namespace

⌨️ 快捷键说明

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