📄 music.cpp
字号:
// ==========================================================================================================
//
// BREW v2.0+ OPENGLES MICROENGINE
//
// ----------------------------------------
//
// Written by Vander Nunes
//
// ==========================================================================================================
#include "music.h"
// --------------------------------------------------------------------------------------
//
// Constructor
//
// --------------------------------------------------------------------------------------
CMusic::CMusic(CEngine* pEngine)
{
m_pData = NULL;
m_pEngine = pEngine;
}
// --------------------------------------------------------------------------------------
//
// Destructor
//
// --------------------------------------------------------------------------------------
CMusic::~CMusic()
{
CleanUp();
}
// --------------------------------------------------------------------------------------
//
// Release memory
//
// --------------------------------------------------------------------------------------
void CMusic::CleanUp()
{
if (m_pData)
{
Stop();
API_FREE(m_pData);
m_pData = NULL;
m_pInfo.pData = NULL;
m_pInfo.dwSize = 0;
}
}
// --------------------------------------------------------------------------------------
//
// Load 2D sprite bitmap from the game dat file (vfs)
//
// --------------------------------------------------------------------------------------
boolean CMusic::LoadFromVfs(char* szVfsFile, char* szFile)
{
CleanUp();
CVfs Vfs;
if (!Vfs.Unpack(szVfsFile, szFile, m_pEngine->Applet()))
return FALSE;
m_pData = new byte[Vfs.FileSize()];
Vfs.Read(m_pData, Vfs.FileSize());
m_pInfo.eInput = SDT_BUFFER;
m_pInfo.pData = m_pData;
m_pInfo.dwSize = Vfs.FileSize();
Vfs.Finish();
return true;
}
// --------------------------------------------------------------------------------------
//
// Load 2D sprite bitmap from the conventional resource file
//
// --------------------------------------------------------------------------------------
boolean CMusic::LoadFromRes(char* szResFile, int16 sRes)
{
CleanUp();
dword dwSize;
AEEResBlob* blob = NULL;
blob = (AEEResBlob*)ISHELL_LoadResDataEx(m_pEngine->Applet()->m_pIShell, szResFile, sRes, RESTYPE_IMAGE, blob, &dwSize);
m_pData = (byte*)API_MALLOC(dwSize);
API_MEMCPY(m_pData, RESBLOB_DATA(blob), dwSize);
m_pInfo.eInput = SDT_BUFFER;
m_pInfo.pData = m_pData;
m_pInfo.dwSize = dwSize;
ISHELL_FreeResData(m_pEngine->Applet()->m_pIShell, blob);
return true;
}
// --------------------------------------------------------------------------------------
//
// SoundPlayer status callback
//
// --------------------------------------------------------------------------------------
void SoundCallBack(void *pUser, AEESoundPlayerCmd eCBType, AEESoundPlayerStatus eSPStatus, uint32 dwParam)
{
CMusic* pMusic = (CMusic*)pUser;
switch (eCBType)
{
case AEE_SOUNDPLAYER_PLAY_CB:
{
//
// Play() command status notification
//
switch (eSPStatus)
{
case AEE_SOUNDPLAYER_DONE:
{
//
// finished playing...
// repeat
pMusic->Play(true);
break;
}
}
break;
}
}
}
// --------------------------------------------------------------------------------------
//
// Play the loaded music
//
// --------------------------------------------------------------------------------------
boolean CMusic::Play(boolean bRepeat)
{
if (!m_pData) return FALSE;
Stop();
dword i = ISOUNDPLAYER_SetInfo(m_pEngine->SoundPlayer(), &m_pInfo);
if (bRepeat)
ISOUNDPLAYER_RegisterNotify(m_pEngine->SoundPlayer(), SoundCallBack, this);
else
ISOUNDPLAYER_RegisterNotify(m_pEngine->SoundPlayer(), NULL, NULL);
if (i == AEE_SUCCESS) ISOUNDPLAYER_Play(m_pEngine->SoundPlayer());
return (i == AEE_SUCCESS);
}
// --------------------------------------------------------------------------------------
//
// Stop the loaded music
//
// --------------------------------------------------------------------------------------
void CMusic::Stop(void)
{
ISOUNDPLAYER_RegisterNotify(m_pEngine->SoundPlayer(), NULL, NULL);
ISOUNDPLAYER_Stop(m_pEngine->SoundPlayer());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -