Exemple #1
0
 public void Apply3DPosition(Cue cue, AudioListener listener, AudioEmitter emitter,
     Vector3 listenerPosition, Vector3 emitterPosition)
 {
     listenerPosition = listener.Position;
     emitterPosition = emitter.Position;
     cue.Apply3D(listener, emitter);
 }
 public SoundManager(Game game)
     : base(game)
 {
     _sounds = new List<AudioSound>();
     _listener = new AudioListener();
     _emitter = new AudioEmitter();
 }
Exemple #3
0
        public override void Destroy()
        {
            isDestroyed = true;

            Vector3 pos = position;
            //float amount = (float)(min + (float)random.NextDouble() * (max - min));
            double min = 0;
            double max = MathHelper.TwoPi;
            double angle;
            for (int i = 0; i < numExplosionSmokeParticles; i++)
            {
                pos = position;
                angle = min + Screen.random.NextDouble() * (max - min);
                Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), rotation.X);
                pos.Y += (float)(radius * Math.Sin(angle));
                pos.X += (float)(radius * Math.Cos(angle));

                drawClass.ringExplosionParticles.AddParticle(pos, Body.Velocity);
                pos.Y -= 0.02f;
            }

            Screen.cue = parentGame.soundBank.GetCue("ring");

            AudioEmitter emitter = new AudioEmitter();
            emitter.Position = position;
            Screen.cue.Apply3D(Screen.listener, emitter);
            Screen.cue.Play();
        }
Exemple #4
0
 public Cue PlaySound(string soundName, AudioListener audioListener, AudioEmitter audioEmitter)
 {
     Cue result = GetCue(soundName);
     result.Apply3D(audioListener, audioEmitter);
     result.Play();
     return result;
 }
 public override void Dispose()
 {
     _instance.Dispose();
     _getEmitterPos = null;
     _getEmitterMove = null;
     _emitter = null;
 }
Exemple #6
0
 public void ChangeEmitterVelocity(AudioEmitter emitter, float maxVelocity, bool increase, float amount)
 {
     if (increase)
         emitter.Velocity = new Vector3(maxVelocity * amount, 0.0f, 0.0f);
     else
         emitter.Velocity = new Vector3(-maxVelocity * amount, 0.0f, 0.0f);
 }
        private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
        {
            // If we have no voice then nothing to do.
            if (_voice == null)
                return;

            // Convert from XNA Emitter to a SharpDX Emitter
            var e = emitter.ToEmitter();
            e.CurveDistanceScaler = SoundEffect.DistanceScale;
            e.DopplerScaler = SoundEffect.DopplerScale;
            e.ChannelCount = _effect._format.Channels;

            // Convert from XNA Listener to a SharpDX Listener
            var l = listener.ToListener();

            // Number of channels in the sound being played.
            // Not actually sure if XNA supported 3D attenuation of sterio sounds, but X3DAudio does.
            var srcChannelCount = _effect._format.Channels;

            // Number of output channels.
            var dstChannelCount = SoundEffect.MasterVoice.VoiceDetails.InputChannelCount;

            // XNA supports distance attenuation and doppler.            
            var dpsSettings = SoundEffect.Device3D.Calculate(l, e, CalculateFlags.Matrix | CalculateFlags.Doppler, srcChannelCount, dstChannelCount);

            // Apply Volume settings (from distance attenuation) ...
            _voice.SetOutputMatrix(SoundEffect.MasterVoice, srcChannelCount, dstChannelCount, dpsSettings.MatrixCoefficients, 0);

            // Apply Pitch settings (from doppler) ...
            _voice.SetFrequencyRatio(dpsSettings.DopplerFactor);
        }
 public AssemblyLane(ContentManager content, Vector3 position, Vector3 rotation, float scale)
     : base(@"Models\AssemblyLane", content, position, rotation, scale)
 {
     FogEnd = 10000;
     emitter = new AudioEmitter();
     emitter.Position = position;
 }
Exemple #9
0
        public XnaAudioSource(AudioEmitter audioEmitter)
        {
            if (audioEmitter == null)
                throw new ArgumentNullException ("audioEmitter");

            this.audioEmitter = audioEmitter;
        }
