A helper function that allow you to load and play immediately hundred of wav
Info:
OrbiterSound allow you only 60 "slots" for wavs, This limitation can be tricky as a slot may be used for a "warning low fuel" sound that will be used very rarely, with a few like this all your slots are quickly full. Fortunately this function allow you to load and play immediately one wav with a single function line. You can virtually play hundred of sound without worrying any-more about slots. (This function use only the same three slot for that, so up to three sound using this function can play in same time.)
Useful for: Cockpit single and 'rare' event like voice announces, notifications.
Not suitable for: frequent sound effect like gears, engine etc. etc.
Limitation: Work only on OrbiterSound 3.5 and higher. (older version are obsolete anyway)
Example of Use:
LoadAndPlay("warning_low_fuel.wav"); // load and play immediately one sound
Code: (For OrbiterSound 4.0's SDK, for 3.5 add a '3' to OrbiterSound function eg: 'RequestLoadVesselWave3')
In your vessel header (outside of class) declare this and choose three slot number that are free:
// define for function 'LoadAndPlay'
#define SLOTVOICE1 50
#define SLOTVOICE2 51
#define SLOTVOICE3 52
Still in the header but this time Inside your vessel class declare this:
[i]class MyAddon: public VESSEL2 {
public: [/i]
[b] void LoadAndPlay(char* WavFilename);
int iSlotNbrLoadAndPlay;[/b]
In a cpp where your class function are declare this:
////////////////////////////////////////////////////////////////////////////////////////////////
// LoadAndPlay- Load and play immediately a cockpit sound
////////////////////////////////////////////////////////////////////////////////////////////////
void MyAddon::LoadAndPlay(char* WavFilename)
{
iSlotNbrLoadAndPlay++; // will use the next slot
// Ensure that we use only our three slot (no need to initialise this value, it will be done at the first call)
if(iSlotNbrLoadAndPlay>SLOTVOICE3||iSlotNbrLoadAndPlay iSlotNbrLoadAndPlay=SLOTVOICE1;
char FilenamePath[255]={0};
sprintf(FilenamePath,"Sound\\[glow=yellow,2,300][b]MyAddon[/b][/glow]\\%s",WavFilename);
RequestLoadVesselWave(MyID,iSlotNbrLoadAndPlay,FilenamePath,INTERNAL_ONLY);
PlayVesselWave(MyID,iSlotNbrLoadAndPlay);
}
To use like this in your code:
// examples:
LoadAndPlay("warning_low_fuel.wav"); // load and play immediately one sound
LoadAndPlay("BayDoorOpen.wav"); // load and play immediately one sound
LoadAndPlay("Critical_temperature.wav"); // load and play immediately one sound
NOTE: Since OrbiterSound 4.0 it is highly recommended to put your wav in a 'Sound/_CustomVesselsSounds/XXXX' folder. So given "XXXX" is your addon folder name, change the line above to this:
sprintf(FilenamePath,"Sound\\_CustomVesselsSounds\\[glow=yellow,2,300][b]XXXXXX[/b][/glow]\\%s",WavFilename);
And if you use OrbiterSound 4.0 3d sound replace the 'RequestLoadVesselWave' line by this one:
// Vector is local vessel coordinate (Must be close to default camera pos)
RequestLoad3DWaveMono(MyID,iSlotNbrLoadAndPlay,FilenamePath,INTERNAL_ONLY,&_V(0,2,30));
Message modifié ( 26-09-2012 18:23 )