Apply3D() public method

Applies 3D positioning to the SoundEffectInstance using a single listener.
public Apply3D ( Microsoft.Xna.Framework.Audio.AudioListener listener, Microsoft.Xna.Framework.Audio.AudioEmitter emitter ) : void
listener Microsoft.Xna.Framework.Audio.AudioListener Data about the listener.
emitter Microsoft.Xna.Framework.Audio.AudioEmitter Data about the source of emission.
return void
Esempio n. 1
0
File: Cue.cs Progetto: raizam/FNA
        private void PlayWave(PlayWaveEvent evt, float?prevVolume = null, float?prevPitch = null)
        {
            SoundEffectInstance sfi = evt.GenerateInstance(
                INTERNAL_activeSound.Volume,
                INTERNAL_activeSound.Pitch,
                INTERNAL_eventLoops[evt],
                prevVolume,
                prevPitch
                );

            if (sfi != null)
            {
                if (INTERNAL_isPositional)
                {
                    sfi.Apply3D(INTERNAL_listener, INTERNAL_emitter);
                }
                foreach (uint curDSP in INTERNAL_activeSound.DSPCodes)
                {
                    // FIXME: This only applies the last DSP!
                    sfi.INTERNAL_applyReverb(
                        INTERNAL_baseEngine.INTERNAL_getDSP(curDSP)
                        );
                }
                INTERNAL_instancePool.Add(sfi);
                INTERNAL_instanceVolumes.Add(sfi.Volume);
                INTERNAL_instancePitches.Add(sfi.Pitch);
                INTERNAL_waveEventSounds.Add(sfi, evt);
                INTERNAL_rpcTrackVolumes.Add(1.0f);
                INTERNAL_rpcTrackPitches.Add(0.0f);
                sfi.Play();
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
 public override void Apply3D(AudioListener listener, AudioEmitter emitter)
 {
     if (_wav != null)
     {
         _wav.Apply3D(listener, emitter);
     }
 }
Esempio n. 4
0
            public override void PlayPositional(AudioListener listener, AudioEmitter emitter)
            {
                SoundEffectInstance newInstance = wave.CreateInstance();

                newInstance.Volume   = Volume;
                newInstance.IsLooped = IsLooped;
                newInstance.Apply3D(listener, emitter);
                newInstance.Play();
                instancePool.Add(newInstance);
            }
Esempio n. 5
0
        public Rocket(MobileFortressClient game, ushort resource, Vector3 position, Quaternion orientation)
            : base(game, resource, position, orientation)
        {
            rocketEngineSound = Resources.Sounds.RocketEngine.CreateInstance();
            UpdateAudio();
            SoundEffectInstance rocketNoise = Resources.Sounds.WeaponSounds[3].CreateInstance();
            rocketNoise.Apply3D(Camera.Audio,Audio);
            rocketNoise.Play();

            rocketEngineSound.IsLooped = true;
            rocketEngineSound.Apply3D(Camera.Audio, Audio);
            rocketEngineSound.Play();
        }
Esempio n. 6
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            soundEffect = this.Content.Load<SoundEffect>("circus");
            instance = soundEffect.CreateInstance();
            instance.IsLooped = true;

            listener = new AudioListener();
            emitter = new AudioEmitter();

            // WARNING!!!!  Apply3D requires sound effect be Mono!  Stereo will throw exception
            instance.Apply3D(listener, emitter);
            instance.Play();
        }
Esempio n. 7
0
 public void Apply3D(AudioListener listener, AudioEmitter emitter)
 {
     if (_complexSound)
     {
         foreach (var clip in _soundClips)
         {
             clip.Apply3D(listener, emitter);
         }
     }
     else
     {
         if (_wave != null)
         {
             _wave.Apply3D(listener, emitter);
         }
     }
 }
Esempio n. 8
0
        internal void PlayWave(
            EventInstance eventInstance,
            double?prevVolume = null,
            short?prevPitch   = null
            )
        {
            PlayWaveEventInstance playWaveEventInstance =
                (PlayWaveEventInstance)eventInstance;
            PlayWaveEvent evt = (PlayWaveEvent)eventInstance.Event;

            double finalVolume;
            short  finalPitch;
            SoundEffectInstance sfi = evt.GenerateInstance(
                INTERNAL_activeSound.Sound.Volume,
                INTERNAL_activeSound.Sound.Pitch,
                playWaveEventInstance.LoopCount,
                prevVolume,
                prevPitch,
                out finalVolume,
                out finalPitch
                );

            if (sfi != null)
            {
                if (INTERNAL_isPositional)
                {
                    sfi.Apply3D(INTERNAL_listener, INTERNAL_emitter);
                }
                foreach (uint curDSP in INTERNAL_activeSound.Sound.DSPCodes)
                {
                    // FIXME: This only applies the last DSP!
                    sfi.INTERNAL_applyReverb(
                        INTERNAL_baseEngine.INTERNAL_getDSP(curDSP)
                        );
                }
                INTERNAL_instancePool.Add(sfi);
                INTERNAL_instanceVolumes.Add(finalVolume);
                INTERNAL_instancePitches.Add(finalPitch);

                INTERNAL_playWaveEventBySound.Add(sfi, playWaveEventInstance);
                INTERNAL_rpcTrackVolumes.Add(0.0f);
                INTERNAL_rpcTrackPitches.Add(0.0f);
                sfi.Play();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Helps apply the distance effect of our music and enemy foot step
        /// </summary>
        /// <param name="listener">The listener of the sound and music</param>
        /// <param name="location">The location that emits the sound and music</param>
        /// <param name="music"></param>
        public void Apply3DAudio(AudioListener listener, Vector3 location, SoundEffectInstance music)
        {
            AudioEmitter emitter = new AudioEmitter();
            emitter.Position = location;
            emitter.Up = Vector3.Up;
            emitter.Velocity = location - position;
            emitter.Forward = Vector3.Normalize(location - position);
            music.Apply3D(listener, emitter);

            if ( leftLegRotation < MIN_LEG_ROTATION || rightLegRotation < MIN_LEG_ROTATION )
            {
                // switch between left and right foot step sound
                if (isLeftLegForward)
                {
                    SoundEffectInstance sfxInstance = leftFootStepAudio.CreateInstance();
                    sfxInstance.IsLooped = false;
                    sfxInstance.Apply3D(listener, emitter);
                    sfxInstance.Play();
                }
                else
                {
                    SoundEffectInstance sfxInstance = rightFootStepAudio.CreateInstance();
                    sfxInstance.IsLooped = false;
                    sfxInstance.Apply3D(listener, emitter);
                    sfxInstance.Play();
                }
                // Switch legs
                isLeftLegForward = !isLeftLegForward;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="se"></param>
        /// <param name="ae"></param>
        /// <returns></returns>
        public SoundEffectInstance Update3DSoundEffect(SoundEffectInstance se, AudioEmitter ae)
        {
            se.Apply3D(AvatarListener, ae);

            return se;
        }
Esempio n. 11
0
 public static void Apply3D(SoundEffectInstance soundCue)
 {
     soundCue.Apply3D(listner, emitter);
 }
        private void handleBullets()
        {
            //bullet stuff
            if (bulletQueue.Count > 0)
            {
                tempBulletArray = bulletQueue.ToArray();
                bulletQueue.Clear();                                  //convert to array, clear the queue and fill it up after changes

                for (int i = 0; i < tempBulletArray.Length; i++)
                {
                    ((Bullet)tempBulletArray.GetValue(i)).CurrentPos += ((Bullet)tempBulletArray.GetValue(i)).DirectionIncrement;

                    bulletQueue.Enqueue((Bullet)tempBulletArray.GetValue(i));
                }

                if (((Bullet)bulletQueue.Peek()).isDead())        //remove dead bullets from the queue
                {
                    bulletQueue.Dequeue();
                }

                tempBulletArray = bulletQueue.ToArray();
            }

            //this is the frame where the bullet is created
            if (animation.currentFrame == 18 && bulletAdded == false && (activity == EnemyActivity2.enemyShootDown || activity == EnemyActivity2.enemyShootDiagDown || activity == EnemyActivity2.enemyShootAhead || activity == EnemyActivity2.enemyShootDiagUp || activity == EnemyActivity2.enemyShootUp))
            {
                Bullet bullet = new Bullet();

                if (MainMenuScreen.currentGameScreen == 1)
                {
                    bullet.Texture = GameplayScreen.bulletTex2;
                }
                else
                {
                    bullet.Texture = GameplayScreen2.bulletTex2;
                }

                if(animation.myEffect == SpriteEffects.FlipHorizontally)  //to the right
                {
                    if (activity == EnemyActivity2.enemyShootDown)
                    {
                        bullet.DirectionIncrement = new Vector2(0f, 1f);
                        bullet.Origin = Position + new Vector2(21f, 70f);
                    }
                    else if (activity == EnemyActivity2.enemyShootDiagDown)
                    {
                        bullet.DirectionIncrement = new Vector2(0.75f, 0.75f);
                        bullet.Origin = Position + new Vector2(60f, 50f);
                    }
                    else if (activity == EnemyActivity2.enemyShootAhead)
                    {
                        bullet.DirectionIncrement = new Vector2(1f, 0f);
                        bullet.Origin = Position + new Vector2(90f, -5f);
                    }
                    else if (activity == EnemyActivity2.enemyShootDiagUp)
                    {
                        bullet.DirectionIncrement = new Vector2(0.75f, -0.75f);
                        bullet.Origin = Position + new Vector2(65f, -73f);
                    }
                    else if (activity == EnemyActivity2.enemyShootUp)
                    {
                        bullet.DirectionIncrement = new Vector2(0f, -1f);
                        bullet.Origin = Position + new Vector2(2f, -100f);
                    }
                }
                else   //to the left
                {
                    if (activity == EnemyActivity2.enemyShootDown)
                    {
                        bullet.DirectionIncrement = new Vector2(0f, 1f);
                        bullet.Origin = Position + new Vector2(-35f, 70f);
                    }
                    else if (activity == EnemyActivity2.enemyShootDiagDown)
                    {
                        bullet.DirectionIncrement = new Vector2(-0.75f, 0.75f);
                        bullet.Origin = Position + new Vector2(-87f, 58f);
                    }
                    else if (activity == EnemyActivity2.enemyShootAhead)
                    {
                        bullet.DirectionIncrement = new Vector2(-1f, 0f);
                        bullet.Origin = Position + new Vector2(-90f, -5f);
                    }
                    else if (activity == EnemyActivity2.enemyShootDiagUp)
                    {
                        bullet.DirectionIncrement = new Vector2(-0.75f, -0.75f);
                        bullet.Origin = Position + new Vector2(-77f, -75f);
                    }
                    else if (activity == EnemyActivity2.enemyShootUp)
                    {
                        bullet.DirectionIncrement = new Vector2(0f, -1f);
                        bullet.Origin = Position + new Vector2(-16f, -100f);
                    }
                }

                bullet.MaxDistanceFromOrigin = 1500;
                bullet.Speed = 6;
                bullet.CurrentPos = bullet.Origin;
                bullet.DirectionIncrement *= bullet.Speed;

                bulletQueue.Enqueue(bullet);    //add the bullet to the queue of bullets

                bulletAdded = true;

                soundEffectInstance = GameStateManagementGame.bearShoot.CreateInstance();        //play bullet sound quitely if far away

                if (MainMenuScreen.currentGameScreen == 1)
                {
                    soundEffectInstance.Apply3D(GameplayScreen.audioListener, audioEmitter);
                    soundEffectInstance.Play();
                }
                else
                {
                    soundEffectInstance.Apply3D(GameplayScreen2.audioListener, audioEmitter);
                    soundEffectInstance.Play();
                }
            }

            if (animation.currentFrame > 18 && (activity == EnemyActivity2.enemyShootDown || activity == EnemyActivity2.enemyShootDiagDown || activity == EnemyActivity2.enemyShootAhead || activity == EnemyActivity2.enemyShootDiagUp || activity == EnemyActivity2.enemyShootUp))
            {
                bulletAdded = false;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            KeyboardState keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.Space) && prevKeyboardState.IsKeyUp(Keys.Space))
            {
                currentSound = applause.CreateInstance();
                listener = new AudioListener();
                listener.Position = camera.Position;
                listener.Up = camera.Up;
                listener.Forward = camera.Forward;

                emitter = new AudioEmitter();
                emitter.Position = cube.Position;
                emitter.Up = Vector3.Up;
                emitter.Forward = -camera.Forward;

                currentSound.Apply3D(listener, emitter);
                currentSound.Play();
            }

            cube.RotateY = 0.05f;
            cube.RotateX = 0.01f;

            MouseState mouseState = Mouse.GetState();
            if (mouseState.LeftButton == ButtonState.Pressed && prevMouseState.LeftButton == ButtonState.Released)
            {
                ray = new Ray();
                ray.Position = GraphicsDevice.Viewport.Unproject(
                    new Vector3(mouseState.X, mouseState.Y, 0),
                    camera.Projection, camera.View, cube.World);
                ray.Direction = GraphicsDevice.Viewport.Unproject(
                    new Vector3(mouseState.X, mouseState.Y, 1),
                    camera.Projection, camera.View, cube.World) - ray.Position;
                BoundingBox box = new BoundingBox(-Vector3.One, Vector3.One);

                if (box.Intersects(ray) != null)
                /*if(nextClick == i)*/
                {
                    SetupNext();

                    currentSound = applause.CreateInstance();
                    currentSound.Play();
                    clicked = true;
                }
                else
                {

                }

            }

            listener.Position += Vector3.UnitZ * 0.05f;
            currentSound.Apply3D(listener, emitter);
            currentSound.Play();

            prevKeyboardState = keyboardState;
            prevMouseState = mouseState;

            cube.Update(gameTime);
            base.Update(gameTime);
        }
Esempio n. 14
0
        public void Update(SoundObject soundObj, SoundEffectInstance inst)
        {
            inst.Volume = soundObj.Volume;

            if (Type == SoundType.World || Type == SoundType.Global)
            {
                SoundEffect.DistanceScale = soundObj.Radius;
                inst.Apply3D(listener, soundObj.Emitter);
            }
        }