Exemple #10
0
 protected SoundObject(ISoundObjectParent parent, SoundEffectGame sfx)
 {
     this.parent = parent;
     this.soundEffectGame = sfx;
     this.emitter = new AudioEmitter();
     this.Volume = sfx.Volume;
 }
        public CueEmitter(Cue sound, Vector3 position)
        {
            cue = sound;

            audioEmitter = new AudioEmitter();
            audioEmitter.Position = position;
            audioEmitter.Velocity = Vector3.Zero;
        }
Exemple #12
0
 public void Apply3DAll(Cue cue, AudioListener listener, AudioEmitter emitter, Vector3 listenerPosition,
     Vector3 emitterPosition, Vector3 listenerVelocity, Vector3 emitterVelocity)
 {
     listenerPosition = listener.Position;
     emitterPosition = emitter.Position;
     listener.Velocity = listener.Velocity;
     emitter.Velocity = emitter.Velocity;
     cue.Apply3D(listener, emitter);
 }
 public HangarSound(string soundName, Vector3 position, float volume = 1, float customDivFact = 300)
 {
     this.soundName = soundName;
     this.volume = volume;
     divFact = customDivFact;
     this.position = position;
     emitter = new AudioEmitter();
     emitter.Position = position;
 }
        public Enemy(string modelName, ContentManager content, float scale)
        {
            this.modelName = modelName;
            LoadContent(content);
            modelScale = scale;
            emitter = new AudioEmitter();

            emitter.Position = position;
        }
 public PositionedSound(Cue cue, String cueName, string soundBankFile)
     : base()
 {
     mSound = new Sound(cue, cueName, soundBankFile);
     Variables = mSound.Variables;
     mSound.OnCueRetrieved += new Sound.OnCueRetrievedHandler(UpdateAudio);
     
     mEmitter = new AudioEmitter();
 }
