[ < ] [ > ]   [ << ] [ 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),

  csRef<iLoader> loader = csQueryRegistry<iLoader> (GetObjectRegistry ());
  if (!loader)
    ReportError ("Failed to locate Loader!");

  csRef<iSndSysRenderer> sndrenderer = csQueryRegistry<iSndSysRenderer> (GetObjectRegistry ());
  if (!sndrenderer)
    ReportError ("Failed to locate Sound renderer!"); 
  csRef<iSndSysWrapper> w_boom = loader->LoadSoundWrapper ("buzz","/lib/std/loopbzzt.wav");
  if (!w_boom)
    ReportError ("No Wrapper");

  csRef<iSndSysData> snddata = w_boom->GetData ();
  if (!snddata)
    ReportError ("No Sound Data");

  csRef<iSndSysStream> sndstream = sndrenderer->CreateStream (snddata, CS_SND3D_ABSOLUTE);
  if (!sndstream)
    ReportError ("No Stream");
  sndstream->SetLoopState (CS_SNDSYS_STREAM_DONTLOOP);
  sndstream->Unpause ();
  csRef<iSndSysSource> sndsrc = sndrenderer->CreateSource (sndstream);
  if (!sndsrc)
    ReportError ("No Source");

  sndsrc->SetVolume (1.0);

Looping Background Music

Here is how you can specify a looping sound:

  sndstream->SetLoopState (CS_SNDSYS_STREAM_LOOP);
  sndstream->Unpause ();

This document was generated using texi2html 1.76.