Programmer sound c++ examples

I’m implementing vo for our game (9000+ lines) and and setting up programmer sounds. I have it all set up in FMOD studio to build vo banks, etc. I keep reading about some example code in the docs but am unable to actually find it. I am using the c++ API (not Unity/UE). Can someone point me to some c++ sample code. I’m not sure how to trigger a sound for a given line of dialog and how to then play the sound in the vo bank.

There aren’t any examples for C++ in out online documents, which I will put a note in our tracker to look into for a future release. There is a C++ example included in the FMOD Studio API installation folders, which I will upload here for your convenience.

If you have any questions please don’t hesitate to ask.

programmer_sound.txt (6.8 KB)

This should be enough for me to get it going. Thanks.

Having some problems getting programmer sounds working using the C api. I trigger the sound and I don’t get the callback (but there are no errors). If I trigger it again, I get the callback but the userInfo() doesn’t contain a valid ProgrammerSoundContext *context (it’s all null).

To start the sound, I have this code:

int playDialog(const char *dialog_id) {
    ProgrammerSoundContext programmerSoundContext;
    programmerSoundContext.system = _fmod_studio_system;
    programmerSoundContext.coreSystem = _fmod_system;
    programmerSoundContext.dialogueString = dialog_id;

	FMOD_STUDIO_EVENTDESCRIPTION* event_desc = NULL;
	FMOD_STUDIO_EVENTINSTANCE* event_instance = NULL;

	if (FMOD_ERROR(FMOD_Studio_System_GetEvent(_fmod_studio_system, "event:/vo", &event_desc), dialog_id)) {
		return 0;
	}
	if (FMOD_ERROR(FMOD_Studio_EventDescription_CreateInstance(event_desc, &event_instance))) {
		return 0;
	}
	if (FMOD_ERROR(FMOD_Studio_EventInstance_SetUserData(event_instance, &programmerSoundContext))) {
		return 0;
	}
	if (FMOD_ERROR(FMOD_Studio_EventDescription_SetCallback(event_desc, _programmer_sound_callback, FMOD_STUDIO_EVENT_CALLBACK_CREATE_PROGRAMMER_SOUND | FMOD_STUDIO_EVENT_CALLBACK_DESTROY_PROGRAMMER_SOUND))) {
		return 0;
	}
	if (FMOD_ERROR(FMOD_Studio_EventInstance_Start(event_instance))) {
		return 0;
	}
	if (FMOD_ERROR(FMOD_Studio_EventInstance_Release(event_instance))) {
		return 0;
	}
    return 1;
}

The programmer sound event:/vo is in the dialog_en.bank, I assume this is correct. It wasn’t clear where to put it.

It looks like you are setting the callback on the EventDescription, which will only affect instances created in the future. To fix this you will either need to set the callback before the event instance is created, or you can change this to EventInstance_SetCallback().

Also, I’m not sure about the userInfo() being null? Are you expecting the void *parameters argument of the callback function to contain the userdata? To get the userdata, you’ll need to call FMOD_Studio_EventInstance_GetUserData().

I figure out the issue with the callback. If seems you call FMOD_Studio_EventInstance_SetUserData the user data is not copied and since the programmerSoundContext was a local var it lost scope for the call back. Easy fix and now it’s working.

One more question:

When I get a callback for FMOD_STUDIO_EVENT_CALLBACK_DESTROY_PROGRAMMER_SOUND I need to know the event instance but the event passed in is not the original event instance so it doesn’t have the userInfo anymore. Is there a way to attach useInfo to the sound created with FMOD_System_CreateSound? I need to track some information through to the destroy.

Never mind, I figured it out. Error on my part.