D:/FMOD/inc
From InstalledFolder/api/studio/inc
fmod_studio.h | fmod_studio.hpp | fmod_studio_common.h |
---|
From InstalledFolder/api/core/inc
fmod.h | fmod_common.h | fmod_codec.h | fmod_dsp.h |
---|---|---|---|
fmod_dsp_effects.h | fmod_output.h | fmod.hpp |
D:/FMOD/lib
InstalledFolder/api/studio/lib/x64
InstalledFolder/api/core/lib/x64
Titan Engine/Projects/_Build_/appname
folder
InstalledFolder/api/core/lib/x64
InstalledFolder/api/studio/lib/x64
D:\\FMOD\\inc\\fmod_studio.hpp
D:\\FMOD\\lib\\fmodstudio_vc.lib|D:\\FMOD\\lib\\fmod_vc.lib
// Declaration
FMOD.System *fModSystem;
FMOD.Sound *fModSound;
FMOD.Channel *fModChannel;
FMOD_RESULT fModResult;
void *extraDriverData = 0;
// Init stuff
bool Init()
{
fModResult = FMOD.System_Create(&fModSystem);
fModResult = fModSystem.init(100, FMOD_INIT_NORMAL, extraDriverData);
// Load some sound
const char8 *result = "sound.wav";
fModResult = fModSystem.createSound(result, FMOD_DEFAULT, 0, &fModSound);
return true;
}
// Update process
bool Update()
{
//Press Space to play sound
if(Kb.bp(KB_SPACE))
fModResult = fModSystem.playSound(fModSound, 0, false, &fModChannel);
fModResult = fModSystem.update();
return true;
}
// Declaration is the same as "Play simple sound" but add some new variables
flt stepSide = 0;
flt stepUp = 0;
flt stepForward = 0;
bool soundPlayed = false;
// Init stuff
bool Init()
{
fModResult = FMOD.System_Create(&fModSystem);
fModResult = fModSystem.init(100, FMOD_INIT_NORMAL, extraDriverData);
// Load some sound
const char8 *result = "sound.wav";
fModResult = fModSystem.createSound(result, FMOD_3D, 0, &fModSound);
fModResult = fModSound.set3DMinMaxDistance(0.5, 5000);
fModResult = fModSound.setMode(FMOD_LOOP_NORMAL);
return true;
}
// Update process
bool Update()
{
//Press Space to play sound
if(Kb.bp(KB_SPACE))
{
// Play looping sound once
fModResult = fModSystem.playSound(fModSound, 0, false, &fModChannel);
soundPlayed = true;
}
if(soundPlayed)
{
// Reposition sound
stepSide += Kb.b(KB_D) ? Time.d() : 0;
stepSide -= Kb.b(KB_A) ? Time.d() : 0;
stepUp += Kb.b(KB_E) ? Time.d() : 0;
stepUp -= Kb.b(KB_Q) ? Time.d() : 0;
stepForward += Kb.b(KB_W) ? Time.d() : 0;
stepForward -= Kb.b(KB_S) ? Time.d() : 0;
FMOD_VECTOR pos = {stepSide, stepUp, stepForward};
FMOD_VECTOR vel = {0, 0, 0};
fModResult = fModChannel.set3DAttributes(&pos, &vel);
}
// Update listener
FMOD_VECTOR fModListenerPos = {0, 0, 0};
FMOD_VECTOR fModListenerForward = {0, 0, 1};
FMOD_VECTOR fModListenerUp = {0, 1, 0};
FMOD_VECTOR fModListenerVel = {0, 1, 0};
fModResult = fModSystem.set3DListenerAttributes(0, &fModListenerPos, &fModListenerVel, &fModListenerForward, &fModListenerUp);
// Reset listener position
if(Kb.bp(KB_R)) stepSide = stepUp = stepForward = 0;
// Update FMOD
fModResult = fModSystem.update();
return true;
}
// Draw debug process
void Draw()
{
D.clear(AZURE);
D.text(0, 0.9, S+ stepSide + " | " + stepUp + " | " + stepForward);
}
FMOD builds all sound/event into a bank. Then we use code to load event to play sound from built bank
// Declaration
FMOD.Studio.System *fModStudioSystem;
FMOD.Studio.Bank *fModBank;
FMOD.Studio.EventDescription *fModEventDescription;
FMOD.Studio.EventInstance *fModEventInstance;
void *extraDriverData = 0;
// Init stuff
bool Init()
{
// Basic setup
FMOD.Studio.System.create(&fModStudioSystem);
fModStudioSystem.initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, extraDriverData);
// Load FMOD bank and get event
const char8 *bankPath = "Sounds/bank.bank";
fModStudioSystem.loadBankFile(bankPath, FMOD_STUDIO_LOAD_BANK_NORMAL, &fModBank);
fModStudioSystem.getEvent("event:/evenname", &fModEventDescription);
// Create eventInstance from eventDescription
fModEventDescription.createInstance(&fModEventInstance);
fModEventInstance.setParameterByName("paramName", someValue); //Set parameter of event if need
fModEventInstance.start(); //Start play sound event
// Reposition listener and eventInstance using attributes
FMOD_3D_ATTRIBUTES attr = {{0}};
// Listener first
attr.forward.z = 1.0f;
attr.up.y = 1.0f;
fModStudioSystem.setListenerAttributes(0, &attr);
// Then evenInstance
attr.position.x = 2;
attr.position.y = 0;
attr.position.z = 1;
fModEventInstance.set3DAttributes(&attr);
return true;
}
// Update process
bool Update()
{
// Update FMOD
fModStudioSystem.update();
return true;
}