[PloobsEngine] Tutorial 9 – Playing Sounds

This tutorial will talk about how to play all kind of sounds using PloobsEngine. (tutorials series here)

The PloobsEngine has basicaly three types of sounds: The 3D sound effects, the 2D sound effects an a Music Player.

Before understanding the details of each type, we need to know the global options that affects the way we play sounds.

The PloobsEngine offers a way to configure the global settings using a description object. The following code shows how to recover and set these properties:

      protected override void InitScreen(GraphicInfo GraphicInfo, EngineStuff engine)
            base.InitScreen(GraphicInfo, engine);

            ///Controls some master option of the engine sound player
            SoundMasterOptionDescription sod = engine.GetSoundMasterOptionDescription();
            ///between 0 and 1
            sod.MasterVolume = 0.9f;
            ///varies according to your game scale
            ///Used in 3D sounds
            sod.DistanceScale = 200;
            engine.SetSoundMasterOptionDescription(ref sod);

It is pretty simple, we just recover the Sound Options object from the engine (can be done anywhere, not only in the InitScreen as i did in this sample), change the options and set it in the engine.
For now, we have the following options we can set:

  • DistanceScale (use in 3D sound,  it scales the attenuation, value can be in any range — depends of the distance between your objects in your game)
  • DoplerScale (controls how intense the dopler effect should be, value must be in the 0-1 range)
  • MasterVolume (between 0 and 1 — controls the master volume)


This is the easiest way to produce a sound.  The following code shows how to use it:

///Create (second parameter is the path of the sound, we support all xna sound types)
SimpleSoundEffect se = new SimpleSoundEffect(contentManager, "Songs/alarm");
///Use the following methods to play,plause and stop the effect

The problem with this aproach is that the sounds used are not reutilized (internaly, every time you create a sound instance, a new internal structure is created), so it can consume lots of memory (principaly in WP7).
The good point is that the sounds are not shared, so you can do wherever you want with it without fear of destroying something else.

This way of playing sound is a bit diferent, it creates a repository of sounds and share the instances with everyone who wants.
The following code shows how to create the SoundAudioPlayer, how to add sounds to it and how to play its contents.

            ///Create and add a sound to the SoundAudioPlayer
            SoundAudioPlayer ap = new SoundAudioPlayer(contentManager);
            ///Add a sound to the repo (the second parameter is a name used to refer to this song in the future)
            ap.AddSoundToRepository("Songs/bye", "bye");
            ///Play, Stop ....

The good and the bad point is that the memory is shared (good for WP7, but hard to manage in some circunstances)=P

The best option is to mix both approaches.


This class is used to play musics stored in your hard drive (Media Player library). You show lists of albums, songs … and let the player choose what he wants to listen. The following code shows how to use it:

///Load the Sounds that you hear in your Microsoft Media Player
///Just loading the first album found =P
LocalMediaAudioPlayer lm = new LocalMediaAudioPlayer();
AlbumCollection ac = lm.MediaLibrary.Albums;

It is pretty easy to use, but it  is not very “interesting” (most users dont use Media Player Libraries =P)


The Static3DSound is responsible for playing 3D static sounds (that have a fixed position in the space and follow the doppler rule). Different from the other sounds, this one must be added to the IWorld, the following code shows hot to create and play a 3D static sound.

            ///Static 3D sound, the last parameter is the position
            Static3DSound sound = new Static3DSound(contentManager, "Songs/pianosong", Vector3.Zero);
            this.World.AddSoundEmitter(sound, true);

You can also create sounds that follow objects (if you want you can make any kind of 3D sounds, just extending the existing ones). The following sample shows a 3D sound effect that follows an IObject. (sound position is updated each frame according to the IObject position)

                SimpleModel sm2 = new SimpleModel(factory, "Model\\ball");
                sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red, false), TextureType.DIFFUSE);
                DeferredNormalShader nd = new DeferredNormalShader();
                IMaterial m = new DeferredMaterial(nd);
                SphereObject pi2 = new SphereObject(new Vector3(100,50,0), 1, 10, 10, MaterialDescription.DefaultBepuMaterial());
                IObject o = new IObject(m, sm2, pi2);

                sound2 = new ObjectFollower3DSound(contentManager, "Songs/pianosong", o);

One commom problem iwith 3D is forgetting to set the flobal Distance Scale (if you dont and your game scale is very diferent from the default one you wont not hear the 3D sound effect).

This is all for today =P.

Any doubts, problems … Just contact to us =P

You can find all of the discussed code in the AdvancedDemos Package.


, , , , ,

  1. #1 by golden goose pas cher on 28 de maio de 2017 - 5:05 am

    visage dans la salle où mes relations sont rassemblées ensem-er, ils seront tous regarder vers le bas sur le sol et garder le silence; donc si je vais inshouting et qui fait rage, il sera tout à fait hors de l’harmonie; mais si elles abuse104.A célèbre acteur de Yedo, qui a vécu il y a 195 ans. Il est né à Sakura, inShim? Sa.105.The coupe de vin ordinaire tenant seulement une thimbleful, de boire du vin sur teacups est agreat morceau de brandy potable débauche comme dans tumblers.252me, alors je serai dans la droite si Je saute sur eux et fais peur themwell. Le meilleur plan sera pour moi de sortir du bosquet de bambous whichis derrière la maison, et à ramper autour de la véranda, et je peux écouter tothese boursiers tenant leur consultation: ils seront certainement ratisser upall sortes de scandale autour de moi. Il sera tout en harmonie, puis, si je

  2. #2 by http://news.louboutinheels.xyz/louboutinheelsxyz/120.asp on 28 de maio de 2017 - 6:50 am

    Purchased your as being a gifts concerning my mom and/or she liked things. pleasant good cool amount furthermore my personal mother loved that it. In addition delivered super accelerated. When you need a gift quick while like this compared to this is the definitely one you ought to invest!

  3. #3 by hilfreiche website on 28 de maio de 2017 - 7:25 am

    findet nur gute Angebote mit vernünftigen Preisen ohne Abzocke.

  4. #4 by buy online sandals for women on 28 de maio de 2017 - 7:30 am

    Some can offer you money, whilst there are also other people that can provide you goods.|There is continuity of work even without energy. One of the most popular is the Goal Credit Card. Now family buying had moved to heaven.

  5. #5 by http://www.ttsq.fr/dresses.asp on 28 de maio de 2017 - 8:17 am

    it comes down within a stunning box seems great but its a bit small really for our moms wrist however it appearance great only want information technology ended up being longer

  6. #6 by workout clothes for women  on 28 de maio de 2017 - 8:49 am

    We’re a group of volunteers and opening a new scheme in our community. Your site offered us with valuable info to work on. You’ve done a formidable job and our whole community will be grateful to you.

  7. #7 by puzzle games on 28 de maio de 2017 - 8:50 am

    hi!,I love your writing so much! percentage we keep in touch more approximately your post on AOL? I need a specialist in this house to unravel my problem. Maybe that’s you! Having a look ahead to peer you.

  8. #8 by hermes bracelet replica on 28 de maio de 2017 - 9:38 am

    I have this particular gifts to the mother for the Xmas due to the fact she is letter jewelry freak. The actual one thing she cannot wear far concerning are, bracelets. I purchased this girl it appeal bracelet then once she exposed this yesterday she absolutley adored that it! This time the problem is, the lady getting this regarding plus down simply by herself. Haha… general very good goods, it shipped as well as came very early plus our mother is actually experiencing this. Thank people.

  9. #9 by cl05a104ka5nnnc on 28 de maio de 2017 - 10:52 am

    Spot on with this write-up, I actually think this web site needs much more consideration. I’ll most likely be once more to read far more, thanks for that info.

  10. #10 by http://news.monclerjacketsoutlet.xyz/monclerjacketsoutletxyz/613.asp on 28 de maio de 2017 - 11:04 am

    The son offered myself our towards moms evening. He realizes im not around price but everything originates from on center. I can’t think this has my favourite shade and/or even matches the wrist. I never could come across bracelets to fit headphonesmy personal slight wrist. Very happy to has recieved this one as being a gift.

1 609 610 611
(não será publicado)