title: Converting AVAudioPCMBuffer to NSData
body: <p>I'm currently trying to convert the audio samples from <code>AVAudioPCMBuffer</code> to <code>NSData</code> - I had taken a look at the accepted answer on this <a href="https://stackoverflow.com/questions/28048568/convert-avaudiopcmbuffer-to-nsdata-and-back?noredirect=1&amp;lq=1">SO Post</a> and this <a href="https://github.com/tryolabs/TLSphinx/blob/master/TLSphinx/Decoder.swift" rel="nofollow noreferrer">code from GitHub</a> but it appears some of the <code>AVFAudio</code> API's have changed...below is the extension I have for <code>AVAudioPCMBuffer</code>:</p>
  
  <pre><code>private extension AVAudioPCMBuffer {
  
      func toNSData() -&gt; NSData {
          let channels = UnsafeBufferPointer(start: int16ChannelData, count: 1)
          let ch0Data = NSData(bytes: channels[0], length:Int(frameCapacity * format.streamDescription.inTotalBitsPerChannel))
  
          return ch0Data
      }
  
  }
  </code></pre>
  
  <p>I'm seeing an error of <code>Value of type 'UnsafePointer&lt;AudioStreamBasicDescription&gt;' has no member 'inTotalBitsPerChannel'</code>. So far, I've not been able to find out any other way to find out the <code>inTotalBitsPerChannel</code> value...any help appreciated!</p>