Play() public method

Plays or resumes a SoundEffectInstance.
Throws an exception if more sounds are playing than the platform allows.
public Play ( ) : void
return void
Example #1
0
        public void Update(GameManager gameManager, Menu menu, Carte map)
        {
            if (nouveaujeu == false && gameManager.Etat == GameManager.etat.NouveauJeuIntro)
            {
                sonmanager.Stop();
                sonmanager = sons[5].CreateInstance();
                sonmanager.IsLooped = true;
                sonmanager.Play();
                nouveaujeu = true;
            }

            if (jeu == false && gameManager.Etat == GameManager.etat.InGame)
            {
                jeu = true;
            }

            if (!menu.pauseactive)
            {
                if (menu.sound == Menu.Son.On && sonmanager.State == SoundState.Paused)
                {
                    sonmanager.Play();
                }

                if (menu.sound == Menu.Son.Off && sonmanager.State == SoundState.Playing)
                {
                    sonmanager.Pause();
                }
            }

            if(menu.pauseactive)
            {
                if (sonmanager.State == SoundState.Playing)
                    sonmanager.Pause();
            }
        }
Example #2
0
        public EndScreen(ADHDGame g, SpriteBatch spb, Ending e)
            : base(g, spb)
        {
            end = e;
            sb = spb;
            game = g;
            banjoEnd = game.Content.Load<Texture2D>("newspaper_death01");
            space = game.Content.Load<Texture2D>("spaceBG");
            explosion = game.Content.Load<SoundEffect>("Explosion").CreateInstance();
            airlockEnd = game.Content.Load<Texture2D>("newspaper_death02");
            blackhole = game.Content.Load<Texture2D>("newspaper_death03");
            breaks = game.Content.Load<Texture2D>("newspaper_death04");
            thrusters = game.Content.Load<Texture2D>("newspaper_death05");
            tutorial = game.Content.Load<Texture2D>("tutorial");
            inactive = game.Content.Load<Texture2D>("newspaper_death06");
            dub = game.Content.Load<Texture2D>("newspaper_death07");
            help = game.Content.Load<Texture2D>("newspaper_death08");

            explosion.Play();

            if (e != Ending.Banjo)
            {
                MediaPlayer.Play(game.Content.Load<Song>("SpaceRock_V1"));
            }
        }
Example #3
0
        public GameStateManagementGame()
        {
            Content.RootDirectory = "Content";

            graphics = new GraphicsDeviceManager(this);
            //TargetElapsedTime = TimeSpan.FromTicks(333333);
            TargetElapsedTime = TimeSpan.FromTicks(333);

            #if WINDOWS_PHONE
            graphics.IsFullScreen = true;
            InitializeLandscapeGraphics();
            #endif

            screenFactory = new ScreenFactory();
            Services.AddService(typeof(IScreenFactory), screenFactory);
            screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            #if WINDOWS_PHONE
            // hook
            Microsoft.Phone.Shell.PhoneApplicationService.Current.Launching +=
                new EventHandler<Microsoft.Phone.Shell.LaunchingEventArgs>(GameLaunching);
            Microsoft.Phone.Shell.PhoneApplicationService.Current.Activated +=
                new EventHandler<Microsoft.Phone.Shell.ActivatedEventArgs>(GameActivated);
            Microsoft.Phone.Shell.PhoneApplicationService.Current.Deactivated +=
                new EventHandler<Microsoft.Phone.Shell.DeactivatedEventArgs>(GameDeactivated);
            #else
            AddInitialScreens();
            #endif
            gameMusic = Content.Load<SoundEffect>("sounds/GamePlayHalfBit");
            gameMusicI = gameMusic.CreateInstance();
            gameMusicI.IsLooped = true;
            gameMusicI.Play();
        }
