//#include "stdafx.h"
#ifndef AK_OPTIMIZED
#include <AK/Comm/AkCommunication.h> // Communication between Wwise and the game (excluded in release build)
#endif // AK_OPTIMIZED
//#ifdef AK_MOTION
//#include <AK/MotionEngine/Common/AkMotionEngine.h> // Motion Engine (required only for playback of Motion objects)
//#endif // AK_MOTION
#include <AK/SoundEngine/Common/AkMemoryMgr.h> // Memory Manager interface
#include <AK/SoundEngine/Common/AkModule.h> // Default memory manager
#include <AK/SoundEngine/Common/IAkStreamMgr.h> // Streaming Manager
#include <AK/Tools/Common/AkPlatformFuncs.h> // �̶߳���
#include <AK/SoundEngine/Common/AkStreamMgrModule.h> // AkStreamMgrModule
#include <AK/SoundEngine/Common/AkSoundEngine.h>
#include <AK/MusicEngine/Common/AkMusicEngine.h>
#include <AK/SpatialAudio/Common/AkSpatialAudio.h>
#include "AkFilePackageLowLevelIOBlocking.h" //注意,这个地方安卓,ios,window地址
#include <AK/Plugin/AkPeakLimiterFXFactory.h>
#include <AK/Plugin/AkDelayFXFactory.h>
#include <AK/Plugin/AkMatrixReverbFXFactory.h>
#include <AK/Plugin/AkRoomVerbFXFactory.h>
#include <AK/Plugin/AkStereoDelayFXFactory.h>
#include <AK/Plugin/AkSynthOneSourceFactory.h>
#include <AK/Plugin/AkToneSourceFactory.h>
#include <AK/Plugin/AkParametricEQFXFactory.h>
#include <AK/Plugin/AkAudioInputSourceFactory.h>
#include <AK/Plugin/AkAudioInputPlugin.h>
#include <AK/SoundEngine/Common/AkTypes.h>
#include <PostObj.h>
#include <PostEventGan.h>
//#include "ScriptEngine.hpp"
// Ak core libs
#if defined(WIN32)
#pragma comment( lib, "AkMemoryMgr.lib")
#pragma comment( lib, "AkSpatialAudio.lib")
#pragma comment( lib, "AkSoundEngine.lib")
#pragma comment( lib, "AkStreamMgr.lib")
#pragma comment( lib, "AkMusicEngine.lib")
#pragma comment( lib, "dxguid.lib") //DirectSound
#pragma comment( lib, "AkPeakLimiterFX.lib")
#pragma comment( lib, "AkDelayFX.lib")
#pragma comment( lib, "AkMatrixReverbFX.lib")
#pragma comment( lib, "AkRoomVerbFX.lib")
#pragma comment( lib, "AkStereoDelayFX.lib")
#pragma comment( lib, "AkSynthOneSource.lib")
#pragma comment( lib, "AkToneSource.lib")
#pragma comment( lib, "AkParametricEQFX.lib")
#pragma comment( lib, "AkAudioInputSource.lib")
#ifdef _DEBUG
#pragma comment( lib, "CommunicationCentral")
#endif
#endif
static const AkGameObjectID LISTENER_ID = 0;
namespace AK
{
#ifdef WIN32
// Note: VirtualAllocHook() may be used by I/O pools of the default implementation
// of the Stream Manager, to allow "true" unbuffered I/O (using FILE_FLAG_NO_BUFFERING
// - refer to the Windows SDK documentation for more details). This is NOT mandatory;
// you may implement it with a simple malloc().
void * VirtualAllocHook(
void * in_pMemAddress,
size_t in_size,
AkUInt32 in_dwAllocationType,
AkUInt32 in_dwProtect
)
{
return VirtualAlloc(in_pMemAddress, in_size, in_dwAllocationType, in_dwProtect);
}
void VirtualFreeHook(
void * in_pMemAddress,
size_t in_size,
AkUInt32 in_dwFreeType
)
{
VirtualFree(in_pMemAddress, in_size, in_dwFreeType);
}
#endif
}
#include "YLWwiseEngine.h"
#include <android/log.h>
static YLWwiseEngine* instance = 0;
YLWwiseEngine::YLWwiseEngine()
{
m_pLowLevelIO = new CAkFilePackageLowLevelIOBlocking();
}
YLWwiseEngine::~YLWwiseEngine()
{
delete m_pLowLevelIO;
m_pLowLevelIO = NULL;
}
YLWwiseEngine* YLWwiseEngine::getInstance()
{
if (instance == 0)
{
instance = new YLWwiseEngine();
}
return instance;
}
void YLWwiseEngine::destroy()
{
if (instance != 0)
{
delete instance;
instance = 0;
}
}
/**
void YLWwiseEngine::postCallback(AkCallbackType in_eType, AkCallbackInfo* in_pCallbackInfo)
{
if (in_eType == AK_EndOfEvent)
{
printf("postEventʧ�ܣ���������%d\n", in_eType);
}
}
**/
bool YLWwiseEngine::init(const char* basePath)
{
char * name = "mronion";
__android_log_print(ANDROID_LOG_INFO, "lclclc", "-------my name111111111-------- is %s\n", basePath); //log i类型
AkMemSettings memSettings;
AK::MemoryMgr::GetDefaultSettings(memSettings);
if (AK::MemoryMgr::Init(&memSettings) != AK_Success)
{
return false;
}
AkStreamMgrSettings stmSettings;
AK::StreamMgr::GetDefaultSettings(stmSettings);
// �ڴ��Զ��� Stream Manager ���á�
if (!AK::StreamMgr::Create(stmSettings))
{
return false;
}
AkDeviceSettings deviceSettings;
AK::StreamMgr::GetDefaultDeviceSettings(deviceSettings);
deviceSettings.bUseStreamCache = true;
if (m_pLowLevelIO->Init(deviceSettings) != AK_Success)
{
return false;
}
AkInitSettings initSettings;
AkPlatformInitSettings platformInitSettings;
AK::SoundEngine::GetDefaultInitSettings(initSettings);
AK::SoundEngine::GetDefaultPlatformInitSettings(platformInitSettings);
if (AK::SoundEngine::Init(&initSettings, &platformInitSettings) != AK_Success)
{
return false;
}
AkMusicSettings musicInit;
AK::MusicEngine::GetDefaultInitSettings(musicInit);
if (AK::MusicEngine::Init(&musicInit) != AK_Success)
{
return false;
}
AkSpatialAudioInitSettings settings; // ���캯���������Ĭ�����ø��� AkSpatialAudioInitSettings��
if (AK::SpatialAudio::Init(settings) != AK_Success)
{
return false;
}
#ifndef AK_OPTIMIZED
//
// Initialize communications (not in release build!)
//
AkCommSettings commSettings;
AK::Comm::GetDefaultInitSettings(commSettings);
commSettings.ports.uDiscoveryBroadcast = 15000;
if (AK::Comm::Init(commSettings) != AK_Success)
{
return false;
}
#endif
// ��������
AK::SoundEngine::RegisterGameObj(LISTENER_ID, "Listener (Default)");
AK::SoundEngine::SetDefaultListeners(&LISTENER_ID, 1);
// �������ߵ�λ��
this->setListenerPosition(0, 0, 0);
char *basePaeht1 = new char[strlen(basePath)+1];
strcpy(basePaeht1,basePath);
AKRESULT ret = m_pLowLevelIO->SetBasePath(basePaeht1);
if (ret != AK_Success)
{
return false;
}
// ��������
if (AK::StreamMgr::SetCurrentLanguage(AKTEXT("English(US)")) != AK_Success)
{
return false;
}
return true;
}
void YLWwiseEngine::uninit()
{
#ifndef AK_OPTIMIZED
AK::Comm::Term();
#endif
//
// Terminate Spatial Audio
//
//AK::SpatialAudio::Term();
//
// ��ֹ��������
//
AK::MusicEngine::Term();
//
// ��ֹ��������
//
AK::SoundEngine::Term();
// ��ֹ�������豸�������Ź�����
// CAkFilePackageLowLevelIOBlocking::Term() ���� Stream Manager ��
// ������ص��������豸����ע���Լ��� File Location Resolver ��ݡ�
m_pLowLevelIO->Term();
if (AK::IAkStreamMgr::Get())
AK::IAkStreamMgr::Get()->Destroy();
// ��ֹ Memory Manager
AK::MemoryMgr::Term();
}
void YLWwiseEngine::update()
{
// ������Ƶ�������¼���λ�á�RTPC ��
AK::SoundEngine::RenderAudio();
}
int YLWwiseEngine::loadBank(const char* fileName)
{
__android_log_print(ANDROID_LOG_INFO, "lclclc", "-------loadBank--------fileName is %s\n", fileName); //log i类型
int id = this->getID();
AkBankID bankID; // δʹ�á���Щ SoundBank ����ͨ�����ǵ��ļ�����ж�ء�
AKRESULT eResult = AK::SoundEngine::LoadBank(fileName, bankID);
if (eResult != AK_Success)
{
printf("���صĴ�������%d\n", eResult);
return 0;
}
return id;
}
void YLWwiseEngine::unloadBank(const char* filename)
{
AkBankID bankID; // δʹ�á���Щ SoundBank ����ͨ�����ǵ��ļ�����ж�ء�
AKRESULT eResult = AK::SoundEngine::UnloadBank(filename, NULL);
if (eResult != AK_Success)
{
printf("���صĴ�������%d\n", eResult);
}
}
int YLWwiseEngine::getID()
{
static int id = 1;
return id++;
}
void YLWwiseEngine::registerGameObject(unsigned int id, const char* name)
{
__android_log_print(ANDROID_LOG_INFO, "lclclc", "------registerGameObject-------- is %s\n", name); //log i类型
AKRESULT eResult = AK::SoundEngine::RegisterGameObj(id, name);
if (eResult != AK_Success)
{
printf("ע��gameObjectʧ�ܣ���������%d\n", eResult);
}
}
void YLWwiseEngine::unregisterGameObject(unsigned int id)
{
AK::SoundEngine::UnregisterGameObj(id);
}
void YLWwiseEngine::setDefaultListener(const int id)
{
AKRESULT eResult = AK::SoundEngine::SetDefaultListeners((AkGameObjectID*)&id, 1);
if (eResult != AK_Success)
{
printf("����Ĭ������ʧ�ܣ���������%d\n", eResult);
}
}
int YLWwiseEngine::postEventFun(const char* eventName, unsigned int gameObjectId, unsigned int funId)
{
//char *pCh= strcpy_s(eventName, const char *);
char* pcname = new char[100];//锟姐够锟斤拷
strcpy(pcname, eventName);
PostObj* postobj = new PostObj();
postobj->funId = funId;
postobj->eventName = pcname;
//postobj->gameObjectId = gameObjectId;
//postobj->eventID = AK::SoundEngine::GetIDFromString(eventName);
AkPlayingID id = AK::SoundEngine::PostEvent(eventName, gameObjectId,
AK_EndOfEvent | AK_Marker | AK_EnableGetSourcePlayPosition,
PostEventGan::getInstance()->postCallback, postobj);
if (id == AK_INVALID_PLAYING_ID)
{
printf("postEvent失锟杰o拷锟斤拷锟斤拷锟斤拷锟斤拷%d\n", id);
return 0;
}
return 1;
}
int YLWwiseEngine::postEvent(const char* eventName, unsigned int gameObjectId)
{
__android_log_print(ANDROID_LOG_INFO, "lclclc", "-------postEvent--------eventName is %s\n", eventName); //log i类型
AkPlayingID id = AK::SoundEngine::PostEvent(eventName, gameObjectId,
AK_EnableGetSourcePlayPosition, NULL, NULL);
this->update();
if (id == AK_INVALID_PLAYING_ID)
{
printf("postEventʧ�ܣ���������%d\n", id);
return 0;
}
return id;
}
void YLWwiseEngine::setGameObjectPosition(unsigned int id, float x, float y, float z)
{
AkVector position;
position.X = x;
position.Y = y;
position.Z = z;
AkVector orientationFront;
orientationFront.Z = 1;
orientationFront.Y = orientationFront.X = 0;
AkVector orientationTop;
orientationTop.X = orientationTop.Z = 0;
orientationTop.Y = 1;
AkSoundPosition soundPos;
soundPos.Set(position, orientationFront, orientationTop);
AKRESULT ret = AK::SoundEngine::SetPosition(id, soundPos);
this->update();
if (ret != AK_Success)
{
printf("����λ��ʧ�ܣ���������%d\n", ret);
}
}
int YLWwiseEngine::getSourcePosition(int id)
{
AkTimeMs uPosition = -1;
// ����Ϸѭ����ij��λ�ã������Է�������
AK::SoundEngine::GetSourcePlayPosition(id, &uPosition);
return uPosition;
}
int YLWwiseEngine::GetIDFromString(const char* eventName)
{
return AK::SoundEngine::GetIDFromString(eventName);
}
int YLWwiseEngine::setSwitch(const char* groupName, const char* name, unsigned int gameid)
{
AKRESULT ret = AK::SoundEngine::SetSwitch(groupName, name, gameid);
if (ret != AK_Success)
{
printf("����switchʱʧ�ܣ���������%d\n", ret);
}
return ret;
}
int YLWwiseEngine::setState(const char* groupName, const char* name)
{
AKRESULT ret = AK::SoundEngine::SetState(groupName, name);
if (ret != AK_Success)
{
printf("����stateʱʧ�ܣ���������%d\n", ret);
}
return ret;
}
void YLWwiseEngine::pauseAll()
{
AK::SoundEngine::Suspend(true);
}
void YLWwiseEngine::resumeAll()
{
AK::SoundEngine::WakeupFromSuspend();
}
unsigned int YLWwiseEngine::getGameObjectId()
{
static unsigned int id = 1;
return id++;
}
void YLWwiseEngine::SetCurrentLanguage(const char* language)
{
size_t len = strlen(language) + 1;
size_t converted = 0;
// wchar_t* WStr;
// WStr = (wchar_t*)malloc(len * sizeof(wchar_t));
// mbstowcs_s(&converted, WStr, len, language, _TRUNCATE);
// AKRESULT ret = AK::StreamMgr::SetCurrentLanguage(WStr);
// free(WStr);
// if (ret != AK_Success)
// {
// printf("��������ʱ������������%d\n", ret);
// }
}
void YLWwiseEngine::stopEvent(unsigned int eventid,unsigned int fadetime)
{
AK::SoundEngine::StopPlayingID(eventid,fadetime);
}
void YLWwiseEngine::setGameObjectVolume(unsigned int gameobj, unsigned int listenerobj, unsigned int volume)
{
AKRESULT ret = AK::SoundEngine::SetGameObjectOutputBusVolume(gameobj, listenerobj, volume / 100.0);
this->update();
if (ret != AK_Success)
{
printf("��������ʧ�ܣ���������%d\n", ret);
}
}
void YLWwiseEngine::stopGameObjectAll(unsigned int id)
{
AK::SoundEngine::StopAll(id);
}
void YLWwiseEngine::addBasePath(const char* basePath)
{
__android_log_print(ANDROID_LOG_INFO, "lclclc", "-------addBasePath-------- is %s\n", basePath); //log i类型
//char* basePaeht1 = new char[200];
//strcpy(basePaeht1,basePath);
AKRESULT ret = m_pLowLevelIO->AddBasePath(basePath);
if (ret != AK_Success)
{
printf("����·��ʱ������������%d\n", ret);
}
}
unsigned int YLWwiseEngine::loadFilePackage(const char* path)
{
__android_log_print(ANDROID_LOG_INFO, "lclclc", "------loadFilePackage-------- path is %s\n", path); //log i类型
AkUInt32 id = 0;
// size_t len = strlen(path) + 1;
// size_t converted = 0;
// wchar_t* WStr;
// WStr = (wchar_t*)malloc(len * sizeof(wchar_t));
// mbstowcs_s(&converted, WStr, len, path, _TRUNCATE);
AKRESULT ret = m_pLowLevelIO->LoadFilePackage(path, id);
// free(WStr);
if (ret != AK_Success)
{
printf("�����ļ���ʱ������������%d\n", ret);
return 0;
}
return id;
}
void YLWwiseEngine::unloadFilePackage(unsigned int id)
{
AKRESULT ret = m_pLowLevelIO->UnloadFilePackage(id);
if (ret != AK_Success)
{
printf("ж��pck�ļ�ʱ������������%d\n", ret);
}
}
void YLWwiseEngine::unloadFilePackageAll()
{
AKRESULT ret = m_pLowLevelIO->UnloadAllFilePackages();
if (ret != AK_Success)
{
printf("ж��pck�ļ�ʱ������������%d\n", ret);
}
}
void YLWwiseEngine::setListenerPosition(float x, float y, float z)
{
AkVector position;
position.X = x;
position.Y = y;
position.Z = z;
AkVector orientationFront;
orientationFront.Z = 1;
orientationFront.Y = orientationFront.X = 0;
AkVector orientationTop;
orientationTop.X = orientationTop.Z = 0;
orientationTop.Y = 1;
AkTransform soundPos;
soundPos.Set(position, orientationFront, orientationTop);
AK::SoundEngine::SetPosition(LISTENER_ID, soundPos);
}
int YLWwiseEngine::wwisePostTrigger(const char* eventName, unsigned int in_gameObjectID)
{
AKRESULT ret = AK::SoundEngine::PostTrigger(eventName, in_gameObjectID);
if (ret != AK_Success)
{
printf("����ʱ������������%d\n", ret);
}
return ret;
}
void YLWwiseEngine::SetGameObjectOutputBusVolume(unsigned int gameObjectID, unsigned int listergameObjectID, float value)
{
AK::SoundEngine::SetGameObjectOutputBusVolume(gameObjectID, listergameObjectID, value);
}
void YLWwiseEngine::UnregisterAllGameObj()
{
AK::SoundEngine::UnregisterAllGameObj();
}
int YLWwiseEngine::ExecuteActionOnEvent(const char* eventName, unsigned int actionType, unsigned int gameObject, unsigned int transitionDuration, unsigned int fadeCurve)
{
AKRESULT ret;
if (actionType == 0) {
// if (fadeCurve == 0)
// {
// ret = AK::SoundEngine::ExecuteActionOnEvent(eventName,
// AK::SoundEngine::AkActionOnEventType::AkActionOnEventType_Stop,
// gameObjectid,
// transitionDuration,
// AkCurveInterpolation_Log3
// );
// }
// else if (fadeCurve == 1)
// {
// ret = AK::SoundEngine::ExecuteActionOnEvent(eventName,
// AK::SoundEngine::AkActionOnEventType::AkActionOnEventType_Stop,
// gameObjectid,
// transitionDuration,
// AkCurveInterpolation_Sine
// );
// }
// else if (fadeCurve == 2)
// {
// ret = AK::SoundEngine::ExecuteActionOnEvent(eventName,
// AK::SoundEngine::AkActionOnEventType::AkActionOnEventType_Stop,
// gameObjectid,
// transitionDuration,
// AkCurveInterpolation_Log1
// );
// }
// else if (fadeCurve == 3)
// {
// ret = AK::SoundEngine::ExecuteActionOnEvent(eventName,
// AK::SoundEngine::AkActionOnEventType::AkActionOnEventType_Stop,
// gameObjectid,
// transitionDuration,
// AkCurveInterpolation_InvSCurve
// );
//
// }
}
if (ret != AK_Success)
{
printf("����ʱ������������%d\n", ret);
}
return ret;
}
void YLWwiseEngine::SetObjectObstructionAndOcclusion(unsigned int emitterGameObjectid, unsigned int listenerGameObjectid, float Obstruction, float Occlusion)
{
AK::SoundEngine::SetObjectObstructionAndOcclusion(emitterGameObjectid, 0, Obstruction, Occlusion);
}
int YLWwiseEngine::SetRTPCValue(const char* pszRtpcName,unsigned int in_value, unsigned int gameObjectID)
{
AK::SoundEngine::SetRTPCValue(pszRtpcName, in_value, gameObjectID );
return 1;
}
void YLWwiseEngine::setIDListenerPosition(float x, float y, float z, unsigned int LISTENER_ID1)
{
AkVector position;
position.X = x;
position.Y = y;
position.Z = z;
AkVector orientationFront;
orientationFront.Z = 1;
orientationFront.Y = orientationFront.X = 0;
AkVector orientationTop;
orientationTop.X = orientationTop.Z = 0;
orientationTop.Y = 1;
AkTransform soundPos;
soundPos.Set(position, orientationFront, orientationTop);
AK::SoundEngine::SetPosition(LISTENER_ID1, soundPos);
}
#pragma once
class CAkFilePackageLowLevelIOBlocking;
#include <functional>
class YLWwiseEngine
{
public:
YLWwiseEngine();
~YLWwiseEngine();
public:
static YLWwiseEngine* getInstance();
static void destroy();
static unsigned int getGameObjectId();
//ceshi
typedef std::function<void(const std::string& msg, const int val)> ResultCallback;
public:
/**
* 初始化引擎,在开启程序的时候调用
*/
bool init(const char* basePath);
/**
* 逆初始化,释放资源
*/
void uninit();
/**
* 每帧调用,更新引擎状态
*/
void update();
/**
* 加载一个bank文件
* @param bank的文件名
* @return id 返回文件的id
*/
int loadBank(const char* filename);
/**
* 卸载bank文件
* @param bank文件名
*/
void unloadBank(const char* filename);
/**
* 注册游戏对象
* @param id 对象的值,一个无符号整数
*/
void registerGameObject(unsigned int id, const char* name);
/**
* 取消注册游戏对象
* @param id
*/
void unregisterGameObject(unsigned int id);
/**
* 注册默认听者
* @param id 听者的gameObjectId
*/
void setDefaultListener(const int id);
/**
* 发布一个event
* @param eventName 事件名称
* @param gameObj 游戏对象
*/
int postEventFun(const char* eventName, unsigned int gameObjectId,unsigned int funId);
int postEvent(const char* eventName, unsigned int gameObjectId);
/**
* 设置game object 的位置
* @param id GameObject 的id
* @param x, y, z 坐标
*/
void setGameObjectPosition(unsigned int id, float x, float y, float z);
/**
* 设置switch的情况
* @param groupName switch组名
* @param switch名
*/
int setSwitch(const char* groupName, const char* name, unsigned int gameid);
/**
* 设置state
* @param groupName state组名
* @param name state名,都由于设计师设置
*/
int setState(const char* groupName, const char* name);
/**
* 停止所有音频播放
*/
void pauseAll();
/**
* 继续播放全部音乐
*/
void resumeAll();
/**
* 设置默认语言
* @param language 当前使用语言的字符串
*/
void SetCurrentLanguage(const char* language);
/**
* 停止某个播放的音频
* @param eventid 返回的eventid
*/
void stopEvent(unsigned int id,unsigned int fadetime);
/**
* 设置游戏对象的音量
* @param gameobj 游戏对象
* @param listenerobj 听者对象
* @param 设置的音量,从0到100
*/
void setGameObjectVolume(unsigned int gameobj, unsigned int listenerobj, unsigned int volume);
/**
* 停止某个游戏对象上所有的声音播放
* @param gameObj 某个游戏对象,传-1为停止所有
*/
void stopGameObjectAll(unsigned int id);
/**
* 增加查找路径
* @param 基础路径
*/
void addBasePath(const char* basePath);
/**
* 加载pck文件
* @param path 文件的路径
*/
unsigned int loadFilePackage(const char* path);
/**
* 卸载一个pck文件
* @param id 加载时返回的id
*/
void unloadFilePackage(unsigned int id);
/**
* 卸载所有pck文件包
*/
void unloadFilePackageAll();
/**
* 设置听者的方位
* @param x, y, z 坐标
*/
void setListenerPosition(float x, float y, float z);
int getSourcePosition(int id);
int GetIDFromString(const char* eventName);
int wwisePostTrigger(const char* eventName, unsigned int in_gameObjectID);
//设置背景音乐 音量0.1 -- 1之间
void SetGameObjectOutputBusVolume(unsigned int gameObjectID, unsigned int listergameObjectID, float value);
void UnregisterAllGameObj();
int ExecuteActionOnEvent(const char* eventName, unsigned int actionType, unsigned int gameObject, unsigned int transitionDuration, unsigned int fadeCurve);
void SetObjectObstructionAndOcclusion(unsigned int emitterGameObjectid, unsigned int listenerGameObjectid, float Obstruction, float Occlusion);
int SetRTPCValue(const char* pszRtpcName,unsigned int in_value, unsigned int gameObjectID);
void setIDListenerPosition(float x, float y, float z, unsigned int LISTENER_ID1);
private:
CAkFilePackageLowLevelIOBlocking* m_pLowLevelIO;
private:
int getID();
};