SHARE
TWEET

Untitled

a guest Sep 24th, 2017 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   func normalize() {
  2.         let numChannels = Int(self.numberOfChannels)
  3.         let numSamples = Int(self.bufferSize)
  4.      
  5.         // Scale using log curve
  6.         for c in 0 ..< numChannels {
  7.             for i in 0 ..< numSamples {
  8.                 let oldValue = self.buffers![c]![i]
  9.                 let newValue = log2f(1.0 + oldValue)
  10.                 self.buffers![c]![i] = newValue
  11.             }
  12.         }
  13.        
  14.         // Find the max peak value
  15.         var maxAmplitude : Float = 0
  16.        
  17.         for c in 0 ..< numChannels {
  18.             for i in 0 ..< numSamples {
  19.                 let value = self.buffers![c]![i]
  20.                 maxAmplitude = max(value, maxAmplitude)
  21.             }
  22.         }
  23.        
  24.         // Normalize to max peak value
  25.         for c in 0 ..< numChannels {
  26.             for i in 0 ..< numSamples {
  27.                 let oldValue = self.buffers![c]![i]
  28.                 let newValue = oldValue / maxAmplitude
  29.                 self.buffers![c]![i] = newValue
  30.             }
  31.         }
  32.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top