Example #4
0
        public ShipObj(MobileFortressClient game,Vector3 position, Quaternion orientation, ShipData data)
            : base(game,position,orientation,2)
        {
            Data = data;
            Data.ComposeHitbox();
            Data.Hitbox.Position = position;
            Sector.Redria.Space.Add(Data.Hitbox);
            this.Entity = Data.Hitbox;

            //Thrusters = new SingleEntityLinearMotor(Entity, Position);
            //ControlSurfaces = new SingleEntityAngularMotor(Entity);
            //ControlSurfaces.Settings.Mode = MotorMode.Servomechanism;
            //ControlSurfaces.Settings.Servo.MaxCorrectiveVelocity = 2;

            //Thrusters.Settings.Mode = MotorMode.VelocityMotor;
            //Thrusters.Settings.VelocityMotor.Softness = 0.002f;

            //Sector.Redria.Space.Add(Thrusters);
            //Sector.Redria.Space.Add(ControlSurfaces);
            Entity.IsAffectedByGravity = false;

            engineNoise = Resources.Sounds.Engine.CreateInstance();
            engineNoise.Apply3D(Camera.Audio, Audio);
            engineNoise.IsLooped = true;
            engineNoise.Play();
            Entity.CollisionInformation.Tag = this;
        }
Example #5
0
        public Boat(EnemyType type, Vector2 position, Texture2D sheet, int scene)
            : base(type, position, sheet, scene)
        {
            spawnPosition = position;
            numFrames = 1;
            animTime = 50;
            isAnimating = true;
            animFrame = 0;

            Speed = 0.003f;

            frameSize = new Vector2(64,64);
            frameOffset = new Vector2(32, 20);
            hitRadius = 25;

            centerOffestLength = 0;

            fireRate = 50;
            fireCountdown = 50;

            HP = 20;

            Target = GameManager.Hero.Position + Helper.AngleToVector(GameManager.Hero.spriteRot, 400f);

            chopperSound = AudioController.effects["boat"].CreateInstance();
            chopperSound.Volume = 0f;
            chopperSound.IsLooped = true;
            chopperSound.Play();
        }
Example #6
0
 public void playBackground(byte theme)
 {
     if (currentBackground != null) currentBackground.Stop();
     currentBackground = backgroundSounds[theme].CreateInstance();
     currentBackground.IsLooped = true;
     currentBackground.Play();
 }
        public void Update(GameManager gameManager, Menu menu)
        {
            if (jeu && gameManager.Etat == GameManager.etat.InGame)
            {
                sonmanager.Stop();
                sonmanager = sons[2].CreateInstance();
                sonmanager.IsLooped = false;
                sonmanager.Play();
                jeu = false;
            }

            if (gameManager.Etat == GameManager.etat.InGame && sonmanager.State == SoundState.Stopped)
            {
                piste++;
                if (piste == 1)
                {
                    sonmanager.Stop();
                    sonmanager = sons[2].CreateInstance();
                    sonmanager.IsLooped = false;
                    sonmanager.Play();
                }
                else if (piste == 2)
                {
                    sonmanager.Stop();
                    sonmanager = sons[3].CreateInstance();
                    sonmanager.IsLooped = false;
                    sonmanager.Play();
                }
                else if (piste == 3)
                {
                    sonmanager.Stop();
                    sonmanager = sons[4].CreateInstance();
                    sonmanager.IsLooped = false;
                    sonmanager.Play();
                }
                else
                {
                    piste = 0;
                }
            }

            if (!menu.pauseactive)
            {
                if (menu.sound == Menu.Son.On && sonmanager.State == SoundState.Paused)
                {
                    sonmanager.Play();
                }

                if (menu.sound == Menu.Son.Off && sonmanager.State == SoundState.Playing)
                {
                    sonmanager.Pause();
                }
            }

            if(menu.pauseactive)
            {
                if (sonmanager.State == SoundState.Playing)
                    sonmanager.Pause();
            }
        }
Example #8
0
        public TitleScreen(ADHDGame g, SpriteBatch spb)
            : base(g,spb)
        {
            RobotActions.Instance.energy = 20;
            paper = false;
            mouse = false;
            game = g;
            sb = spb;
            titleSequence = new List<Texture2D>(40);
            gs = new GameplayScreen(g, spb);
            titleAnim = new Animation(new Rectangle(0, 0, 1024, 768), 40, 30, true);
            introNews = g.Content.Load<Texture2D>("newspaper_intro");
            space = g.Content.Load<Texture2D>("spaceBG");
            int i;
            for (i = 0; i < 40; i++)
            {
                titleSequence.Add(g.Content.Load<Texture2D>("titlescreen\\titlescreen" + (i+1).ToString()));
            }
            snoring = g.Content.Load<SoundEffect>("Snoring").CreateInstance();
            alarm = g.Content.Load<SoundEffect>("alarm_02").CreateInstance();

            alarm.IsLooped = true;
            alarm.Volume = 0.2f;
            snoring.IsLooped = true;
            snoring.Play();
        }
