AudioStreamBasicDescript
ion format; // 声音格式设置,这些设置要和采集时的配置一致
memset(&format, 0, sizeof(format));
format.mSampleRate = 44100; // 采样率 (立体声 = 8000)
format.mFormatID = kAudioFormatLinearPCM; // PCM 格式
format.mFormatFlags = kLinearPCMFormatFlagIsSi
gnedInteger | kLinearPCMFormatFlagIsPa
cked;
format.mChannelsPerFrame = 1;
// 1:单声道;2:立体声
format.mBitsPerChannel = 16; // 语音每采样点占用位数
format.mBytesPerFrame = (format.mBitsPerChannel /
* format.mChannelsPerFrame;
format.mFramesPerPacket = 1;
format.mBytesPerPacket = format.mBytesPerFrame * format.mFramesPerPacket;
AudioQueueRef queue;
AudioQueueNewOutput(&format,
AQPlayer::AQOutputCallback,
this,
// opaque reference to whatever you like
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes,
0,
&queue);
const int bufferSize = 0xA000;
// 48K - around 1/2 sec of 44kHz 16 bit mono PCM
for (int i = 0; i < kNumberBuffers; ++i)
AudioQueueAllocateBuffer
WithPacketDescriptions(queue, bufferSize, 0, &mBuffers[i]);
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, 1.0);
UInt32 category = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionPrope rty_AudioCategory, sizeof(category), &category);
AudioSessionSetActive(true);
// prime the queue with some data befor e starting
for (int i = 0; i < kNumberBuffers; ++i)
OutputCallback(queue, mBuffers[i]);
AudioQueueStart(queue, NULL);
在CallBack中填出数据:
void OutputCallback(void* inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer) {
memset(&format, 0, sizeof(format));
format.mSampleRate = 44100; // 采样率 (立体声 = 8000)
format.mFormatID = kAudioFormatLinearPCM; // PCM 格式
format.mFormatFlags = kLinearPCMFormatFlagIsSi
format.mChannelsPerFrame = 1;
format.mBitsPerChannel = 16; // 语音每采样点占用位数
format.mBytesPerFrame = (format.mBitsPerChannel /
format.mFramesPerPacket = 1;
format.mBytesPerPacket = format.mBytesPerFrame * format.mFramesPerPacket;
AudioQueueRef queue;
AudioQueueNewOutput(&format,
const int bufferSize = 0xA000;
for (int i = 0; i < kNumberBuffers; ++i)
AudioQueueSetParameter(queue, kAudioQueueParam_Volume, 1.0);
UInt32 category = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionPrope rty_AudioCategory, sizeof(category), &category);
AudioSessionSetActive(true);
// prime the queue with some data befor e starting
for (int i = 0; i < kNumberBuffers; ++i)
AudioQueueStart(queue, NULL);
在CallBack中填出数据:
void OutputCallback(void* inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer) {