FMOD_RESULT F_CALLBACK eventcallback(FMOD_EVENT *event, FMOD_EVENT_CALLBACKTYPE type, void *param1, void *param2, void *userdata) { FMOD_RESULT result; switch (type) { case FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE : { char *name = (char *)param1; // [in] (char *) name of sound definition int entryindex = *((int *)param2); // [in] (int) index of sound definition entry FMOD::Sound **s = (FMOD::Sound **)param2; // [out] (FMOD::Sound *) a valid lower level API FMOD Sound handle char sound_name[128]; ERRCHECK((g_index_map[g_sound_index] >= 0) ? FMOD_OK : FMOD_ERR_SUBSOUNDS); ERRCHECK(result = fsb->getSubSound(g_index_map[g_sound_index], s)); ERRCHECK(result = (*s)->getName(sound_name, 128)); printf("FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE '%s' (%d)\n", sound_name, g_index_map[g_sound_index]); break; } case FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_RELEASE : { FMOD::Sound *s = (FMOD::Sound *)param2; // [in] (FMOD::Sound *) the FMOD sound handle that was previously created in FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE char sound_name[128]; ERRCHECK(result = s->getName(sound_name, 128)); printf("FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_RELEASE '%s'\n", sound_name); break; } } return FMOD_OK; }
void initIndexMap(FMOD::Sound *fsb) { FMOD_RESULT result; int numsubsounds, i; /* Sounds aren't in a logical order in the FSB, so we need to iterate through and assign the appropriate filenames to the index map */ FMOD_OPENSTATE openstate; do { fsb->getOpenState(&openstate, 0, 0, 0); } while (openstate != FMOD_OPENSTATE_READY); ERRCHECK(result = fsb->getNumSubSounds(&numsubsounds)); for (i = 0; i < SOUND_INDEX_MAX; ++i) { g_index_map[i] = -1; } for (i = 0; i < numsubsounds; ++i) { FMOD::Sound *sound; char name[100]; ERRCHECK(result = fsb->getSubSound(i, &sound)); do { fsb->getOpenState(&openstate, 0, 0, 0); } while (openstate != FMOD_OPENSTATE_READY); ERRCHECK(result = sound->getName(name, 100)); if(strncmp(name, "sequence-one", 100) == 0) { g_index_map[0] = i; } else if(strncmp(name, "sequence-two", 100) == 0) { g_index_map[1] = i; } else if(strncmp(name, "sequence-three", 100) == 0) { g_index_map[2] = i; } else if(strncmp(name, "sequence-four", 100) == 0) { g_index_map[3] = i; } } }
int main(int argc, char *argv[]) { FMOD::System *system; FMOD::Sound *sound; FMOD::Channel *channel = 0; FMOD_RESULT result; FMOD_MODE mode = FMOD_2D | FMOD_HARDWARE | FMOD_CREATESTREAM; unsigned int version; if (argc != 3) { std::cout << "unpacker.exe fsbPath outdirPath" << std::endl; return 1; } auto fsbPath = std::string(argv[1]); auto outPath = std::string(argv[2]); //fsbPath = "LoL_SFX_ziggs.fsb"; //fsbPath = "LoL_SFX_karma_base.fsb"; //fsbPath = "LoL_SFX_fiddlesticks.fsb"; result = FMOD::System_Create(&system); ERRCHECK(result); result = system->getVersion(&version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } //system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER); result = system->init(1, FMOD_INIT_NORMAL, 0); ERRCHECK(result); auto codecHandle = registerLeagueCodec(system, 50); int numsubsounds; FMOD::Sound *subSound = nullptr; char name[256]; int soundNum = 0; try { result = system->createSound(fsbPath.c_str(), mode, nullptr, &sound); ERRCHECK(result); result = sound->getNumSubSounds(&numsubsounds); ERRCHECK(result); soundNum = 0; sound->getSubSound(0, &subSound); subSound->getName(name, 256); subSound->release(); makePath(outPath.c_str()); sound->release(); system->close(); system->release(); std::set<std::string> writtenFiles; FMOD::Channel* channel; bool playing; for (int sndIdx = 0; sndIdx < numsubsounds; sndIdx++) { ERRCHECK(FMOD::System_Create(&system)); ERRCHECK(system->getVersion(&version)); system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER_NRT); auto outFilePath = outPath + "\\" + std::string(name) + ".wav"; if (writtenFiles.find(outFilePath) != writtenFiles.end()) { int cnt = 1; char arr[80]; do { _itoa_s(cnt, arr, 10); outFilePath = outPath + "\\" + std::string(name) + "_" + std::string(arr) + ".wav"; cnt++; } while (writtenFiles.find(outFilePath) != writtenFiles.end()); } writtenFiles.insert(outFilePath); ERRCHECK(system->init(1, FMOD_INIT_STREAM_FROM_UPDATE, (void*)outFilePath.c_str())); auto codecHandle = registerLeagueCodec(system, 50); system->createSound(fsbPath.c_str(), mode, nullptr, &sound); sound->getSubSound(sndIdx, &subSound); system->playSound(FMOD_CHANNEL_FREE, subSound, false, &channel); do { system->update(); channel->isPlaying(&playing); } while (playing); subSound->release(); if (sndIdx < numsubsounds - 1) { sound->getSubSound(sndIdx+1, &subSound); subSound->getName(name, 256); subSound->release(); outFilePath = outPath + "\\" + std::string(name) + ".wav"; } sound->release(); system->close(); system->release(); } } catch (const std::runtime_error& error) { std::cout << "Exception caught:" << std::endl; std::cout << " " << error.what() << std::endl; } return 0; }
int main(int argc, char *argv[]) { FMOD::System *system; FMOD::Sound *fsb; FMOD::Channel *channel = 0; FMOD_RESULT result; int key, count, numsubsounds; unsigned int version; /* Create a System object and initialize. */ result = FMOD::System_Create(&system); ERRCHECK(result); result = system->getVersion(&version); ERRCHECK(result); if (version < FMOD_VERSION) { printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION); return 0; } result = system->init(32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = system->createSound("../media/example.fsb", FMOD_DEFAULT, 0, &fsb); ERRCHECK(result); printf("===================================================================\n"); printf("FSB Example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("===================================================================\n"); printf("\n"); result = fsb->getNumSubSounds(&numsubsounds); ERRCHECK(result); for (count = 0; count < numsubsounds; count++) { FMOD::Sound *subsound; char name[256]; result = fsb->getSubSound(count, &subsound); ERRCHECK(result); result = subsound->getName(name, 256); ERRCHECK(result); printf("Press '%c' to play \"%s\"\n", '1' + count, name); } printf("Press 'Esc' to quit\n"); printf("\n"); /* Main loop. */ do { if (_kbhit()) { key = _getch(); if (key >= '1' && key < '1' + numsubsounds) { FMOD::Sound *subsound; int index = key - '1'; fsb->getSubSound(index, &subsound); result = system->playSound(FMOD_CHANNEL_FREE, subsound, false, &channel); ERRCHECK(result); } } system->update(); { unsigned int ms = 0; unsigned int lenms = 0; bool playing = 0; bool paused = 0; int channelsplaying = 0; if (channel) { FMOD::Sound *currentsound = 0; result = channel->isPlaying(&playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = channel->getPaused(&paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } channel->getCurrentSound(¤tsound); if (currentsound) { result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } } } system->getChannelsPlaying(&channelsplaying); printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = fsb->release(); ERRCHECK(result); result = system->close(); ERRCHECK(result); result = system->release(); ERRCHECK(result); return 0; }