3
votes

I'm trying to play PCM stream data from server using AudioQueue.

PCM data format :

Sample rate = 48000, num of channel = 2, Bit per sample = 16

And, server is not streaming fixed bytes to client. (variable bytes.) (ex : 30848, 128, 2764, ... bytes )

How to set ASBD ? I don't know how to set mFramesPerPacket, mBytesPerFrame, mBytesPerPacket . I have read Apple reference document, but there is no detailed descriptions.

Please give me any idea.

New added : Here, ASBD structure what I have setted. (language : Swift)

// Create ASBD structure & set properties.
var streamFormat = AudioStreamBasicDescription()

streamFormat.mSampleRate = 48000
streamFormat.mFormatID = kAudioFormatLinearPCM
streamFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked
streamFormat.mFramesPerPacket = 1
streamFormat.mChannelsPerFrame = 2
streamFormat.mBitsPerChannel = 16

streamFormat.mBytesPerFrame = (streamFormat.mBitsPerChannel / 8) * streamFormat.mChannelsPerFrame
streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame
streamFormat.mReserved = 0

// Create AudioQueue for playing PCM streaming data.
var err = AudioQueueNewOutput(&streamFormat, self.queueCallbackProc, nil, nil, nil, 0, &aq)

...

I have setted ASBD structure like the above.

AudioQueue play streamed PCM data very well for a few seconds,

but soon playing is stop. What can I do?

(still streaming, and queueing AudioQueue)

Please give me any idea.

1

1 Answers

1
votes

ASBD is just a structure underneath defined like follows:

struct AudioStreamBasicDescription
{
    Float64             mSampleRate;
    AudioFormatID       mFormatID;
    AudioFormatFlags    mFormatFlags;
    UInt32              mBytesPerPacket;
    UInt32              mFramesPerPacket;
    UInt32              mBytesPerFrame;
    UInt32              mChannelsPerFrame;
    UInt32              mBitsPerChannel;
    UInt32              mReserved;
};
typedef struct AudioStreamBasicDescription  AudioStreamBasicDescription;

You may set the variables of a struct like this:

AudioStreamBasicDescription streamFormat;

streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;

streamFormat.mSampleRate = sampleRate;
streamFormat.mBitsPerChannel = bitsPerChannel;
streamFormat.mChannelsPerFrame = channelsPerFrame;
streamFormat.mFramesPerPacket = 1;

int bytes = (bitsPerChannel / 8) * channelsPerFrame;
streamFormat.mBytesPerFrame = bytes;
streamFormat.mBytesPerPacket = bytes;