Advertisement
2019PASTEBIN2019

Untitled

Jul 4th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.69 KB | None | 0 0
  1. //------------------------------------------------------------------------------
  2. // <copyright file="MainWindow.xaml.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. //------------------------------------------------------------------------------
  6.  
  7. // This module contains code to do Kinect NUI initialization,
  8. // processing, displaying players on screen, and sending updated player
  9. // positions to the game portion for hit testing.
  10.  
  11. namespace ShapeGame
  12. {
  13. using System;
  14. using System.Collections.Generic;
  15. using System.ComponentModel;
  16. using System.Linq;
  17. using System.Media;
  18. using System.Runtime.InteropServices;
  19. using System.Threading;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Data;
  23. using System.Windows.Threading;
  24. using Microsoft.Kinect;
  25. using Microsoft.Kinect.Toolkit;
  26. using Microsoft.Samples.Kinect.WpfViewers;
  27. using ShapeGame.Speech;
  28. using ShapeGame.Utils;
  29.  
  30. /// <summary>
  31. /// Interaction logic for MainWindow.xaml
  32. /// </summary>
  33. ///
  34. public partial class MainWindow : Window
  35. {
  36. public static readonly DependencyProperty KinectSensorManagerProperty =
  37. DependencyProperty.Register(
  38. "KinectSensorManager",
  39. typeof(KinectSensorManager),
  40. typeof(MainWindow),
  41. new PropertyMetadata(null));
  42.  
  43. #region Private State
  44. private const int TimerResolution = 2; // ms
  45. private const int NumIntraFrames = 3;
  46. private const int MaxShapes = 80;
  47. private const double MaxFramerate = 70;
  48. private const double MinFramerate = 15;
  49. private const double MinShapeSize = 12;
  50. private const double MaxShapeSize = 90;
  51. private const double DefaultDropRate = 2.5;
  52. private const double DefaultDropSize = 32.0;
  53. private const double DefaultDropGravity = 1.0;
  54.  
  55. private readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
  56. private readonly SoundPlayer popSound = new SoundPlayer();
  57. private readonly SoundPlayer hitSound = new SoundPlayer();
  58. private readonly SoundPlayer squeezeSound = new SoundPlayer();
  59. private readonly KinectSensorChooser sensorChooser = new KinectSensorChooser();
  60.  
  61. private double dropRate = DefaultDropRate;
  62. private double dropSize = DefaultDropSize;
  63. private double dropGravity = DefaultDropGravity;
  64. private DateTime lastFrameDrawn = DateTime.MinValue;
  65. private DateTime predNextFrame = DateTime.MinValue;
  66. private double actualFrameTime;
  67.  
  68.  
  69.  
  70. private Skeleton[] skeletonData;
  71.  
  72. // Player(s) placement in scene (z collapsed):
  73. private Rect playerBounds;
  74. private Rect screenRect;
  75.  
  76. private double targetFramerate = MaxFramerate;
  77. private int frameCount;
  78. private bool runningGameThread;
  79. private FallingThings myFallingThings;
  80. private int playersAlive;
  81. //$$$$$$$$$$$$$$$$
  82. int numOfPlayers = 0;
  83.  
  84. //$$$$$$$$$$$$$$$
  85.  
  86.  
  87. private SpeechRecognizer mySpeechRecognizer;
  88. #endregion Private State
  89.  
  90. #region ctor + Window Events
  91.  
  92. public MainWindow()
  93. {
  94.  
  95.  
  96.  
  97. this.KinectSensorManager = new KinectSensorManager();
  98. this.KinectSensorManager.KinectSensorChanged += this.KinectSensorChanged;
  99. this.DataContext = this.KinectSensorManager;
  100.  
  101. InitializeComponent();
  102.  
  103. this.SensorChooserUI.KinectSensorChooser = sensorChooser;
  104. sensorChooser.Start();
  105.  
  106. // Bind the KinectSensor from the sensorChooser to the KinectSensor on the KinectSensorManager
  107. var kinectSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
  108. BindingOperations.SetBinding(this.KinectSensorManager, KinectSensorManager.KinectSensorProperty, kinectSensorBinding);
  109.  
  110. this.RestoreWindowState();
  111. }
  112.  
  113. public KinectSensorManager KinectSensorManager
  114. {
  115. get { return (KinectSensorManager)GetValue(KinectSensorManagerProperty); }
  116. set { SetValue(KinectSensorManagerProperty, value); }
  117. }
  118.  
  119. // Since the timer resolution defaults to about 10ms precisely, we need to
  120. // increase the resolution to get framerates above between 50fps with any
  121. // consistency.
  122. [DllImport("Winmm.dll", EntryPoint = "timeBeginPeriod")]
  123. private static extern int TimeBeginPeriod(uint period);
  124.  
  125. private void RestoreWindowState()
  126. {
  127. // Restore window state to that last used
  128. Rect bounds = Properties.Settings.Default.PrevWinPosition;
  129. if (bounds.Right != bounds.Left)
  130. {
  131. this.Top = bounds.Top;
  132. this.Left = bounds.Left;
  133. this.Height = bounds.Height;
  134. this.Width = bounds.Width;
  135. }
  136.  
  137. this.WindowState = (WindowState)Properties.Settings.Default.WindowState;
  138. }
  139.  
  140. private void WindowLoaded(object sender, EventArgs e)
  141. {
  142. playfield.ClipToBounds = true;
  143.  
  144. this.myFallingThings = new FallingThings(MaxShapes, this.targetFramerate, NumIntraFrames);
  145.  
  146. this.UpdatePlayfieldSize();
  147.  
  148. this.myFallingThings.SetGravity(this.dropGravity);
  149. this.myFallingThings.SetDropRate(this.dropRate);
  150. this.myFallingThings.SetSize(this.dropSize);
  151. this.myFallingThings.SetPolies(PolyType.All);
  152. this.myFallingThings.SetGameMode(GameMode.Off);
  153.  
  154. this.popSound.Stream = Properties.Resources.Pop_5;
  155. this.hitSound.Stream = Properties.Resources.Hit_2;
  156. this.squeezeSound.Stream = Properties.Resources.Squeeze;
  157.  
  158. this.popSound.Play();
  159.  
  160. TimeBeginPeriod(TimerResolution);
  161. var myGameThread = new Thread(this.GameThread);
  162. myGameThread.SetApartmentState(ApartmentState.STA);
  163. myGameThread.Start();
  164.  
  165. FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Shapes!");
  166. }
  167.  
  168. private void WindowClosing(object sender, CancelEventArgs e)
  169. {
  170. sensorChooser.Stop();
  171.  
  172. this.runningGameThread = false;
  173. Properties.Settings.Default.PrevWinPosition = this.RestoreBounds;
  174. Properties.Settings.Default.WindowState = (int)this.WindowState;
  175. Properties.Settings.Default.Save();
  176. }
  177.  
  178. private void WindowClosed(object sender, EventArgs e)
  179. {
  180. this.KinectSensorManager.KinectSensor = null;
  181. }
  182.  
  183. #endregion ctor + Window Events
  184.  
  185. #region Kinect discovery + setup
  186.  
  187. private void KinectSensorChanged(object sender, KinectSensorManagerEventArgs<KinectSensor> args)
  188. {
  189. if (null != args.OldValue)
  190. {
  191. this.UninitializeKinectServices(args.OldValue);
  192. }
  193.  
  194. // Only enable this checkbox if we have a sensor
  195. enableAec.IsEnabled = null != args.NewValue;
  196.  
  197. if (null != args.NewValue)
  198. {
  199. this.InitializeKinectServices(this.KinectSensorManager, args.NewValue);
  200. }
  201. }
  202.  
  203. // Kinect enabled apps should customize which Kinect services it initializes here.
  204. private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor)
  205. {
  206. // Application should enable all streams first.
  207. kinectSensorManager.ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;
  208. kinectSensorManager.ColorStreamEnabled = true;
  209.  
  210. sensor.SkeletonFrameReady += this.SkeletonsReady;
  211. kinectSensorManager.TransformSmoothParameters = new TransformSmoothParameters
  212. {
  213. Smoothing = 0.5f,
  214. Correction = 0.5f,
  215. Prediction = 0.5f,
  216. JitterRadius = 0.05f,
  217. MaxDeviationRadius = 0.04f
  218. };
  219. kinectSensorManager.SkeletonStreamEnabled = true;
  220. kinectSensorManager.KinectSensorEnabled = true;
  221.  
  222. if (!kinectSensorManager.KinectSensorAppConflict)
  223. {
  224. // Start speech recognizer after KinectSensor started successfully.
  225. this.mySpeechRecognizer = SpeechRecognizer.Create();
  226.  
  227. if (null != this.mySpeechRecognizer)
  228. {
  229. this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething;
  230. this.mySpeechRecognizer.Start(sensor.AudioSource);
  231. }
  232.  
  233. enableAec.Visibility = Visibility.Visible;
  234. this.UpdateEchoCancellation(this.enableAec);
  235. }
  236. }
  237.  
  238. // Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here.
  239. private void UninitializeKinectServices(KinectSensor sensor)
  240. {
  241. sensor.SkeletonFrameReady -= this.SkeletonsReady;
  242.  
  243. if (null != this.mySpeechRecognizer)
  244. {
  245. this.mySpeechRecognizer.Stop();
  246. this.mySpeechRecognizer.SaidSomething -= this.RecognizerSaidSomething;
  247. this.mySpeechRecognizer.Dispose();
  248. this.mySpeechRecognizer = null;
  249. }
  250.  
  251. enableAec.Visibility = Visibility.Collapsed;
  252. }
  253.  
  254. #endregion Kinect discovery + setup
  255.  
  256. #region Kinect Skeleton processing
  257. private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e)
  258. {
  259. using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
  260. {
  261. if (skeletonFrame != null)
  262. {
  263. int skeletonSlot = 0;
  264.  
  265. if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
  266. {
  267. this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
  268. }
  269.  
  270. skeletonFrame.CopySkeletonDataTo(this.skeletonData);
  271.  
  272.  
  273. //$$$$$$$$$$$$$
  274. //if(skeletonData.Length==0)
  275. //{
  276. // ;
  277. //}
  278. //else
  279. //{
  280. // ;
  281. //}
  282. //$$$$$$$$$$$$$
  283.  
  284.  
  285. //$$$$$$$$$$int l = skeletonData.Length;
  286.  
  287. this.numOfPlayers = 0;
  288. foreach (Skeleton skeleton in this.skeletonData)
  289. {
  290.  
  291. if (SkeletonTrackingState.Tracked == skeleton.TrackingState)
  292. {
  293. Player player;
  294. if (this.players.ContainsKey(skeletonSlot))
  295. {
  296. player = this.players[skeletonSlot];
  297. }
  298. else
  299. {
  300. if (this.numOfPlayers==0)
  301. {
  302. var x = "s";
  303. player = new Player(skeletonSlot);
  304. player.SetBounds(this.playerBounds);
  305. this.players.Add(skeletonSlot, player);
  306. string s = "add" + skeleton.ToString() + "," + player.GetId();
  307.  
  308. this.numOfPlayers++;
  309. }
  310.  
  311.  
  312. }
  313.  
  314. player.LastUpdated = DateTime.Now;
  315.  
  316. // Update player's bone and joint positions
  317. if (skeleton.Joints.Count > 0)
  318. {
  319. player.IsAlive = true;
  320.  
  321. // Head, hands, feet (hit testing happens in order here)
  322. player.UpdateJointPosition(skeleton.Joints, JointType.Head);
  323. player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft);
  324. player.UpdateJointPosition(skeleton.Joints, JointType.HandRight);
  325. player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft);
  326. player.UpdateJointPosition(skeleton.Joints, JointType.FootRight);
  327.  
  328. // Hands and arms
  329. player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight);
  330. player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight);
  331. player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight);
  332.  
  333. player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft);
  334. player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft);
  335. player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft);
  336.  
  337. // Head and Shoulders
  338. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head);
  339. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter);
  340. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight);
  341.  
  342. // Legs
  343. player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft);
  344. player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft);
  345. player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft);
  346.  
  347. player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight);
  348. player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight);
  349. player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight);
  350.  
  351. player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter);
  352. player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight);
  353.  
  354. // Spine
  355. player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter);
  356. }
  357. }
  358.  
  359. skeletonSlot++;
  360. }
  361. }
  362. }
  363. }
  364.  
  365. private void CheckPlayers()
  366. {
  367. foreach (var player in this.players)
  368. {
  369.  
  370. if (!player.Value.IsAlive)
  371. {
  372. // Player left scene since we aren't tracking it anymore, so remove from dictionary
  373. this.players.Remove(player.Value.GetId());
  374. break;
  375. }
  376. }
  377.  
  378. // Count alive players
  379. int alive = this.players.Count(player => player.Value.IsAlive);
  380.  
  381. if (alive != this.playersAlive)
  382. {
  383. if (alive == 2)
  384. {
  385. this.myFallingThings.SetGameMode(GameMode.TwoPlayer);
  386. }
  387. else if (alive == 1)
  388. {
  389. this.myFallingThings.SetGameMode(GameMode.Solo);
  390. }
  391. else if (alive == 0)
  392. {
  393. this.myFallingThings.SetGameMode(GameMode.Off);
  394. }
  395.  
  396. if ((this.playersAlive == 0) && (this.mySpeechRecognizer != null))
  397. {
  398. BannerText.NewBanner(
  399. Properties.Resources.Vocabulary,
  400. this.screenRect,
  401. true,
  402. System.Windows.Media.Color.FromArgb(200, 255, 255, 255));
  403. }
  404.  
  405. this.playersAlive = alive;
  406. }
  407. }
  408.  
  409. private void PlayfieldSizeChanged(object sender, SizeChangedEventArgs e)
  410. {
  411. this.UpdatePlayfieldSize();
  412. }
  413.  
  414. private void UpdatePlayfieldSize()
  415. {
  416. // Size of player wrt size of playfield, putting ourselves low on the screen.
  417. this.screenRect.X = 0;
  418. this.screenRect.Y = 0;
  419. this.screenRect.Width = this.playfield.ActualWidth;
  420. this.screenRect.Height = this.playfield.ActualHeight;
  421.  
  422. BannerText.UpdateBounds(this.screenRect);
  423.  
  424. this.playerBounds.X = 0;
  425. this.playerBounds.Width = this.playfield.ActualWidth;
  426. this.playerBounds.Y = this.playfield.ActualHeight * 0.2;
  427. this.playerBounds.Height = this.playfield.ActualHeight * 0.75;
  428.  
  429. foreach (var player in this.players)
  430. {
  431. player.Value.SetBounds(this.playerBounds);
  432. }
  433.  
  434. Rect fallingBounds = this.playerBounds;
  435. fallingBounds.Y = 0;
  436. fallingBounds.Height = playfield.ActualHeight;
  437. if (this.myFallingThings != null)
  438. {
  439. this.myFallingThings.SetBoundaries(fallingBounds);
  440. }
  441. }
  442. #endregion Kinect Skeleton processing
  443.  
  444. #region GameTimer/Thread
  445. private void GameThread()
  446. {
  447. this.runningGameThread = true;
  448. this.predNextFrame = DateTime.Now;
  449. this.actualFrameTime = 1000.0 / this.targetFramerate;
  450.  
  451. // Try to dispatch at as constant of a framerate as possible by sleeping just enough since
  452. // the last time we dispatched.
  453. while (this.runningGameThread)
  454. {
  455. // Calculate average framerate.
  456. DateTime now = DateTime.Now;
  457. if (this.lastFrameDrawn == DateTime.MinValue)
  458. {
  459. this.lastFrameDrawn = now;
  460. }
  461.  
  462. double ms = now.Subtract(this.lastFrameDrawn).TotalMilliseconds;
  463. this.actualFrameTime = (this.actualFrameTime * 0.95) + (0.05 * ms);
  464. this.lastFrameDrawn = now;
  465.  
  466. // Adjust target framerate down if we're not achieving that rate
  467. this.frameCount++;
  468. if ((this.frameCount % 100 == 0) && (1000.0 / this.actualFrameTime < this.targetFramerate * 0.92))
  469. {
  470. this.targetFramerate = Math.Max(MinFramerate, (this.targetFramerate + (1000.0 / this.actualFrameTime)) / 2);
  471. }
  472.  
  473. if (now > this.predNextFrame)
  474. {
  475. this.predNextFrame = now;
  476. }
  477. else
  478. {
  479. double milliseconds = this.predNextFrame.Subtract(now).TotalMilliseconds;
  480. if (milliseconds >= TimerResolution)
  481. {
  482. Thread.Sleep((int)(milliseconds + 0.5));
  483. }
  484. }
  485.  
  486. this.predNextFrame += TimeSpan.FromMilliseconds(1000.0 / this.targetFramerate);
  487.  
  488. this.Dispatcher.Invoke(DispatcherPriority.Send, new Action<int>(this.HandleGameTimer), 0);
  489. }
  490. }
  491.  
  492. private void HandleGameTimer(int param)
  493. {
  494. // Every so often, notify what our actual framerate is
  495. if ((this.frameCount % 100) == 0)
  496. {
  497. this.myFallingThings.SetFramerate(1000.0 / this.actualFrameTime);
  498. }
  499.  
  500. // Advance animations, and do hit testing.
  501. for (int i = 0; i < NumIntraFrames; ++i)
  502. {
  503. foreach (var pair in this.players)
  504. {
  505. HitType hit = this.myFallingThings.LookForHits(pair.Value.Segments, pair.Value.GetId());
  506. if ((hit & HitType.Squeezed) != 0)
  507. {
  508. this.squeezeSound.Play();
  509. }
  510. else if ((hit & HitType.Popped) != 0)
  511. {
  512. this.popSound.Play();
  513. }
  514. else if ((hit & HitType.Hand) != 0)
  515. {
  516. this.hitSound.Play();
  517. }
  518. }
  519.  
  520. this.myFallingThings.AdvanceFrame();
  521. }
  522.  
  523. // Draw new Wpf scene by adding all objects to canvas
  524. playfield.Children.Clear();
  525. this.myFallingThings.DrawFrame(this.playfield.Children);
  526. foreach (var player in this.players)
  527. {
  528. //if (players.Count > 1)
  529. // numOfPlayers= players.Count;
  530. player.Value.Draw(playfield.Children);
  531. }
  532.  
  533. BannerText.Draw(playfield.Children);
  534. FlyingText.Draw(playfield.Children);
  535.  
  536. this.CheckPlayers();
  537. }
  538. #endregion GameTimer/Thread
  539.  
  540. #region Kinect Speech processing
  541. private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
  542. {
  543. FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), e.Matched);
  544. switch (e.Verb)
  545. {
  546. case SpeechRecognizer.Verbs.Pause:
  547. this.myFallingThings.SetDropRate(0);
  548. this.myFallingThings.SetGravity(0);
  549. break;
  550. case SpeechRecognizer.Verbs.Resume:
  551. this.myFallingThings.SetDropRate(this.dropRate);
  552. this.myFallingThings.SetGravity(this.dropGravity);
  553. break;
  554. case SpeechRecognizer.Verbs.Reset:
  555. this.dropRate = DefaultDropRate;
  556. this.dropSize = DefaultDropSize;
  557. this.dropGravity = DefaultDropGravity;
  558. this.myFallingThings.SetPolies(PolyType.All);
  559. this.myFallingThings.SetDropRate(this.dropRate);
  560. this.myFallingThings.SetGravity(this.dropGravity);
  561. this.myFallingThings.SetSize(this.dropSize);
  562. this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
  563. this.myFallingThings.Reset();
  564. break;
  565. case SpeechRecognizer.Verbs.DoShapes:
  566. this.myFallingThings.SetPolies(e.Shape);
  567. break;
  568. case SpeechRecognizer.Verbs.RandomColors:
  569. this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
  570. break;
  571. case SpeechRecognizer.Verbs.Colorize:
  572. this.myFallingThings.SetShapesColor(e.RgbColor, false);
  573. break;
  574. case SpeechRecognizer.Verbs.ShapesAndColors:
  575. this.myFallingThings.SetPolies(e.Shape);
  576. this.myFallingThings.SetShapesColor(e.RgbColor, false);
  577. break;
  578. case SpeechRecognizer.Verbs.More:
  579. this.dropRate *= 1.5;
  580. this.myFallingThings.SetDropRate(this.dropRate);
  581. break;
  582. case SpeechRecognizer.Verbs.Fewer:
  583. this.dropRate /= 1.5;
  584. this.myFallingThings.SetDropRate(this.dropRate);
  585. break;
  586. case SpeechRecognizer.Verbs.Bigger:
  587. this.dropSize *= 1.5;
  588. if (this.dropSize > MaxShapeSize)
  589. {
  590. this.dropSize = MaxShapeSize;
  591. }
  592.  
  593. this.myFallingThings.SetSize(this.dropSize);
  594. break;
  595. case SpeechRecognizer.Verbs.Biggest:
  596. this.dropSize = MaxShapeSize;
  597. this.myFallingThings.SetSize(this.dropSize);
  598. break;
  599. case SpeechRecognizer.Verbs.Smaller:
  600. this.dropSize /= 1.5;
  601. if (this.dropSize < MinShapeSize)
  602. {
  603. this.dropSize = MinShapeSize;
  604. }
  605.  
  606. this.myFallingThings.SetSize(this.dropSize);
  607. break;
  608. case SpeechRecognizer.Verbs.Smallest:
  609. this.dropSize = MinShapeSize;
  610. this.myFallingThings.SetSize(this.dropSize);
  611. break;
  612. case SpeechRecognizer.Verbs.Faster:
  613. this.dropGravity *= 1.25;
  614. if (this.dropGravity > 4.0)
  615. {
  616. this.dropGravity = 4.0;
  617. }
  618.  
  619. this.myFallingThings.SetGravity(this.dropGravity);
  620. break;
  621. case SpeechRecognizer.Verbs.Slower:
  622. this.dropGravity /= 1.25;
  623. if (this.dropGravity < 0.25)
  624. {
  625. this.dropGravity = 0.25;
  626. }
  627.  
  628. this.myFallingThings.SetGravity(this.dropGravity);
  629. break;
  630. }
  631. }
  632.  
  633. private void EnableAecChecked(object sender, RoutedEventArgs e)
  634. {
  635. var enableAecCheckBox = (CheckBox)sender;
  636. this.UpdateEchoCancellation(enableAecCheckBox);
  637. }
  638.  
  639. private void UpdateEchoCancellation(CheckBox aecCheckBox)
  640. {
  641. this.mySpeechRecognizer.EchoCancellationMode = aecCheckBox.IsChecked != null && aecCheckBox.IsChecked.Value
  642. ? EchoCancellationMode.CancellationAndSuppression
  643. : EchoCancellationMode.None;
  644. }
  645.  
  646. #endregion Kinect Speech processing
  647. }
  648. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement