iPhone Audio Queue, hardware decoding
<p>I am writing an iPhone application that downloads audio files from the internet and can play them while downloading (and play white noise if network buffer is empty), so, I think, I can't use just an AVAudioPlayer and should fill audio buffer myself. Files are in MP3's and they should be hardware decoded. My first try was AudioUnit with:</p>

<pre><code>AudioStreamBasicDescription audioFormat;
bzero(&amp;audioFormat, sizeof(AudioStreamBasicDescription));
audioFormat.mSampleRate = 44100;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mFormatID = kAudioFormatMPEGLayer3;
audioFormat.mFramesPerPacket = 1152;
</code></pre>

<p>and then filling buffer with MP3 packets, but this is not working as Remote IO does not work with compressed streams, so I decided to dive into Audio Queue:</p>

<pre><code>static void HandleOutputBuffer (
    void                *aqData,
    AudioQueueRef       inAQ,
    AudioQueueBufferRef inBuffer
) {
    AQPlayerState *pAqData = (AQPlayerState *) aqData;        // 1
    if (pAqData-&gt;mIsRunning == 0) return;                     // 2
    UInt32 numBytesReadFromFile;                              // 3
    UInt32 numPackets = pAqData-&gt;mNumPacketsToRead;           // 4
    AudioFileReadPackets (
        pAqData-&gt;mAudioFile,
        false,
        &amp;numBytesReadFromFile,
        pAqData-&gt;mPacketDescs,
        pAqData-&gt;mCurrentPacket,
        &amp;numPackets,
        inBuffer-&gt;mAudioData
    );
    if (numPackets &gt; 0) {                                     // 5
        inBuffer-&gt;mAudioDataByteSize = numBytesReadFromFile;  // 6
        AudioQueueEnqueueBuffer (
            pAqData-&gt;mQueue,
            inBuffer,
            (pAqData-&gt;mPacketDescs ? numPackets : 0),
            pAqData-&gt;mPacketDescs
        );
        pAqData-&gt;mCurrentPacket += numPackets;                // 7
    } else {
        AudioQueueStop (
            pAqData-&gt;mQueue,
            false
        );
        pAqData-&gt;mIsRunning = false;
    }
}
</code></pre>

<p>The question is: will <code>pAqData-&gt;mAudioFile</code> be hardware decoded this way? And another question is: how can I feed mp3 data stored in NSData to AudioQueueEnqueueBuffer?</p>
