title: iOS: Playing PCM buffers from a stream
body: <p>I'm receiving a series of UDP packets from a socket containing encoded PCM buffers. After decoding them, I'm left with an int16 * audio buffer, which I'd like to immediately play back.</p>
  
  <p>The intended logic goes something like this:</p>
  
  <pre><code>init(){
     initTrack(track, output, channels, sample_rate, ...);
  }
  
  onReceiveBufferFromSocket(NSData data){
     //Decode the buffer
     int16 * buf = handle_data(data);
  
     //Play data
     write_to_track(track, buf, length_of_buf, etc);
  }
  </code></pre>
  
  <p>I'm not sure about everything that has to do with playing back the buffers though. On Android, I'm able to achieve this by creating an AudioTrack object, setting it up by specifying a sample rate, a format, channels, etc... and then just calling the "write" method with the buffer (like I wish I could in my pseudo-code above) but on iOS I'm coming up short. </p>
  
  <p>I tried using the Audio File Stream Services, but I'm guessing I'm doing something wrong since no sound ever comes out and I feel like those functions by themselves don't actually do any playback. I also attempted to understand the Audio Queue Services (which I think might be close to what I want), however I was unable to find any simple code samples for its usage.</p>
  
  <p>Any help would be greatly appreciated, specially in the form of example code.</p>