Exemple #16
0
        /// <summary>
        /// Creates a new instance of CorvSoundEffectCue with attenuation.
        /// </summary>
        public CorvSoundEffectCue(Cue cue, Vector2 listenerPosition, Vector2 emitterPosition)
            : base(cue)
        {
            this._Listener = new AudioListener();
            this._Listener.Position = new Vector3(listenerPosition, 0);
            this._Emitter = new AudioEmitter();
            this._Emitter.Position = new Vector3(emitterPosition, 0);

            Cue.Apply3D(this._Listener, this._Emitter);
        }
 public Key(ContentManager content, string keyID)
     : base(@"Models\Key", content)
 {
     emitter = new AudioEmitter();
     emitter.Position = position;
     this.KeyID = keyID;
     screenTransforms = new Matrix[base.model.Bones.Count];
     screenWorldMatrix = Matrix.Identity;
     GetKeyColor(keyID);
 }
        public PianoPlayer(Game game)
        {
            _tune = game.Content.Load<SoundEffect>("piano");
            _tuneInstance = _tune.CreateInstance();
            _tuneInstance.IsLooped = true;

            _emitter = new AudioEmitter();
            _emitter.Forward = Vector3.Backward;
            _emitter.Up = Vector3.Up;
        }
        /// <summary>
        /// Create a car Actor which can interface with the BEPU physics engine
        /// </summary>
        /// <param name="position"></param>
        /// <param name="orientation"></param>
        public BepuCarActor(Game game, CarModelRenderer renderer, Matrix worldMatrix)
            : base(game, renderer)
        {
            emitter_ = new AudioEmitter();
            CarSoundEmitters.AudioEmitters.Add(emitter_);

            // create a pin (for keeping the car stuck to the track)
            Capsule pin = new Capsule(new Vector3(0, -0.7f, -2), 0.6f, 0.12f, 1);
            pin.Bounciness = 0f;
            pin.DynamicFriction = 0f;
            pin.StaticFriction = 0f;

            // create a body:
            CompoundBody body = new CompoundBody();
            body.AddBody(new Box(new Vector3(0, 0, 0), 2.5f, .75f, 4.5f, 60));
            body.AddBody(new Box(new Vector3(0, .75f / 2 + .3f / 2, .5f), 2.5f, .3f, 2f, 1));
            body.AddBody(pin);
            body.CenterOfMassOffset = new Vector3(0, -.5f, 0);

            body.WorldTransform = worldMatrix;
            body.LinearVelocity = Vector3.Zero;
            body.AngularVelocity = Vector3.Zero;
            // construct the car:
            car = new Vehicle(body);

            // attach wheels:
            Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
            for (int i = 0; i < 4; i++)
            {
                Wheel wheel = new Wheel(
                                 new RaycastWheelShape(.375f, wheelGraphicRotation),
                                 new WheelSuspension(2000, 100f, Vector3.Down, .8f,
                                     new Vector3(
                                         ( i <= 1 ) ? -1.1f : 1.1f,
                                         0,
                                         ( (i & 1) == 0 ) ? 1.8f : - 1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5));

                car.AddWheel(wheel);

                // adjust additional values
                wheel.Shape.FreezeWheelsWhileBraking = true;
                wheel.Suspension.SolverSettings.MaximumIterations = 2;
                wheel.Brake.SolverSettings.MaximumIterations = 2;
                wheel.SlidingFriction.SolverSettings.MaximumIterations = 2;
                wheel.DrivingMotor.SolverSettings.MaximumIterations = 2;

            }

            // add it to physics
            Engine.currentWorld.Space.Add(car);
        }
 public FinalGate(ContentManager content,
     ref List<AABB> collisionList,
     Vector3 position, Vector3 rotation, float scale)
     : base(@"Models\Environment\FinalGatePillars", content, position, rotation, scale)
 {
     CreateDoors(content, ref collisionList, position, scale);
     base.FogEnd = 3000;
     currentState = GateState.CLOSED;
     emitter = new AudioEmitter();
     emitter.Position = position;
 }
 public SoundInstanceXNA(SoundEffectInstance effect, Func<Vector2?> getEmitterPos, Func<Vector2?> getEmitterMove, float baseVolume, float distanceScale)
 {
     _instance = effect;
     _getEmitterPos = getEmitterPos;
     _getEmitterMove = getEmitterMove;
     _emitter = new AudioEmitter();
     _baseVolume = baseVolume;
     _distanceScale = distanceScale;
     SetVolume(1);
     UpdateSpatial(DEFAULT_LISTENERS);
 }
 public Key(ContentManager content, Vector3 position, Vector3 rotation, float scale, string keyID)
     : base(@"Models\Key", content, position, rotation, scale)
 {
     CreateUseAABB(Vector3.Zero, position, 75, 0);
     Interactables.AddInteractable(this);
     emitter = new AudioEmitter();
     emitter.Position = position;
     this.KeyID = keyID;
     screenTransforms = new Matrix[base.model.Bones.Count];
     screenWorldMatrix = Matrix.Identity;
     GetKeyColor(keyID);
 }
Exemple #23
0
        /// <summary>
        /// Base constructor - registers the component and adds it to the entity.
        /// </summary>
        /// <param name="parent"></param>
        public SoundComponent_cl(Entity_cl parent)
            : base(parent)
        {
            mSoundEmitter = new AudioEmitter();
            PositionComponent_cl emitterPosition = (PositionComponent_cl)mParentEntity.GetComponentOfType(typeof(PositionComponent_cl));
            mSoundEmitter.Position = emitterPosition.Position3D;

            Managers.SoundManager_cl.Instance.RegisterComponent(this);
            mParentEntity.AddComponent(this);

            mSounds3DList = new List<Cue>();
        }
Exemple #24
0
 private void Apply3D(Transform2D transform, Components.AudioEmitter emitter,
                      SoundEffectInstance instance)
 {
     Microsoft.Xna.Framework.Audio.AudioEmitter xnaEmitter = new Microsoft.Xna.Framework.Audio.AudioEmitter
     {
         Position     = new Vector3(transform.Position.X, 0, transform.Position.Y),
         Forward      = new Vector3(),
         Up           = new Vector3(0, 1, 0),
         Velocity     = new Vector3(emitter.Velocity.X, 0, emitter.Velocity.Y),
         DopplerScale = emitter.DopplerScale,
     };
     instance.Apply3D(listener, xnaEmitter);
 }
        public AudioManager(Game game)
        {
            soundBank = game.Content.LoadDirectory<SoundEffect>("audio/bz");
            musicBank = game.Content.LoadDirectory<Song>("audio/music");

            // register ourselves as a service
            if (game.Services != null)
                game.Services.AddService(typeof(IAudioManager), this);

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

        }
Exemple #26
0
        public Cue PlaySound(string soundName, AudioListener audioListener, AudioEmitter audioEmitter, AudioHandler callback)
        {
            Cue result = PlaySound(soundName, audioListener, audioEmitter);

            // todo: need to make this multicast
            if (callbackList[result] != null)
            {
                callbackList[result].Invoke(result);
            }

            callbackList[result] = callback;
            return result;
        }
 /// <summary>
 /// The unlockedRotation must be on format vector3.left/right/foward/backwards
 /// </summary>
 public TurnablePilar(ContentManager content, Vector3 position,
     Vector3 rotation, Vector3 unlockedRotation, float scale,
     Vector3 color)
     : base(@"Models\Environment\SpiderStatue", content, position, rotation, scale)
 {
     CreateCollision(position, rotation, scale);
     base.rotation = rotation;
     unlockRotation = FindUnlockedDegreeRotation(unlockedRotation);
     IsUnlocked = false;
     thisInteractionTarget = base.rotation;
     emitter = new AudioEmitter();
     base.color = color;
 }
Exemple #28
0
 public Hazard(int x, int y, int w, int h, string ItemType)
     : base(x, y, w, h, ItemType)
 {
     isDangerous = true;
     if (itemType.Contains("wire"))
     {
         wireEmitter = new AudioEmitter();
         wireEmitter.Position = new Vector3(x, y, 0.0f);
         wireSound = GameVariables.wireFXInstance;
         wireSound.Volume = 0.2f;
         GameVariables.GameSounds.Add(wireSound);
     }
 }
Exemple #29
0
        static public SharpDX.X3DAudio.Emitter ToEmitter(this Audio.AudioEmitter emitter)
        {
            // Pulling out Vector properties for efficiency.
            var pos     = emitter.Position;
            var vel     = emitter.Velocity;
            var forward = emitter.Forward;
            var up      = emitter.Up;

            // From MSDN:
            //  X3DAudio uses a left-handed Cartesian coordinate system,
            //  with values on the x-axis increasing from left to right, on the y-axis from bottom to top,
            //  and on the z-axis from near to far.
            //  Azimuths are measured clockwise from a given reference direction.
            //
            // From MSDN:
            //  The XNA Framework uses a right-handed coordinate system,
            //  with the positive z-axis pointing toward the observer when the positive x-axis is pointing to the right,
            //  and the positive y-axis is pointing up.
            //
            // Programmer Notes:
            //  According to this description the z-axis (forward vector) is inverted between these two coordinate systems.
            //  Therefore, we need to negate the z component of any position/velocity values, and negate any forward vectors.

            forward *= -1.0f;
            pos.Z   *= -1.0f;
            vel.Z   *= -1.0f;

            return(new SharpDX.X3DAudio.Emitter()
            {
#if WINDOWS_UAP
                Position = new SharpDX.Mathematics.Interop.RawVector3 {
                    X = pos.X, Y = pos.Y, Z = pos.Z
                },
                Velocity = new SharpDX.Mathematics.Interop.RawVector3 {
                    X = vel.X, Y = vel.Y, Z = vel.Z
                },
                OrientFront = new SharpDX.Mathematics.Interop.RawVector3 {
                    X = forward.X, Y = forward.Y, Z = forward.Z
                },
                OrientTop = new SharpDX.Mathematics.Interop.RawVector3 {
                    X = up.X, Y = up.Y, Z = up.Z
                },
#else
                Position = new SharpDX.Vector3(pos.X, pos.Y, pos.Z),
                Velocity = new SharpDX.Vector3(vel.X, vel.Y, vel.Z),
                OrientFront = new SharpDX.Vector3(forward.X, forward.Y, forward.Z),
                OrientTop = new SharpDX.Vector3(up.X, up.Y, up.Z),
                DopplerScaler = emitter.DopplerScale,
#endif
            });
        }
 //Ctor without onUse object, used by duoLever objects
 public Lever(ContentManager content,
     Vector3 position, Vector3 rotation,
     float scale, Vector3 openFromDirection,
     bool isUsed = false)
     : base(@"Models\Environment\Lever",
         content, position, rotation, scale)
 {
     this.isUsed = isUsed;
     closedModel = base.GetModel();
     usedModel = content.Load<Model>(@"Models\Environment\LeverUsed");
     CreateUseAABB(openFromDirection, Position, 100, 100);
     emitter = new AudioEmitter();
     emitter.Position = position;
 }
        public override void AddedToStage(EventArgs e)
        {
            base.AddedToStage(e);

            if (audioListener == null)
            {
                audioListener = new AudioListener();
                audioListener.Position = new Vector3(600, 0, 0);
                audioListener.Velocity = new Vector3(0, 0, 0);
                audioListener.Forward = new Vector3(-1, 0, 0);
            }
            audioEmitter = new AudioEmitter();
            audioEmitter.Forward = new Vector3(1, 0, 0);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ISoundEmitter3D"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="SoundName">Name of the sound.</param>
        public ISoundEmitter3D(GraphicFactory factory,String SoundName)
        {
            System.Diagnostics.Debug.Assert(factory != null);
            System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(SoundName));

            this.internalName = SoundName;
            SoundEffect se = factory.GetAsset<SoundEffect>(SoundName);                        
            soundEngineInstance = se.CreateInstance();

            Name = se.Name;
            Duration = se.Duration;
            listener = new AudioListener();
            emiter = new AudioEmitter();
        }
        private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
        {
            // If we have no voice then nothing to do.
            if (_voice == null)
            {
                return;
            }

            // Convert from XNA Emitter to a SharpDX Emitter
            var e = ToDXEmitter(emitter);

            e.CurveDistanceScaler = SoundEffect.DistanceScale;
            e.DopplerScaler       = SoundEffect.DopplerScale;
            e.ChannelCount        = _effect._format.Channels;

            //stereo channel
            if (e.ChannelCount > 1)
            {
                e.ChannelRadius   = 0;
                e.ChannelAzimuths = _defaultChannelAzimuths;
            }

            // Convert from XNA Listener to a SharpDX Listener
            var l = ToDXListener(listener);

            // Number of channels in the sound being played.
            // Not actually sure if XNA supported 3D attenuation of sterio sounds, but X3DAudio does.
            var srcChannelCount = _effect._format.Channels;

            // Number of output channels.
            var dstChannelCount = SoundEffect.MasterVoice.VoiceDetails.InputChannelCount;

            // XNA supports distance attenuation and doppler.
            var dpsSettings = SoundEffect.Device3D.Calculate(l, e, CalculateFlags.Matrix | CalculateFlags.Doppler, srcChannelCount, dstChannelCount);

            // Apply Volume settings (from distance attenuation) ...
            _voice.SetOutputMatrix(SoundEffect.MasterVoice, srcChannelCount, dstChannelCount, dpsSettings.MatrixCoefficients, 0);

            // Apply Pitch settings (from doppler) ...
            _voice.SetFrequencyRatio(dpsSettings.DopplerFactor);
        }
Exemple #34
0
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            // We positional now
            if (!INTERNAL_positionalAudio)
            {
                // Do we need to convert a stereo buffer to mono?
                if (!isDynamic &&
                    INTERNAL_parentEffect.INTERNAL_buffer.Channels == 2 &&
                    INTERNAL_parentEffect.INTERNAL_monoBuffer == null)
                {
                    INTERNAL_parentEffect.INTERNAL_monoBuffer = AudioDevice.ALDevice.ConvertStereoToMono(
                        INTERNAL_parentEffect.INTERNAL_buffer
                        );
                }

                // K, we really positional now
                INTERNAL_positionalAudio = true;
            }

            // Set up our final position according to orientation of listener
            position = Vector3.Transform(
                emitter.Position - listener.Position,
                Matrix.CreateWorld(Vector3.Zero, listener.Forward, listener.Up)
                );

            // XACT doesn't do automated attenuation!
            if (INTERNAL_isXACTSource && position != Vector3.Zero)
            {
                position.Normalize();
            }

            // This can get called before Play()...
            if (INTERNAL_alSource != null)
            {
                // Finally.
                AudioDevice.ALDevice.SetSourcePosition(
                    INTERNAL_alSource,
                    position
                    );
            }
        }
