In my app, i would be receiving audio data over socket in Linear PCM Format, in uniform interval of time, 50 ms approx., I am using AudioQueue to play the same, i referred most of the code from AudioQueue SpeakHere Example only the difference is i need to run it on the Mac OS,
Following is the relevant piece of code,
Setup AudioBufferDescription format,
FillOutASBDForLPCM (sRecordFormat,
                    16000,
                    1,
                    16,
                    16,
                    false,
                    false
                    );
Allocate Buffers to hold and play data
for (int i = 0; i < kNumberBuffersPLyer; ++i) {
    XThrowIfError(AudioQueueAllocateBuffer(mQueue, bufferByteSize,   &mBuffers[i]),
                  "AudioQueueAllocateBuffer failed");
}
Where bufferByteSize is 640 and Number of buffer is 3
To Start the Queue, 开发者_StackOverflow
OSStatus errorCode = AudioQueueStart(mQueue,NULL);
Now, the thing is, i was expecting, it should hit the Callback automatically When it played buffer, but it was't happening,
So as and when i am getting buffer, i am enqueue buffer , this is the code
void AudioStream::startQueueIfNeeded(){
    SetLooping(true);
    // prime the queue with some data before starting
    for (int i = 0; i < kNumberBuffersPLyer; ++i) 
    {
        AQBufferCallback (this, mQueue, mBuffers[0]);           
        //enQueueBuffer(this,mQueue,mBuffers[i]);
    }
    //  AudioSessionSetActive( true );
    OSStatus errorCode = AudioQueueStart(mQueue,NULL);
    mIsDone = false;
    mIsStarted = true;
}
i feel the buffer is proper but i can't hear the sound, can anyone guide me, what i am doing wrong.
Thanks in advance
Thanks for have a look on it, the problem was, i was running AudioQueue in C++ based thread class and it was terminated , when i take it out of thread class it worked fine.
                                        
                                        
                                        
                                        
                                        
                                        
                                        
                                        
 加载中,请稍侯......
      
精彩评论