Example #9
0
        //Obtain how far collide with the object and move back to original position
        //For Player sprite
        public void SpriteCollision(ref Character name, SoundEffectInstance song6Inst, SoundEffectInstance song7Inst)
        {
            //Temporary Value for Object position
            Vector2 currentPos;

            //Difference between each objects edges
            Vector2 Diff = new Vector2(0, 0);

            //Obtain difference from Actionhandler
            Diff = CollisionCheck(name.SpriteID);

            //For X axis difference
            if (Math.Abs(Diff.X) > 0)
            {
                //Sounds for colliding into object
                song6Inst.Volume = 1.0f;
                song6Inst.Play();
                currentPos = name.pos;
                currentPos.X -= Diff.X;
                name.pos = currentPos;
            }
            //For Y axis difference
            if (Math.Abs(Diff.Y) > 0)
            {
                //Sounds for colliding into object
                song7Inst.Volume = 1.0f;
                song7Inst.Play();
                currentPos = name.pos;
                currentPos.Y -= Diff.Y;
                name.pos = currentPos;
            }
        }
Example #10
0
        public static Area City(Character player)
        {
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.TownSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Point levelrange = new Point(3, 8);
            var map = ContentLoader.City;

            Vector2 spawn = Vector2.One;
            if (player.PreviousArea != null)
                if (player.PreviousArea.Name == "Shop") {
                    spawn = new Vector2(256, 192);
                }
                else if (player.PreviousArea.Name == "Route 1") {
                    spawn = new Vector2(256, 416);
                }
                else {
                    spawn = new Vector2(32, 96);
                }

            List<Monster> monsters = new List<Monster>();
            List<Character> opponents = new List<Character>();
            //Sound = ContentLoader.RouteSong;
            //Sound.IsLooped = true;
            //Sound.Play();

            return new Area("City", levelrange, monsters, opponents, spawn, map);
        }
Example #11
0
        public Boss(EnemyType type, Vector2 position, Texture2D sheet, List<Point> path, bool loop, int pathnode, int scene)
            : base(type, position, sheet, path, loop, pathnode, scene)
        {
            numFrames = 2;
            animTime = 50;
            isAnimating = true;

            Speed = 0f;

            frameSize = new Vector2(128,128);
            frameOffset = new Vector2(64, 125);
            hitRadius = 30 * scale;

            centerOffestLength = 32 * scale;

            fireRate = 50;
            fireCountdown = 50;

            HP = 150;

            jeepSound = AudioController.effects["truck"].CreateInstance();
            jeepSound.Volume = 0f;
            jeepSound.IsLooped = true;
            jeepSound.Play();
        }
Example #12
0
        public void checkPaddleCollision(Rectangle paddle, SoundEffectInstance soundEngineInstance)
        {
            Rectangle ballLocation = new Rectangle((int)position.X, (int)position.Y,
                sprite.Width, sprite.Height);

            if (paddle.Intersects(ballLocation) && !inCollision)
            {
                inCollision = true;

                // La balle émet le son approprié
                soundEngineInstance.Volume = 0.75f;
                soundEngineInstance.Play();

                //Collision avec le top de la palette
                if (ballLocation.Intersects(new Rectangle(paddle.X, paddle.Y, paddle.Width, 0)))
                {
                    direction.Y *= -1;
                    position.Y = paddle.Y - sprite.Height;

                    float paddleCenter = paddle.X + (paddle.Width/2);
                    float ballCenter = position.X + sprite.Width/2;
                    direction.X = (ballCenter - paddleCenter) / (paddle.Width / 2);
                    direction = Vector2.Normalize(direction);
                }

            }
            else if(!paddle.Intersects(ballLocation))
                inCollision = false;
        }