Exemple #35
0
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }
            if (emitter == null)
            {
                throw new ArgumentNullException("emitter");
            }

            emitter.emitterData.ChannelCount        = bank.dspSettings.SrcChannelCount;
            emitter.emitterData.CurveDistanceScaler = float.MaxValue;
            FAudio.FACT3DCalculate(
                bank.engine.handle3D,
                ref listener.listenerData,
                ref emitter.emitterData,
                ref bank.dspSettings
                );
            FAudio.FACT3DApply(ref bank.dspSettings, handle);
        }
Exemple #36
0
        private Emitter ToDXEmitter(AudioEmitter emitter)
        {
            // Pulling out Vector properties for efficiency.
            var pos     = emitter.Position;
            var vel     = emitter.Velocity;
            var forward = emitter.Forward;
            var up      = emitter.Up;

            // From MSDN:
            //  X3DAudio uses a left-handed Cartesian coordinate system,
            //  with values on the x-axis increasing from left to right, on the y-axis from bottom to top,
            //  and on the z-axis from near to far.
            //  Azimuths are measured clockwise from a given reference direction.
            //
            // From MSDN:
            //  The XNA Framework uses a right-handed coordinate system,
            //  with the positive z-axis pointing toward the observer when the positive x-axis is pointing to the right,
            //  and the positive y-axis is pointing up.
            //
            // Programmer Notes:
            //  According to this description the z-axis (forward vector) is inverted between these two coordinate systems.
            //  Therefore, we need to negate the z component of any position/velocity values, and negate any forward vectors.

            forward *= -1.0f;
            pos.Z   *= -1.0f;
            vel.Z   *= -1.0f;

            if (_dxEmitter == null)
            {
                _dxEmitter = new Emitter();
            }

            _dxEmitter.Position      = new RawVector3(pos.X, pos.Y, pos.Z);
            _dxEmitter.Velocity      = new RawVector3(vel.X, vel.Y, vel.Z);
            _dxEmitter.OrientFront   = new RawVector3(forward.X, forward.Y, forward.Z);
            _dxEmitter.OrientTop     = new RawVector3(up.X, up.Y, up.Z);
            _dxEmitter.DopplerScaler = emitter.DopplerScale;
            return(_dxEmitter);
        }
