title: How can I normalized decibel value and make it between 0 and 1
body: <p>I am trying to get the power of audio by looping on the audio samples and getting the average power per channel.</p>
  
  <p>I want to get a value between 0 and 1 that reflect the intensity of the audio being played. Right now I am getting dB (decibel value) which is a float value from -160 (near silent) to 0 (very loud).  </p>
  
  <p><strong>Here is my code</strong> written in Swift:</p>
  
  <pre><code>func configureAudio() {
      audioController.play()
      AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
      audioController.numberOfLoops = 0
      audioController.meteringEnabled = true
      var audTimer = CADisplayLink(target: self, selector: "monitorAudio")
      audTimer.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)
  }
  
  func monitorAudio() {
      audioController.updateMeters()
  
      var dB = Float(0)
      for i in 0..&lt;audioController.numberOfChannels {
          dB += audioController.averagePowerForChannel(i)
      }
  
      dB /= Float(audioController.numberOfChannels)
  //code that I copied from website but obviously it is not normalization
      var power = (Int(log10(dB+161)/log10(1.5) * 100) - 1220) * 6
      if power &lt; 0 {
          power = 0
      }
      println(power)
  }
  </code></pre>
  
  <p>I am not sure if the dB value i am getting is accurate or am I doing something wrong?</p>
  
  <p>right now I am getting values between 0-190 using some code I found but it doesn't make much sense for me.</p>
  
  <p><strong>What I need</strong> is to normalize the dB values I am getting to be between 0 - 1</p>
  
  <p><strong>EDIT - Feel free to write code in Obective-C</strong></p>