Example #13
0
 public Menu(ContentManager Content, SpriteBatch spriteBatch)
 {
     menuTexture = new AnimatedSprite(Content.Load<Texture2D>("Graphics\\MainMenu"), 3, 2, animationSpeed);
     startButton = new Button(new Vector2(startButtonLX, startButtonLY),
         new Vector2(startButtonRX, startButtonRY), "", Vector2.Zero);
     controlsButton = new Button(new Vector2(controlsButtonLX, controlsButtonLY),
         new Vector2(controlsButtonRX, controlsButtonRY), "", Vector2.Zero);
     skipButton = new Button(new Vector2(skipButtonLX, skipButtonLY),
         new Vector2(skipButtonRX, skipButtonRY), "", Vector2.Zero);
     buttonList = new List<Button>() { startButton, skipButton, controlsButton };
     buttonListHover = new List<bool>() { hoverFlag, hoverFlagSkip, hoverFlagControls };
     pixel = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
     pixel.SetData(new[] { Color.White });
     isInControllerMenu = false;
     controllerMenu = new ControllerMenu(Content, spriteBatch);
     selectedButton = 0;
     menuBgm = (Content.Load<SoundEffect>("Music\\Cylinder_Eight.wav")).CreateInstance();
     windEffectInstance = (Content.Load<SoundEffect>("Music\\Wind.wav")).CreateInstance();
     flagEffectInstance = (Content.Load<SoundEffect>("Music\\Flag.wav")).CreateInstance();
     scrollClickEffectInstance = (Content.Load<SoundEffect>("Music\\Click.wav")).CreateInstance();
     confirmClickEffectInstance = (Content.Load<SoundEffect>("Music\\Click2.wav")).CreateInstance();
     menuBgm.IsLooped = true;
     menuBgm.Play();
     windEffectInstance.IsLooped = true;
     windEffectInstance.Volume = windVolume;
     flagEffectInstance.IsLooped = true;
     flagEffectInstance.Volume = flagVolume;
     scrollClickEffectInstance.Volume = clickVolume;
     confirmClickEffectInstance.Volume = clickVolume;
     windEffectInstance.Play();
     flagEffectInstance.Play();
 }
Example #14
0
        public TitleScene()
        {
            m_TitleTexture = HeartAttack.theGameInstance.Content.Load<Texture2D>("title");
            m_HeartcoreTexture = HeartAttack.theGameInstance.Content.Load<Texture2D>("heartcoreMode");
            m_FlowTexture = HeartAttack.theGameInstance.Content.Load<Texture2D>("flowMode");

            bgm = HeartAttack.theGameInstance.Content.Load<SoundEffect>("heartbackground").CreateInstance();
            bgm.Play();

            HeartAttack.theGameInstance.bugsKilled = 0;
            HeartAttack.theGameInstance.shotsFired = 0;
            int space = 20;

            m_FlowRectangle = new Rectangle(
                HeartAttack.theGameInstance.graphics.GraphicsDevice.Viewport.Width -
            m_FlowTexture.Width - space,
            HeartAttack.theGameInstance.graphics.GraphicsDevice.Viewport.Height -
            m_FlowTexture.Height - 2 * space - m_HeartcoreTexture.Height, m_FlowTexture.Width, m_FlowTexture.Height);

            m_HeartcoreRectangle = new Rectangle(
                HeartAttack.theGameInstance.graphics.GraphicsDevice.Viewport.Width -
            m_HeartcoreTexture.Width - space,
            HeartAttack.theGameInstance.graphics.GraphicsDevice.Viewport.Height -
            m_HeartcoreTexture.Height - space, m_HeartcoreTexture.Width, m_HeartcoreTexture.Height);
        }
Example #15
0
 public static void PlayTheme()
 {
     _themeIntance = _theme.CreateInstance();
      _themeIntance.IsLooped = true;
      _themeIntance.Volume = .8f;
      _themeIntance.Play();
 }
