title: Swift Audio Playback speed
body: <p>I am developing a game where the main sprite is a spinning wheel. I would like to associate audio to the spinning wheel that changes pitch as the wheel slows down. When the wheel stops spinning I would like the sound effect to stop. Can someone point me in the right direction?</p>
  
  <p>In my game scene I have the following code:</p>
  
  <pre><code>override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
  
      for touch in touches {
          let location = touch.location(in: self)
          //Start spinning the wheel
          if atPoint(location).name == "play_button" {
              player?.physicsBody?.angularVelocity = 0
              player?.rotatePlayer()
  
              //Click back button
          } else if atPoint(location).name == "back_button" {
              let play_scene = CharacterSelectScene(fileNamed: "CharacterSelect")
              play_scene?.scaleMode = .aspectFill
              self.view?.presentScene(play_scene!, transition: SKTransition.doorsOpenVertical(withDuration: 1))
          } else if atPoint(location).name == "settings_button" {
              let play_scene = SettingsScene(fileNamed: "SettingsScene")
              play_scene?.scaleMode = .aspectFill
              self.view?.presentScene(play_scene!, transition: SKTransition.doorsOpenVertical(withDuration: 1))
          }
      }
  }
  
  override func didSimulatePhysics() {
      let speed = player?.physicsBody?.angularVelocity
      if (speed != CGFloat(0.0)) {
          if (speed! &lt;= CGFloat(0.1)){
              finishedRotation = true
          }
      }
  }
  override func didFinishUpdate() {
      if (finishedRotation == true) {
          let play_scene = QuestionScene(fileNamed: "QuestionScene")
          play_scene?.scaleMode = .aspectFill
          self.view?.presentScene(play_scene!, transition: SKTransition.doorsOpenVertical(withDuration: 1))
      }
  }
  func didBegin(_ contact: SKPhysicsContact) {
      let defaults = UserDefaults.standard
      var firstBody = SKPhysicsBody()
      var secondBody = SKPhysicsBody()
      if (contact.bodyA.node?.name == "pin") {
          firstBody = contact.bodyA
          secondBody = contact.bodyB
      } else {
          firstBody = contact.bodyB
          secondBody = contact.bodyA
      }
      if (firstBody.node?.name == "pin" &amp;&amp; secondBody.node?.name == "geography") {
          let set_topic = secondBody.node?.name
          defaults.set(set_topic, forKey: "Topic")
      } else if (firstBody.node?.name == "pin" &amp;&amp; secondBody.node?.name == "maths") {
          let set_topic = secondBody.node?.name
          defaults.set(set_topic, forKey: "Topic")
      } else if (firstBody.node?.name == "pin" &amp;&amp; secondBody.node?.name == "history") {
          let set_topic = secondBody.node?.name
          defaults.set(set_topic, forKey: "Topic")
      } else if (firstBody.node?.name == "pin" &amp;&amp; secondBody.node?.name == "science") {
          let set_topic = secondBody.node?.name
          defaults.set(set_topic, forKey: "Topic")
      }
  }
  </code></pre>
  
  <p>The rotatePlayer method from the Player class is defined as below:</p>
  
  <pre><code>func rotatePlayer() {
      let random = GKRandomDistribution(lowestValue: 20, highestValue: 120)
      let r = random.nextInt()
      self.physicsBody?.angularVelocity = 0
      self.physicsBody?.angularVelocity = CGFloat(r)
      self.physicsBody?.angularDamping = 1.02
  
  }
  </code></pre>