作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我设置音频队列服务的代码:
aqData = AQRecorderState()
aqData.mDataFormat.mFormatID = kAudioFormatMPEG4AAC
aqData.mDataFormat.mSampleRate = 16000.0
aqData.mDataFormat.mChannelsPerFrame = 1
aqData.mDataFormat.mBitsPerChannel = 16
aqData.mDataFormat.mBytesPerPacket = aqData.mDataFormat.mChannelsPerFrame * UInt32(sizeof(UInt16))
aqData.mDataFormat.mBytesPerFrame = aqData.mDataFormat.mChannelsPerFrame * UInt32(sizeof(UInt16))
aqData.mDataFormat.mFramesPerPacket = 1
aqData.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsBigEndian
aqData.mQueue = AudioQueueRef()
fileType = kAudioFileM4AType
// create new input for audio queue
AudioQueueNewInput(&aqData.mDataFormat, handleInputBuffer, &aqData, nil, kCFRunLoopCommonModes, 0, &aqData.mQueue)
var dataFormatSize:UInt32 = UInt32(sizeof(aqData.mDataFormat.dynamicType))
AudioQueueGetProperty(aqData.mQueue, kAudioQueueProperty_StreamDescription, &aqData.mDataFormat, &dataFormatSize)
// create file to store audio
let data = recordUrl.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
let audioFileURL: CFURLRef = CFURLCreateFromFileSystemRepresentation(nil, UnsafePointer(data.bytes), data.length, false)
AudioFileCreateWithURL(audioFileURL, fileType, &aqData.mDataFormat, AudioFileFlags.EraseFile, &aqData.mAudioFile)
// set magic cookie for file if needed
setMegicCookieForFile(aqData.mQueue, inFile: aqData.mAudioFile)
// derive buffer size
deriveBufferSize(aqData.mQueue, ASBDescription: &aqData.mDataFormat, seconds: kBufferLengthInSecond, outbufferSize: &aqData.bufferByteSize)
// allocate and enqueue each buffer
for i in 0..<Record.kNumberBuffers {
AudioQueueAllocateBuffer(aqData.mQueue, aqData.bufferByteSize, &aqData.mBuffers[i])
AudioQueueEnqueueBuffer(aqData.mQueue, aqData.mBuffers[i], 0, nil)
}
AudioQueueNewInput(&aqData.mDataFormat, handleInputBuffer, &aqData, nil, kCFRunLoopCommonModes, 0, &aqData.mQueue)
AudioConverterNew from AudioQueueNew returned 'fmt?'
最佳答案
来自 CoreAudioTypes.h
头文件,我们收集到:
kAudioFormatMPEG4AAC MPEG-4 Low Complexity AAC audio object, has no flags.
AudioStreamBasicDescription
上方发表评论在同一个文件中说:
In compressed audio, a Packet is an indivisible chunk of compressed data, for example an AAC packet will contain 1024 sample frames.
mBitsPerChannel
,
mBytesPerPacket
和
mFramesPerPacket
应该为零。
AudioStreamBasicDescription
的这些字段:
aqData.mDataFormat.mBitsPerChannel = 0
aqData.mDataFormat.mBytesPerPacket = 0
aqData.mDataFormat.mBytesPerFrame = 0
aqData.mDataFormat.mFramesPerPacket = 1024
aqData.mDataFormat.mFormatFlags = 0
关于ios - 音频队列录制错误 : AudioConverterNew from AudioQueueNew returned 'fmt?' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33882455/
这是我设置音频队列服务的代码: aqData = AQRecorderState() aqData.mDataFormat.mFormatID = kAudioForm
我是一名优秀的程序员,十分优秀!