Exemple #37
0
        public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
        {
            if (INTERNAL_alSource == -1)
            {
                return;
            }

            // Get AL's listener position
            float x, y, z;

            AL.GetListener(ALListener3f.Position, out x, out y, out z);

            for (int i = 0; i < listeners.Length; i++)
            {
                AudioListener listener = listeners[i];

                // Get the emitter offset from origin
                Vector3 posOffset = emitter.Position - listener.Position;

                // Set up orientation matrix
                Matrix orientation = Matrix.CreateWorld(Vector3.Zero, listener.Forward, listener.Up);

                // Set up our final position and velocity according to orientation of listener
                position = new Vector3(x + posOffset.X, y + posOffset.Y, z + posOffset.Z);
                position = Vector3.Transform(position, orientation);
                velocity = emitter.Velocity;
                velocity = Vector3.Transform(velocity, orientation);

                // FIXME: This is totally arbitrary. I dunno the exact ratio here.
                position /= 255.0f;
                velocity /= 255.0f;

                // Set the position based on relative positon
                AL.Source(INTERNAL_alSource, ALSource3f.Position, position.X, position.Y, position.Z);
                AL.Source(INTERNAL_alSource, ALSource3f.Velocity, velocity.X, velocity.Y, velocity.Z);
            }

            INTERNAL_positionalAudio = true;
        }
