See site in english Voir le site en francais
Website skin:
home  download  forum  link  contact

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Author Topic: OrbiterSound - C++ Code Snippet for SDK  (Read 2492 times)

0 Members and 1 Guest are viewing this topic.

Offline DanSteph

  • Administrator
  • Legend
  • *****
  • Posts: 14999
  • Karma: 172
  • Hein, quoi !?
    • FsPassengers
26 September 2012, 17:36:06

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: [Select]
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:

Code: [Select]
// 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:

Code: [Select]
[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:

Code: [Select]
////////////////////////////////////////////////////////////////////////////////////////////////
// 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:

Code: [Select]
// 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:

Code: [Select]
  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:

Code: [Select]
  // 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 )


Offline SolarLiner

  • Global Moderator
  • Legend
  • *****
  • Posts: 2768
  • Country: France fr
  • Karma: 54
  • a été remercié par Le Créateur
Reply #1 - 26 September 2012, 18:04:09
Great Dan ! Can't wait for release !



Offline Vincent Majerowicz

  • Jr. Member
  • **
  • Posts: 27
  • Karma: 0
Reply #2 - 27 September 2012, 02:26:22
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

« Last Edit: 27 September 2012, 02:26:22 by Vincent Majerowicz »