HelloWorld::HelloWorld() : _cue(nullptr) { CriAtomExStandardVoicePoolConfig vp_config; criAtomExVoicePool_SetDefaultConfigForStandardVoicePool(&vp_config); vp_config.num_voices = 8; vp_config.player_config.streaming_flag = CRI_TRUE; vp_config.player_config.max_sampling_rate = 48000 << 1; CriAtomExPlayerConfig pf_config; criAtomExPlayer_SetDefaultConfig(&pf_config); pf_config.max_path_strings = 1; pf_config.max_path = 256; /* ADX2 Atomライブラリの初期化。内部的に多重初期化は回避している */ ADX2::Manager::initialize(pf_config, vp_config); auto cue = ADX2::Cue::create("ADX2_samples.acf", "Basic.acb", "Basic.awb"); this->setCue(cue); }
Manager::Manager(CriAtomExPlayerConfig playerConfig, CriAtomExStandardVoicePoolConfig voicePoolConfig) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) auto interruptionListener = [](void *userData, UInt32 interruptionState) { switch (interruptionState) { case kAudioSessionBeginInterruption: criAtomEx_StopSound_IOS(); break; case kAudioSessionEndInterruption: AudioSessionSetActive(true); criAtomEx_StartSound_IOS(); break; } }; AudioSessionInitialize(NULL, NULL, interruptionListener, NULL); UInt32 category = kAudioSessionCategory_AmbientSound; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category); AudioSessionSetActive(true); #endif auto errorCallback = [](const char *errid, uint32_t p1, uint32_t p2, uint32_t *parray) { const CriChar8 *errmsg; errmsg = criErr_ConvertIdToMessage(errid, p1, p2); cocos2d::log("%s", errmsg); }; criErr_SetCallback(errorCallback); auto userAlloc = [](void *obj, uint32_t size) { return malloc(size); }; auto userFree = [] (void *obj, void *ptr) { free(ptr); }; criAtomEx_SetUserAllocator(userAlloc, userFree, NULL); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) criAtomEx_Initialize_IOS(NULL, NULL, 0); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) criAtomEx_Initialize_ANDROID(NULL, NULL, 0); /* ANDROIDの場合で必要な一手間。assetsフォルダへのアクセスを可能にする */ /* まずはJniHelperでActivityのContextを取得 */ cocos2d::JniMethodInfo methodInfo; cocos2d::JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxActivity", "getContext", "()Landroid/content/Context;"); auto android_context_object = (jobject)methodInfo.env->CallStaticObjectMethod( methodInfo.classID, methodInfo.methodID ); /* 有効化。assetsフォルダはCocosプロジェクトのResource相当なので、ほぼ必須と言って良い手順 */ criFs_EnableAssetsAccess_ANDROID(cocos2d::JniHelper::getJavaVM(), android_context_object); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) criAtomEx_Initialize_PC(NULL, NULL, 0); #endif _dbasID = criAtomDbas_Create(NULL, NULL, 0); /* 上で作った設定オブジェクトを渡して、ボイスプールを作成 */ _voicePool = criAtomExVoicePool_AllocateStandardVoicePool(&voicePoolConfig, NULL, 0); /* Player作成にも設定は必要 */ criAtomExPlayer_SetDefaultConfig(&playerConfig); _player = criAtomExPlayer_Create(&playerConfig, NULL, 0); }