Exemple #38
0
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            if ((IsPlaying || IsStopping) && !INTERNAL_isPositional)
            {
                throw new InvalidOperationException("Apply3D call after Play!");
            }
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }
            if (emitter == null)
            {
                throw new ArgumentNullException("emitter");
            }
            INTERNAL_listener = listener;
            INTERNAL_emitter  = emitter;

            // Set Apply3D-related Variables
            Vector3 emitterToListener = listener.Position - emitter.Position;
            float   distance          = emitterToListener.Length();

            SetVariable("Distance", distance);
            SetVariable(
                "DopplerPitchScalar",
                INTERNAL_calculateDoppler(emitterToListener, distance)
                );
            SetVariable(
                "OrientationAngle",
                MathHelper.ToDegrees((float)Math.Acos(
                                         Vector3.Dot(
                                             emitterToListener / distance, // Direction...
                                             listener.Forward
                                             )                             // Slope...
                                         ))                                // Angle!
                );

            INTERNAL_isPositional = true;
        }
Exemple #39
0
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }
            if (emitter == null)
            {
                throw new ArgumentNullException("emitter");
            }

            is3D = true;
            SoundEffect.FAudioContext dev = SoundEffect.Device();
            emitter.emitterData.CurveDistanceScaler = dev.CurveDistanceScaler;
            emitter.emitterData.ChannelCount        = dspSettings.SrcChannelCount;
            FAudio.F3DAudioCalculate(
                dev.Handle3D,
                ref listener.listenerData,
                ref emitter.emitterData,
                (
                    FAudio.F3DAUDIO_CALCULATE_MATRIX |
                    FAudio.F3DAUDIO_CALCULATE_DOPPLER
                ),
                ref dspSettings
                );
            if (handle != IntPtr.Zero)
            {
                UpdatePitch();
                FAudio.FAudioVoice_SetOutputMatrix(
                    handle,
                    SoundEffect.Device().MasterVoice,
                    dspSettings.SrcChannelCount,
                    dspSettings.DstChannelCount,
                    dspSettings.pMatrixCoefficients,
                    0
                    );
            }
        }
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            if (INTERNAL_alSource == -1)
            {
                return;
            }

            // Set up orientation matrix
            Matrix orientation = Matrix.CreateWorld(Vector3.Zero, listener.Forward, listener.Up);

            // Set up our final position according to orientation of listener
            position = Vector3.Transform(emitter.Position - listener.Position, orientation);
            if (position != Vector3.Zero)
            {
                position.Normalize();
            }

            // Set the position based on relative positon
            AL.Source(INTERNAL_alSource, ALSource3f.Position, position.X, position.Y, position.Z);

            // We positional now
            INTERNAL_positionalAudio = true;
        }