Example #16
0
        public void CreatePlane()
        {
            // Already created plane?
            if (plane != -1)
            {
                factory.Objects[plane].sprite.Location = new Vector2(-LengthAddedfromZoom - factory.Objects[plane].sprite.BoundingBoxRect.Width, -650);
                return;
            }

            plane = factory.Create((int)RaginRovers.GameObjectTypes.PLANE,
                Vector2.Zero,
                "plane_with_banner",
                Vector2.Zero,
                0f,
                0f,
                0f);
            factory.Objects[plane].sprite.Location = new Vector2(-LengthAddedfromZoom - factory.Objects[plane].sprite.BoundingBoxRect.Width, -850); //moved plane up 100 pixels so won't collide with that one map
            factory.Objects[plane].sprite.Scale = 2;
            factory.Objects[plane].sprite.PhysicsBodyFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(factory.Objects[plane].sprite.BoundingBoxRect.Width), ConvertUnits.ToSimUnits(factory.Objects[plane].sprite.BoundingBoxRect.Height), 1, ConvertUnits.ToSimUnits(new Vector2(0, 0)), factory.Objects[plane].sprite.PhysicsBody);
            factory.Objects[plane].sprite.PhysicsBodyFixture.OnCollision += new OnCollisionEventHandler(factory.Objects[plane].sprite.HandleCollision);
            factory.Objects[plane].saveable = false;

            soundBuzz = AudioManager.Instance.GetSoundEffectLooped("airplane");
            soundBuzz.Volume = 0.2f;
            soundBuzz.Play();

            isCreated = true;
        }
        public void Play(string soundEffectName, bool isLooped,float volume)
        {
            soundEffect = gestionnaireDeSoundEffect.Find(soundEffectName);
            
            if (!(listeSound.Contains(soundEffectName)))
            {
                listeSound.Add(soundEffectName);
                soundEffectInstanceList.Add(soundEffect.CreateInstance());
            }
            for(int i = 0; i < listeSound.Count;++i)
            {
                test = string.Compare(listeSound[i], soundEffectName) == 0;
                if (test)
                {
                    index = i;
                    break;
                }

            }
            test = false;
            soundEffectInstance = soundEffectInstanceList[index];
            
            if (isLooped && !estRentré)
            {
                soundEffectInstance.IsLooped = true;
                estRentré = true;
            }
            soundEffectInstance.Volume = volume;
            if(!(soundEffectInstance.State == SoundState.Playing))
                soundEffectInstance.Play();
        }
 public DisposableSoundEffect(SoundEffectInstance instance, float volume, List<DisposableSoundEffect> toDelete)
 {
     this.instance = instance;
     this.toDelete = toDelete;
     instance.IsLooped = false;
     instance.Volume = volume;
     instance.Play();
 }
Example #19
0
 public static void Changement_son(int song)
 {
     sonmanager.Stop();
     piste = song;
     sonmanager = sons[song].CreateInstance();
     sonmanager.IsLooped = true;
     sonmanager.Play();
 }
Example #20
0
 public void StartPlaying(String name)
 {
     if (_soundBank.ContainsKey(name))
     {
         _effectInstance = _soundBank[name].CreateInstance();
         _effectInstance.Play();
     }
 }
Example #21
0
 public void PlaySound(SoundEffectEnum sound)
 {
     if (!Settings.Instance.MyAppSettings.GameSettings.IsSoundOn)
         return;
     m_soundEffectInstance = m_sounds[sound];
     m_soundEffectInstance.Volume = Settings.Instance.MyAppSettings.GameSettings.SoundVolume;
     m_soundEffectInstance.Play();
 }
 public void playSilencer()
 {
     if (Silinst == null || Silinst.State == SoundState.Stopped)
     {
         Silinst = SilencerSound.CreateInstance();
         Silinst.Play();
     }
 }
 public void playgun()
 {
     if (guninst == null || guninst.State == SoundState.Stopped)
     {
         guninst = gun.CreateInstance();
         guninst.Play();
     }
 }
 public void playMagnum()
 {
     if (Maginst == null || Maginst.State == SoundState.Stopped)
     {
         Maginst = magnumSound.CreateInstance();
         Maginst.Play();
     }
 }
