public void MakeDualityTarget() { if (DualityApp.ExecContext == DualityApp.ExecutionContext.Terminated) { return; } activeCamView = this; DualityApp.WindowSize = this.activeState.RenderedImageSize; DualityApp.Mouse.Source = this; DualityApp.Keyboard.Source = this; // If we have a CamView-local listener that is active, use that one. // Note: The GameViewCamViewState deactivates its own camera, since it uses the // regular Scene rendering setup, rather than providing its own. SoundListener localListener = this.CameraObj.GetComponent <SoundListener>(); if (localListener != null && localListener.Active) { localListener.MakeCurrent(); } // If we don't have a local listener, use the regular one from the current scene else { SoundListener sceneListener = Scene.Current.FindComponent <SoundListener>(); if (sceneListener != null) { sceneListener.MakeCurrent(); } } }
/// <summary> /// Ordinary constructor. /// </summary> /// <param name="game">The main CanyonShooter game object</param> public Ghost(ICanyonShooterGame game) : base(game, "PlayerElcode") { EnabledChanged += (Player2_EnabledChanged); // Set player profile values SetModel(game.GameStates.Profil.CurrentProfil.Model); BankingFactor = game.GameStates.Profil.CurrentProfil.Banking; DriftFactor = game.GameStates.Profil.CurrentProfil.Drift; TranslationGap = game.GameStates.Profil.CurrentProfil.Translation; RollFactor = game.GameStates.Profil.CurrentProfil.Rolling; MaxDecay = game.GameStates.Profil.CurrentProfil.Brake; AutoLevel = game.GameStates.Profil.CurrentProfil.AutoLevel; Health = game.GameStates.Profil.CurrentProfil.Health; MinSpeed = game.GameStates.Profil.CurrentProfil.Speed; Shield = game.GameStates.Profil.CurrentProfil.Shield; SpeedGap = game.GameStates.Profil.CurrentProfil.Acceleration; // Initialize player environment LocalPosition = new Vector3(0, 0, 0); ConnectedToXpa = true; ContactGroup = ContactGroup.None; InfluencedByGravity = false; this.game = game; //SetCamera(game); // Set sound listener for 3D sound listener = new SoundListener(game); game.Sounds.SoundListener = listener; }
public void StartListen() { if (soundListener == null) { soundListener = new SoundListener(Program.SoundCaptureDevice); soundListener.NotifyPointsInSecond = NotifyPerSecond; soundListener.Listen += new SoundListener.ListenHandler(soundListener_Listen); soundListener.StartListen(); } }
public void MetronomeTest() { MetronomeMachine m = new MetronomeMachine(10, 50);//se crea instancia,(contador, duracion). TextListener t = new TextListener();// se crea una instancia, esta escucha a metronememachine e imprime en pantalla la duracion y frecuencia. t.Subscribe(m);//El este metodo recibe un MetronomeMachine y a éste, al evento que se encuentra en el objeto, le asigna una variable, un metodo que hace imprime en pantalla la duracion y frecuencia. SoundListener l = new SoundListener();//se crea una instancia. l.Subscribe(m);//este metodo le asigna recibe un metronomemachine, busca su evento y le suscribe una variable que a su vez es un metodo que emite un beep cada vez que se displara el evento en la clase metronomemachine. //m.Tick -= l.EmitSound; remover handler m.Start();//dispara el evento. }
/// <summary> /// Setup the test environment. /// </summary> /// <param name="game"></param> public void SetUp(ICanyonShooterGame game) { // Create sound system sounds = new SoundSystem(game); // Create the listener listener = new SoundListener(game); // Set global volumes sounds.EffectVolume = 0.8f; // The listener "player" sounds.SoundListener = listener; }
public void StopListen() { if (soundListener != null) { try { soundListener.StopListen(); soundListener.Listen -= new SoundListener.ListenHandler(soundListener_Listen); soundListener = null; } catch (Exception ex) { MessageBox.Show("Error in stopping device,\nError Message: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
void Start() { traversalCenter = transform.position; traversalReturn = transform.position; anim = GetComponent <Animator>(); MovementSight ms = GetComponentInChildren <MovementSight>(); if (ms) { ms.onMovementSightTrigger += OnMovementSightEnter; } SoundListener sl = GetComponent <SoundListener>(); if (sl) { sl.onListenSound += OnListenSound; } }
private void UpdateListener() { if (this.soundListener != null && (this.soundListener.Disposed || !this.soundListener.Active)) { this.soundListener = null; } // If no listener is defined, search one if (this.soundListener == null) { this.soundListener = Scene.Current.FindComponent <SoundListener>(); } DualityApp.AudioBackend.UpdateListener( this.ListenerPos * AudioUnit.LengthToPhysical, this.ListenerVel * AudioUnit.VelocityToPhysical, this.ListenerAngle * AudioUnit.AngleToPhysical, this.mute); }
internal static void UpdateDependencies() { #if !WINDOWS_PHONE && !MONOGAME && !SILVERLIGHT SoundListener.UpdateDependencies(TimeManager.CurrentTime); SoundListener.UpdateAudio(); for (int i = 0; i < PositionedSounds.Count; i++) { PositionedSounds[i].UpdateDependencies(TimeManager.CurrentTime); PositionedSounds[i].UpdateAudio(); } if (mXnaAudioEngine != null) { mXnaAudioEngine.Update(); } #endif mSoundsPlayedThisFrame.Clear(); }
protected override void Initialize() { base.Initialize(); cam = RenderManager.ActiveCamera2D.Transform; emitter = new SoundEmitter() { DistanceScale = 5 }; listener = new SoundListener(); children = new List <Animation2D>(); foreach (Entity ent in Owner.ChildEntities) { Animation2D a = ent.FindComponent <Animation2D>(); if (a != null) { children.Add(a); } } }
// Update is called once per frame void Update() { if (!move.isPaused()) { foreach (GameObject target in Targets) { SoundListener lis = target.GetComponentInChildren <SoundListener>(); if (lis) { Vector3 pos = target.transform.position; pos.z = 0.0f; Astar.ComputePath(pos, circle.radius, true); float dis = Astar.GetPathDistance(); if (dis <= circle.radius) { lis.UpdateWaypoints(Astar.GetInvertedWaypoints()); } } } } }
public Player(ICanyonShooterGame game, int PlayerID) : base(game, "player" + PlayerID) { // TODO: Construct any child components here this.game = game; playerID = PlayerID; camera = new PerspectiveCamera(game); // Sound Listener by M.R. Set SoundSystem listener. listener = new SoundListener(game); game.Sounds.SoundListener = listener; // ----------------------------------------------- SetModel(game.GameStates.Profil.CurrentProfil.Model); //SetModel("F35eger"); //SetModel("Starfighter"); //SetModel("Fighter"); //SetModel("Drone"); //SetModel("Car"); //SetModel("G35hopper"); LocalPosition = /*this.LocalPosition + */ new Vector3(0, 0, 0); //LocalScale = new Vector3(0.15f, 0.4f, 0.6f); //LocalScale = new Vector3(0.5f, 0.5f, 0.5f); //Scale(new Vector3(0.5f, 0.5f, 0.5f)); ConnectedToXpa = true; ContactGroup = ContactGroup.Player; InfluencedByGravity = false; //Velocity = new Vector3(0, 0, -20.0f); //this.Solid.AddShape(t11); //this.Solid.AddShape(t12); //this.Solid.UserData = this; /* * SphereShapeData t11 = new SphereShapeData(); * t11.Radius = 20.0f; * t11.Material.Hardness = 0.2f; * t11.Material.Bounciness = 0.6f; * t11.Material.Friction = 1.0f; * t11.Material.Density = 0.4f; * t11.Offset.Translation = new Vector3(5, 4, 0); * SphereShapeData t12 = new SphereShapeData(); * t12.Radius = 20.0f; * t12.Material.Hardness = 0.2f; * t12.Material.Bounciness = 0.6f; * t12.Material.Friction = 1.0f; * t12.Material.Density = 0.4f; * t12.Offset.Translation = new Vector3(-5, 0, 0); * * obj = new GameObject[2]; * * obj[0] = new GameObject(this, "0"); * obj[0].SetModel("Drone"); * obj[0].LocalPosition = obj[0].LocalPosition + new Vector3(0, 0, -50); * obj[0].ConnectedToXpa = true; * obj[0].Solid.AddShape(t11); * obj[0].Solid.AddShape(t12); * obj[0].Solid.UserData = obj[0]; * obj[1] = new GameObject(this, "1"); * Components.Add(obj[1]); * obj[1].SetModel("Roket"); * obj[1].LocalPosition = obj[1].LocalPosition + new Vector3(-10, 0, 0); * //obj[1].Solid.UserData = obj[1]; * obj[1].Parent = obj[0]; * * Components.Add(obj[0]); * * Solid platte = physics.CreateSolid(); * PlaneShapeData planeData = new PlaneShapeData(new Plane(new Vector3(0, 1, 0), -30)); * planeData.Material.Hardness = 1f; * planeData.Material.Bounciness = 0.9f; * planeData.Material.Friction = 1.0f; * planeData.Material.Density = 0.8f; * platte.Tag = "Bodenplatte"; * platte.AddShape(planeData); * platte.Static = true; */ }
void ICmpUpdatable.OnUpdate() { Transform transform = this.GameObj.Transform; RigidBody body = this.GameObj.GetComponent <RigidBody>(); ShipBlueprint blueprint = this.blueprint.Res; // Heal when damaged if (this.hitpoints < 1.0f) { this.hitpoints = MathF.Clamp(this.hitpoints + blueprint.HealRate * Time.SPFMult * Time.TimeMult / blueprint.MaxHitpoints, 0.0f, 1.0f); } // Apply force according to the desired thrust Vector2 actualVelocity = body.LinearVelocity; Vector2 targetVelocity = this.targetThrust * blueprint.MaxSpeed; Vector2 velocityDiff = (targetVelocity - actualVelocity); float sameDirectionFactor = Vector2.Dot( velocityDiff / MathF.Max(0.001f, velocityDiff.Length), this.targetThrust / MathF.Max(0.001f, this.targetThrust.Length)); Vector2 thrusterActivity = this.targetThrust.Length * MathF.Max(sameDirectionFactor, 0.0f) * velocityDiff / MathF.Max(velocityDiff.Length, 1.0f); if (thrusterActivity.Length > 0.00001f) // Don't wake physics without actually doing work { body.ApplyWorldForce(thrusterActivity * blueprint.ThrusterPower); } // Turn to the desired fire angle if (this.targetAngleRatio > 0.0f) { float shortestTurnDirection = MathF.TurnDir(transform.Angle, this.targetAngle); float shortestTurnLength = MathF.CircularDist(transform.Angle, this.targetAngle); float turnDirection; float turnLength; if (MathF.Abs(body.AngularVelocity) > blueprint.MaxTurnSpeed * 0.25f) { turnDirection = MathF.Sign(body.AngularVelocity); turnLength = (turnDirection == shortestTurnDirection) ? shortestTurnLength : (MathF.RadAngle360 - shortestTurnLength); } else { turnDirection = shortestTurnDirection; turnLength = shortestTurnLength; } float turnSpeedRatio = MathF.Min(turnLength * 0.25f, MathF.RadAngle30) / MathF.RadAngle30; float turnVelocity = turnSpeedRatio * turnDirection * blueprint.MaxTurnSpeed * this.targetAngleRatio; float angularVelocityChange = (turnVelocity - body.AngularVelocity) * blueprint.TurnPower; if (MathF.Abs(angularVelocityChange) > 0.0000001f) // Don't wake physics without actually doing work { body.AngularVelocity += angularVelocityChange * Time.TimeMult; } } // Weapon cooldown this.weaponTimer = MathF.Max(0.0f, this.weaponTimer - Time.MsPFMult * Time.TimeMult); // Play the owners special flight sound, when available if (this.owner != null && this.owner.FlightLoop != null) { SoundListener listener = Scene.Current.FindComponent <SoundListener>(); Vector3 listenerPos = listener.GameObj.Transform.Pos; // Determine the target panning manually, because we don't want a true 3D sound here (doppler, falloff, ...) float targetPanning; if (listenerPos.Xy == transform.Pos.Xy || Player.AlivePlayers.Count() <= 1) { targetPanning = 0.0f; } else { targetPanning = -Vector2.Dot(Vector2.UnitX, (listenerPos - transform.Pos).Xy.Normalized); } // Determine the target volume float targetVolume = MathF.Clamp(this.targetThrust.Length, 0.0f, 1.0f); // Clean up disposed flight loop if (this.flightLoop != null && this.flightLoop.Disposed) { this.flightLoop = null; } // Start the flight loop when requested if (targetVolume > 0.0f && this.flightLoop == null) { if ((int)Time.MainTimer.TotalMilliseconds % 2976 <= (int)Time.MsPFMult) { this.flightLoop = DualityApp.Sound.PlaySound(this.owner.FlightLoop); this.flightLoop.Looped = true; } } // Configure existing flight loop if (this.flightLoop != null) { this.flightLoop.Volume += (targetVolume - this.flightLoop.Volume) * 0.05f * Time.TimeMult; this.flightLoop.Panning += (targetPanning - this.flightLoop.Panning) * 0.05f * Time.TimeMult; } } // Display the damage effect when damaged if (this.hitpoints < 0.85f && blueprint.DamageEffect != null) { // Create a new damage effect instance, if not present yet if (this.damageEffect == null) { GameObject damageObj = blueprint.DamageEffect.Res.Instantiate(transform.Pos); damageObj.Parent = this.GameObj; this.damageEffect = damageObj.GetComponent <ParticleEffect>(); if (this.damageEffect == null) { throw new NullReferenceException(); } } // Configure the damage effect foreach (ParticleEmitter emitter in this.damageEffect.Emitters) { if (emitter == null) { continue; } emitter.BurstDelay = new Range(50.0f + this.hitpoints * 50.0f, 100.0f + this.hitpoints * 300.0f); if (this.owner != null) { ColorHsva targetColor = this.owner.Color.ToHsva(); emitter.MinColor = new ColorHsva(targetColor.H, targetColor.S, emitter.MinColor.V, emitter.MinColor.A); emitter.MaxColor = new ColorHsva(targetColor.H, targetColor.S, emitter.MaxColor.V, emitter.MaxColor.A); } } } // Get rid of existing damage effects, if no longer needed else if (this.damageEffect != null) { // Stop emitting and dispose when empty foreach (ParticleEmitter emitter in this.damageEffect.Emitters) { if (emitter == null) { continue; } emitter.BurstDelay = float.MaxValue; } this.damageEffect.DisposeWhenEmpty = true; this.damageEffect = null; } }
private void buttonStop_Click(object sender, EventArgs e) { if (soundListener != null) { soundListener.StopListen(); soundListener.Listen -= new SoundListener.ListenHandler(SoundListener_Listen); soundListener = null; } endTime = CurrentTime; firstTimeListen = true; windowsMediaPlayer.Ctlcontrols.stop(); timerRefresh.Stop(); TranslateBuffer(); buttonOK.Enabled = true; buttonCancel.Enabled = true; buttonPlay.Enabled = true; buttonListen.Enabled = false; buttonStop.Enabled = false; numericUpDownSpeed.Enabled = true; }
private void buttonPlay_Click(object sender, EventArgs e) { if (soundListener == null) { soundListener = new SoundListener(Program.SoundCaptureDevice); soundListener.NotifyPointsInSecond = notifyPerSecond; soundListener.Listen += new SoundListener.ListenHandler(SoundListener_Listen); } ucNoteGraph.Clear(); windowsMediaPlayer.Ctlcontrols.currentPosition = (double)trackBarTimeline.Value / trackBarTimeline.Maximum * windowsMediaPlayer.Ctlcontrols.currentItem.duration; timerRefresh.Start(); windowsMediaPlayer.Ctlcontrols.play(); buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonPlay.Enabled = false; buttonListen.Enabled = true; buttonStop.Enabled = true; numericUpDownSpeed.Enabled = false; }
/// <summary> /// The program Loop: CTRL+C to stop it properly /// </summary> /// <param name="characteristic"></param> static void Loop(GattCharacteristic characteristic) { SoundListener soundListener = new SoundListener(); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; keepRunning = false; }; LogHelper.Ok("Program running. Press CTRL+C to stop"); #region variables (prevents reallocation) // Rectangle in the middle of the screen Rectangle rect = new Rectangle(1920 / 4, 1080 / 4, 1920 / 4 * 2, 1080 / 4 * 2); String colorCode = ""; Color color; int soundLevel; String brightness; String textToWrite; #endregion #region configuration bool sensitiveToBass = Configuration.audioSensibility == Configuration.AudioSensibility.BASS_LEVEL; bool dynamicSmoothing = Configuration.smoothingMode == Configuration.SmoothingMode.DYNAMIC; bool valueSmoothing = Configuration.smoothingMode == Configuration.SmoothingMode.VALUE; double smoothness = Configuration.smoothingValue; #endregion int current = -1; // Smooth brightness variation int cpt = 0; // Used to know when to read the screen's pixels soundListener.ListenForBass(sensitiveToBass); while (keepRunning) { if (Configuration.audioSensibility != Configuration.AudioSensibility.NONE) { soundLevel = (int)((sensitiveToBass ? soundListener.GetBassLevel() : soundListener.GetSoundLevel()) * 100f); // Between 0.0f and 100.0f if (current == -1) { current = soundLevel; } if (dynamicSmoothing) { current = (current + soundLevel) / 2; } else if (current < soundLevel && valueSmoothing && smoothness > 0) { current = Math.Min((int)(current + 100 / smoothness), soundLevel); } else if (smoothness > 0) { current = Math.Max((int)(current - 100 / smoothness), soundLevel); } else { current = soundLevel; } // Format: 7e 00 01 brightness 00 00 00 00 ef // brightness: 0x00-0x64 (0-100) // So we need to convert the soundLevel to hex so that 100.0f is 0x64 and 0.0f is 0x00 brightness = (current).ToString("X"); textToWrite = "7e0001" + brightness + "00000000ef"; _ = BleUtility.WriteHex(textToWrite, characteristic); // we don't want it to be blocking } if (Configuration.colorSensibility != Configuration.ColorSensibility.NONE) { // We don't want to analyze pixels as fast as we check for the sound level cpt++; if (cpt == 10) { new Thread(() => { color = ScreenUtils.CalculateAverageScreenColorAt(rect); if (color.GetBrightness() >= 0.85f) { // white colorCode = "86"; } else if (color.GetHue() < 25 || color.GetHue() >= 330) { // red colorCode = "80"; } else if (color.GetHue() >= 25 && color.GetHue() < 65) { // yellow colorCode = "84"; } else if (color.GetHue() >= 65 && color.GetHue() < 180) { // green colorCode = "82"; } else if (color.GetHue() >= 180 && color.GetHue() < 200) { // cyan colorCode = "83"; } else if (color.GetHue() >= 200 && color.GetHue() < 250) { // blue colorCode = "81"; } else if (color.GetHue() >= 250 && color.GetHue() < 330) { // magenta colorCode = "85"; } _ = BleUtility.WriteHex("7e0003" + colorCode + "03000000ef", characteristic); }).Start(); cpt = 0; } } Thread.Sleep(50); } soundListener.Dispose(); }
public void RemoveListener(SoundListener listener) { listeners.Remove(listener); }
public void AddListener(SoundListener listener) { listeners.Add(listener); }