/*初期化*/ SoundsManager::SoundsManager() { /* エラーコールバック関数の登録 */ criErr_SetCallback(user_error_callback_func); /* メモリアロケータの登録 */ criAtomEx_SetUserAllocator(user_alloc_func, user_free_func, NULL); /*ライブラリの初期化*/ criAtomEx_Initialize_WASAPI(NULL, NULL, 0); /* ストリーミング用バッファの作成 */ dbas = criAtomDbas_Create(NULL, NULL, 0); /* 全体設定ファイルの登録 */ //criAtomEx_RegisterAcfFile(NULL, PATH ACF_FILE, NULL, 0); criAtomEx_RegisterAcfFile(NULL, ACF_FILE, NULL, 0); /* DSPバス設定の登録 */ criAtomEx_AttachDspBusSetting("DspBusSetting_0", NULL, 0); /* ボイスプールの作成(ストリーム再生対応) */ criAtomExVoicePool_SetDefaultConfigForStandardVoicePool(&vpconfig); vpconfig.player_config.streaming_flag = CRI_TRUE; voice_pool = criAtomExVoicePool_AllocateStandardVoicePool(&vpconfig, NULL, 0); /* MEMO: ストリーム再生無しなら、ボイスプールは構造体NULL指定で可 */ /* サウンドデータの読み込み */ //CriFsBinderHn awb_binder; // acb_hn = criAtomExAcb_LoadAcbFile(NULL, SE_ACB_FILE, AWB_FILE, NULL, NULL, 0); acb_hn = criAtomExAcb_LoadAcbFile(NULL, ACB_FILE, NULL, AWB_FILE, NULL, 0); /* プレーヤの作成 */ player = criAtomExPlayer_Create(NULL, NULL, 0); int a = 0; a++; }
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); }