Example #25
0
 private static void StartBG(string aName, float aLevel)
 {
     SoundEffect bgm = FindAudioClip(aName);
     sBackgroundAudio = bgm.CreateInstance();
     sBackgroundAudio.IsLooped = true;
     sBackgroundAudio.Volume = aLevel;
     sBackgroundAudio.Play();
 }
 public void playExtinguisher()
 {
     if (Extinst == null || Extinst.State == SoundState.Stopped)
     {
         Extinst = ExtinguisherSound.CreateInstance();
         Extinst.Play();
     }
 }
 public override void Initialize()
 {
     if (player.IsLocal())
     {
         intro = Game.Content.Load<SoundEffect>("audio/Intro" + Game1.localPlayer.ColorName()).CreateInstance();
         intro.Play();
     }
 }
Example #28
0
        public static void JouerBruitage(int nombre)
        {
            if (sonmanager != null && sonmanager.State != SoundState.Stopped)
                sonmanager.Stop();

            sonmanager = sons[nombre].CreateInstance();
            sonmanager.IsLooped = false;
            sonmanager.Play();
        }
 public void PlayVehicleFenceCollision()
 {
     if (_collisionInstance != null && _collisionInstance.State == SoundState.Playing)
     {
         return;
     }
     _collisionInstance = _collisions[Utility.RandomGenerator.Next(_collisions.Count)].CreateInstance();
     _collisionInstance.Play();
 }
Example #30
0
 public static void PlaySoundEffect(SoundEffect soundEffect)
 {
     if (Settings.IsSoundsOn)
     {
         soundEffectInstance = soundEffect.CreateInstance();
         soundEffectInstance.Volume = 0.5f;
         soundEffectInstance.Play();
     }
 }
Example #31
0
        public bool Play(float volume, float pitch, float pan)
        {
#if DIRECTX
            if (MasterVolume > 0.0f)
            {
                if (_playingInstances == null)
                {
                    // Allocate lists first time we need them.
                    _playingInstances      = new List <SoundEffectInstance>();
                    _availableInstances    = new List <SoundEffectInstance>();
                    _toBeRecycledInstances = new List <SoundEffectInstance>();
                }
                else
                {
                    // Cleanup instances which have finished playing.
                    foreach (var inst in _playingInstances)
                    {
                        if (inst.State == SoundState.Stopped)
                        {
                            _toBeRecycledInstances.Add(inst);
                        }
                    }
                }

                // Locate a SoundEffectInstance either one already
                // allocated and not in use or allocate a new one.
                SoundEffectInstance instance = null;
                if (_toBeRecycledInstances.Count > 0)
                {
                    foreach (var inst in _toBeRecycledInstances)
                    {
                        _availableInstances.Add(inst);
                        _playingInstances.Remove(inst);
                    }
                    _toBeRecycledInstances.Clear();
                }
                if (_availableInstances.Count > 0)
                {
                    instance = _availableInstances[0];
                    _playingInstances.Add(instance);
                    _availableInstances.Remove(instance);
                }
                else
                {
                    instance = CreateInstance();
                    _playingInstances.Add(instance);
                }

                instance.Volume = volume;
                instance.Pitch  = pitch;
                instance.Pan    = pan;
                instance.Play();
            }

            // XNA documentation says this method returns false if the sound limit
            // has been reached. However, there is no limit on PC.
            return(true);
#else
            if (MasterVolume > 0.0f)
            {
                if (_instance == null)
                {
                    _instance = CreateInstance();
                }
                _instance.Volume = volume;
                _instance.Pitch  = pitch;
                _instance.Pan    = pan;
                _instance.Play();
                return(_instance.Sound.Playing);
            }
            return(false);
#endif
        }