Exemple #41
0
        private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
        {
            // get AL's listener position
            float x, y, z;

            AL.GetListener(ALListener3f.Position, out x, out y, out z);

            // get the emitter offset from origin
            Vector3 posOffset = emitter.Position - listener.Position;
            // set up orientation matrix
            Matrix orientation = Matrix.CreateWorld(Vector3.Zero, listener.Forward, listener.Up);
            // set up our final position and velocity according to orientation of listener
            Vector3 finalPos = new Vector3(x + posOffset.X, y + posOffset.Y, z + posOffset.Z);

            finalPos = Vector3.Transform(finalPos, orientation);
            Vector3 finalVel = emitter.Velocity;

            finalVel = Vector3.Transform(finalVel, orientation);

            // set the position based on relative positon
            AL.Source(sourceId, ALSource3f.Position, finalPos.X, finalPos.Y, finalPos.Z);
            AL.Source(sourceId, ALSource3f.Velocity, finalVel.X, finalVel.Y, finalVel.Z);
        }
 private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
 {
     // Looks like a no-op on PSM?
 }
Exemple #43
0
 public abstract void PlayPositional(AudioListener listener, AudioEmitter emitter);
 public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
 {
     throw new NotSupportedException("OpenAL can only make use of one listener.");
 }
Exemple #45
0
 public abstract void UpdatePosition(AudioListener listener, AudioEmitter emitter);
 /// <summary>Applies 3D positioning to the SoundEffectInstance using a single listener.</summary>
 /// <param name="listener">Data about the listener.</param>
 /// <param name="emitter">Data about the source of emission.</param>
 public void Apply3D(AudioListener listener, AudioEmitter emitter)
 {
     PlatformApply3D(listener, emitter);
 }
 private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
 {
 }
 private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
 {
     // TODO: Read up the rules for this
     // _pannedNode.setPosition _pannedNode.setVelocity _pannedNode.setOrientation
 }
Exemple #49
0
 public override void PlayPositional(AudioListener listener, AudioEmitter emitter)
 {
 }
Exemple #50
0
 private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
 {
     // Appears to be a no-op on Android?
 }
 public void Apply3D(AudioListener listener, AudioEmitter emitter)
 {
     Apply3D(new AudioListener[] { listener }, emitter);
 }
Exemple #52
0
 public void Apply3D(AudioListener listener, AudioEmitter emitter)
 {
 }
Exemple #53
0
 public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
 {
     throw new NotSupportedException("Only one listener is supported.");
 }
Exemple #54
0
 // Needed for positional audio
 internal void PlayPositional(AudioListener listener, AudioEmitter emitter)
 {
     // TODO: run events
     events[0].PlayPositional(listener, emitter);
 }
Exemple #55
0
 internal void UpdatePosition(AudioListener listener, AudioEmitter emitter)
 {
     // TODO: run events
     events[0].UpdatePosition(listener, emitter);
 }
Exemple #56
0
 public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
 {
     throw new NotImplementedException();
 }
Exemple #57
0
 public void PlayCue(string name, AudioListener listener, AudioEmitter emitter)
 {
     throw new NotImplementedException();
 }
Exemple #58
0
 public override void Apply3D(AudioListener listener, AudioEmitter emitter)
 {
 }
 private void PlatformApply3D(AudioListener listener, AudioEmitter emitter)
 {
     throw new NotImplementedException();
 }
Exemple #60
0
 public override void UpdatePosition(AudioListener listener, AudioEmitter emitter)
 {
 }