[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] [ Search: ]

4.17.2 Playing a Sound

Playing a Sound Once

You can create more than one source to have the same sound played multiple times at the same time. For instance if you have a shooting sound and you want your players to shoot at the same time and have the correct number of shooting sounds.

 
#include "isndsys/ss_source.h"
#include "isndsys/ss_loader.h"
#include "isndsys/ss_renderer.h"
#include "isndsys/ss_manager.h"
#include "imap/loader.h"

...

if (!csInitializer::RequestPlugins(object_reg,
...
  CS_REQUEST_PLUGIN("crystalspace.sndsys.renderer.software",
    iSndSysRenderer),
  CS_REQUEST_PLUGIN("crystalspace.sndsys.element.loader",
    iSndSysLoader),
  CS_REQUEST_END))
...

csRef<iLoader> loader = csQueryRegistry<iLoader> (object_reg);
csRef<iSndSysRenderer> sndrdr =
  csQueryRegistry<iSndSysRenderer> (object_reg);
if (sndrdr)
{
  iSndSysWrapper* w_boom = loader->LoadSoundWrapper (
    <sound name>, <sound file>, CS_SND3D_DISABLE);
  if (w_boom)
  {
    csRef<iSoundSource> sndsrc =
      w_boom->GetSound()->CreateSource(w_boom->GetStream());
    w_boom->GetStream ()->SetLoopState (CS_SNDSYS_STREAM_DONTLOOP);
    w_boom->GetStream ()->Unpause();
  }
}

Looping Background Music

Here is how you can play a looping sound:

 
csRef<iSndSysRenderer> sndrdr =
  csQueryRegistry<iSndSysRenderer> (object_reg);
if (sndrdr)
{
  iSndSysWrapper* w_music = loader->LoadSoundWrapper (
    <sound name>, <sound file>, CS_SND3D_DISABLE);
  if (w_music)
  {
    w_music->GetStream ()->SetLoopState (CS_SNDSYS_STREAM_LOOP);
    w_music->GetStream ()->Unpause();
  }
}

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated using texi2html 1.76.




No user comments yet!


Add a comment