Orbiter English > Dan's add-ons

OrbiterSound - C++ Code Snippet for SDK

(1/1)

DanSteph:
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:

--- Code: ---LoadAndPlay("warning_low_fuel.wav"); // load and play immediately one sound

--- End code ---

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:


--- Code: ---// define for function 'LoadAndPlay'
#define SLOTVOICE1             50
#define SLOTVOICE2             51
#define SLOTVOICE3             52
--- End code ---

Still in the header but this time Inside your vessel class declare this:


--- Code: ---[i]class MyAddon: public VESSEL2 {
public: [/i]

[b]     void LoadAndPlay(char* WavFilename);
     int iSlotNbrLoadAndPlay;[/b]

--- End code ---


In a cpp where your class function are declare this:


--- Code: ---////////////////////////////////////////////////////////////////////////////////////////////////
// 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

SolarLiner:
Great Dan ! Can't wait for release !

Vincent Majerowicz:
Hi, Dan!

That is exciting news! I can't until I try out the new orbitersound 4.0 with 3d sounds! Please keep up the excellent work! Thanks!

             Cheers,
          Vincent

Navigation

[0] Message Index

Go to full version