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 { FMOD_Sound_GetOpenState(fsb, &openstate, 0, 0, 0); } while (openstate != FMOD_OPENSTATE_READY); ERRCHECK(result = FMOD_Sound_GetNumSubSounds(fsb, &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 = FMOD_Sound_GetSubSound(fsb, i, &sound)); do { FMOD_Sound_GetOpenState(fsb, &openstate, 0, 0, 0); } while (openstate != FMOD_OPENSTATE_READY); ERRCHECK(result = FMOD_Sound_GetName(sound, 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; } } }
FMOD_SOUND * bmx_FMOD_Sound_GetSubSound(FMOD_SOUND * sound, int index) { FMOD_SOUND * subsound; FMOD_RESULT result = FMOD_Sound_GetSubSound(sound, index, &subsound); if (result) { return 0; } return subsound; }
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); result = FMOD_Sound_GetSubSound(fsb, g_index_map[g_sound_index], s); if (result != FMOD_OK) { printf("FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE: %d: sound not ready, retry next frame\n", g_index_map[g_sound_index]); return result; } result = FMOD_Sound_GetName(*s, sound_name, 128); if (result != FMOD_OK) { printf("FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_CREATE: %d: sound not ready, retry next frame\n", g_index_map[g_sound_index]); return result; } 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 = FMOD_Sound_GetName(s, sound_name, 128)); printf("FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_RELEASE '%s'\n", sound_name); break; } } return FMOD_OK; }
void Java_org_fmod_fsb_Example_cPlayNextSound(JNIEnv *env, jobject thiz) { FMOD_RESULT result = FMOD_OK; FMOD_SOUND *subsound; int numsubsounds; result = FMOD_Sound_GetNumSubSounds(gFSB, &numsubsounds); CHECK_RESULT(result); result = FMOD_Sound_GetSubSound(gFSB, gIndex, &subsound); CHECK_RESULT(result); result = FMOD_System_PlaySound(gSystem, FMOD_CHANNEL_REUSE, subsound, 0, &gChannel); CHECK_RESULT(result); gIndex++; if (gIndex >= numsubsounds) { gIndex = 0; } }
void CDA_Start (int track, qboolean loop, qboolean notify) { #ifdef UQE_FMOD_CDAUDIO if (SND_InitialisedCD == false) return; if(SND_MusicChannel.inuse == true) FMOD_MusicStop(); if(loop == true) { SND_MusicChannel.looping = true; result = FMOD_Sound_SetMode(fmod_musicCD, FMOD_LOOP_NORMAL); FMOD_ERROR(result, true, false); } else { SND_MusicChannel.looping = false; result = FMOD_Sound_SetMode(fmod_musicCD, FMOD_LOOP_OFF); FMOD_ERROR(result, true, false); } // fmod track numbers starts at zero result = FMOD_Sound_GetSubSound(fmod_musicCD, track-1, &fmod_musicCD_subsound); FMOD_ERROR(result, notify, false); result = FMOD_System_GetChannel(fmod_system, 0, &SND_MusicChannel.channel); FMOD_ERROR(result, true, false); result = FMOD_System_PlaySound(fmod_system, FMOD_CHANNEL_REUSE, fmod_musicCD_subsound, FALSE, &SND_MusicChannel.channel); FMOD_ERROR(result, notify, false); SND_MusicChannel.inuse = true; #else CDAudio_Play((byte)track, loop); #endif }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND *cdsound; FMOD_SOUND *sound; FMOD_CHANNEL *channel = 0; FMOD_RESULT result; int key, numtracks, currenttrack = 0; unsigned int version; if (argc < 2) { printf("Usage: cdplayer <volumename>\n"); printf("Example: cdplayer \"Audio CD\"\n"); exit(-1); } printf("==================================================================\n"); printf("CDPlayer Example. Copyright (c) Firelight Technologies 2004-2011.\n"); printf("==================================================================\n\n"); /* Create a System object and initialize. */ result = FMOD_System_Create(&system); ERRCHECK(result); result = FMOD_System_GetVersion(system, &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 = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL); ERRCHECK(result); /* Bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium. */ result = FMOD_System_SetStreamBufferSize(system, 64*1024, FMOD_TIMEUNIT_RAWBYTES); ERRCHECK(result); result = FMOD_System_CreateStream(system, argv[1], FMOD_OPENONLY, 0, &cdsound); ERRCHECK(result); result = FMOD_Sound_GetNumSubSounds(cdsound, &numtracks); ERRCHECK(result); result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound); ERRCHECK(result); for (;;) { FMOD_TAG tag; if (FMOD_Sound_GetTag(cdsound, 0, -1, &tag) != FMOD_OK) { break; } if (tag.datatype == FMOD_TAGDATATYPE_CDTOC) { dump_cddb_query((FMOD_CDTOC *)tag.data); } } printf("\n========================================\n"); printf("Press SPACE to pause\n"); printf(" n to skip to next track\n"); printf(" ESC to exit\n"); printf("========================================\n\n"); /* Print out length of entire CD. Did you know you can also play 'cdsound' and it will play the whole CD without gaps? */ { unsigned int lenms; result = FMOD_Sound_GetLength(cdsound, &lenms, FMOD_TIMEUNIT_MS); ERRCHECK(result); printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100); } /* Play a CD track */ result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); /* Main loop */ do { if (kbhit()) { key = getch(); switch (key) { case ' ' : { int paused; FMOD_Channel_GetPaused(channel, &paused); FMOD_Channel_SetPaused(channel, !paused); break; } case 'n' : { currenttrack++; if (currenttrack >= numtracks) { currenttrack = 0; } result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound); ERRCHECK(result); result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel); ERRCHECK(result); break; } } } FMOD_System_Update(system); if (channel) { unsigned int ms, lenms, percent = 0; FMOD_BOOL playing; FMOD_BOOL paused; result = FMOD_Channel_GetPaused(channel, &paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_IsPlaying(channel, &playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } printf("\rTrack %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped"); fflush(stdout); } Sleep(10); } while (key != 27); printf("\n"); /* Shut down */ result = FMOD_Sound_Release(cdsound); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); 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 = FMOD_System_GetVersion(system, &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 = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0); ERRCHECK(result); result = FMOD_System_CreateSound(system, "../media/example.fsb", FMOD_DEFAULT, 0, &fsb); ERRCHECK(result); printf("===================================================================\n"); printf("FSB Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("===================================================================\n"); printf("\n"); result = FMOD_Sound_GetNumSubSounds(fsb, &numsubsounds); ERRCHECK(result); for (count = 0; count < numsubsounds; count++) { FMOD_SOUND *subsound; char name[256]; result = FMOD_Sound_GetSubSound(fsb, count, &subsound); ERRCHECK(result); result = FMOD_Sound_GetName(subsound, 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'; FMOD_Sound_GetSubSound(fsb, index, &subsound); result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, subsound, FALSE, &channel); ERRCHECK(result); } } FMOD_System_Update(system); { unsigned int ms = 0; unsigned int lenms = 0; int playing = 0; int paused = 0; int channelsplaying = 0; if (channel) { FMOD_SOUND *currentsound = 0; result = FMOD_Channel_IsPlaying(channel, &playing); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPaused(channel, &paused); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } FMOD_Channel_GetCurrentSound(channel, ¤tsound); if (currentsound) { result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS); if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)) { ERRCHECK(result); } } } FMOD_System_GetChannelsPlaying(system, &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 = FMOD_Sound_Release(fsb); ERRCHECK(result); result = FMOD_System_Close(system); ERRCHECK(result); result = FMOD_System_Release(system); ERRCHECK(result); return 0; }