Example #32
0
        public void Play(float volume, AudioEngine engine)
        {
            _cueVolume = volume;
            var category = engine.Categories[_categoryID];

            var curInstances = category.GetPlayingInstanceCount();

            if (curInstances >= category.maxInstances)
            {
                var prevSound = category.GetOldestInstance();

                if (prevSound != null)
                {
                    prevSound.SetFade(0.0f, category.fadeOut);
                    prevSound.Stop(AudioStopOptions.Immediate);
                    SetFade(category.fadeIn, 0.0f);
                }
            }

            float finalVolume = _volume * _cueVolume * category._volume[0];
            float finalPitch  = _pitch + _cuePitch;
            float finalMix    = _useReverb ? _cueReverbMix : 0.0f;

            if (_complexSound)
            {
                foreach (XactClip clip in _soundClips)
                {
                    clip.UpdateState(finalVolume, finalPitch, finalMix, _cueFilterFrequency, _cueFilterQFactor);
                    clip.Play();
                }
            }
            else
            {
                if (_wave != null)
                {
                    if (_streaming)
                    {
                        _wave.Dispose();
                    }
                    else
                    {
                        _wave._isXAct = false;
                    }
                    _wave = null;
                }

                _wave = _soundBank.GetSoundEffectInstance(_waveBankIndex, _trackIndex, out _streaming);

                if (_wave == null)
                {
                    // We couldn't create a sound effect instance, most likely
                    // because we've reached the sound pool limits.
                    return;
                }

                _wave.Pitch  = finalPitch;
                _wave.Volume = finalVolume;
                _wave.PlatformSetReverbMix(finalMix);
                _wave.Play();
            }
        }
Example #33
0
        private void Play(bool pickNewWav)
        {
            var trackCount = _tracks.Length;

            // Do we need to pick a new wav to play first?
            if (pickNewWav)
            {
                switch (_variation)
                {
                case VariationType.Ordered:
                    _wavIndex = (_wavIndex + 1) % trackCount;
                    break;

                case VariationType.OrderedFromRandom:
                    _wavIndex = (_wavIndex + 1) % trackCount;
                    break;

                case VariationType.Random:
                    if (_weights == null || trackCount == 1)
                    {
                        _wavIndex = XactHelpers.Random.Next() % trackCount;
                    }
                    else
                    {
                        var sum = XactHelpers.Random.Next(_totalWeights);
                        for (var i = 0; i < trackCount; i++)
                        {
                            sum -= _weights[i];
                            if (sum <= 0)
                            {
                                _wavIndex = i;
                                break;
                            }
                        }
                    }
                    break;

                case VariationType.RandomNoImmediateRepeats:
                {
                    if (_weights == null || trackCount == 1)
                    {
                        _wavIndex = XactHelpers.Random.Next() % trackCount;
                    }
                    else
                    {
                        var last = _wavIndex;
                        var sum  = XactHelpers.Random.Next(_totalWeights);
                        for (var i = 0; i < trackCount; i++)
                        {
                            sum -= _weights[i];
                            if (sum <= 0)
                            {
                                _wavIndex = i;
                                break;
                            }
                        }

                        if (_wavIndex == last)
                        {
                            _wavIndex = (_wavIndex + 1) % trackCount;
                        }
                    }
                    break;
                }

                case VariationType.Shuffle:
                    // TODO: Need some sort of deck implementation.
                    _wavIndex = XactHelpers.Random.Next() % trackCount;
                    break;
                }
                ;
            }

            _wav = _soundBank.GetSoundEffectInstance(_waveBanks[_wavIndex], _tracks[_wavIndex]);
            if (_wav == null)
            {
                // We couldn't create a sound effect instance, most likely
                // because we've reached the sound pool limits.
                return;
            }

            // Do all the randoms before we play.
            if (_volumeVar.HasValue)
            {
                _trackVolume = _volumeVar.Value.X + ((float)XactHelpers.Random.NextDouble() * _volumeVar.Value.Y);
            }
            if (_pitchVar.HasValue)
            {
                _trackPitch = _pitchVar.Value.X + ((float)XactHelpers.Random.NextDouble() * _pitchVar.Value.Y);
            }
            if (_clip.FilterEnabled)
            {
                if (_filterVar.HasValue)
                {
                    _trackFilterFrequency = _filterVar.Value.X + ((float)XactHelpers.Random.NextDouble() * _filterVar.Value.Y);
                    _trackFilterQFactor   = _filterVar.Value.Z + ((float)XactHelpers.Random.NextDouble() * _filterVar.Value.W);
                }
                else
                {
                    _trackFilterFrequency = _clip.FilterFrequency;
                    _trackFilterQFactor   = _clip.FilterQ;
                }
            }

            // This is a shortcut for infinite looping of a single track.
            _wav.IsLooped = _loopCount == 255 && trackCount == 1;

            // Update all the wave states then play.
            UpdateState();
            _wav.Play();
        }