ExtAudioFileWrite到m4aaac在双核设备上失败(ipad 2,iphone 4s)

ExtAudioFileWrite到m4aaac在双核设备上失败(ipad 2,iphone 4s),第1张

概述我写了一个循环来使用扩展音频文件服务将我的应用程序生成的pcm音频数据编码到aac.编码同步地在后台线程中进行,而不是实时进行. 对于ios 4和i,ipad 1和iphone 3gs / 4的编码完美无缺.然而,对于双核设备(iphone 4s,ipad 2),第三次调用ExtAudioFileWrite会导致编码线程崩溃而没有堆栈跟踪且没有错误代码. 这是有问题的代码: 数据格式 AudioS 我写了一个循环来使用扩展音频文件服务将我的应用程序生成的pcm音频数据编码到aac.编码同步地在后台线程中进行,而不是实时进行.

对于ios 4和i,ipad 1和iphone 3gs / 4的编码完美无缺.然而,对于双核设备(iphone 4s,ipad 2),第三次调用ExtAudiofileWrite会导致编码线程崩溃而没有堆栈跟踪且没有错误代码.

这是有问题的代码:

数据格式

AudioStreamBasicDescription AUCanonicalASBD(float64 sampleRate,UInt32 channel){AudioStreamBasicDescription audioFormat;audioFormat.mSampleRate         = sampleRate;audioFormat.mFormatID           = kAudioFormatlinearPCM;audioFormat.mFormatFlags        = kAudioFormatFlagsAudioUnitCanonical;audioFormat.mChannelsPerFrame   = channel;audioFormat.mBytesPerPacket     = sizeof(AudioUnitSampleType);audioFormat.mBytesPerFrame      = sizeof(AudioUnitSampleType);audioFormat.mFramesPerPacket    = 1;audioFormat.mBitsPerChannel     = 8 * sizeof(AudioUnitSampleType);audioFormat.mReserved           = 0;return audioFormat;}AudioStreamBasicDescription MixdownAAC(voID){AudioStreamBasicDescription audioFormat;audioFormat.mSampleRate         = 44100.0;audioFormat.mFormatID           = kAudioFormatMPEG4AAC;audioFormat.mFormatFlags        = kMPEG4Object_AAC_Main;audioFormat.mChannelsPerFrame   = 2;audioFormat.mBytesPerPacket     = 0;audioFormat.mBytesPerFrame      = 0;audioFormat.mFramesPerPacket    = 1024;audioFormat.mBitsPerChannel     = 0;audioFormat.mReserved           = 0;return audioFormat;}

渲染循环

Osstatus err;ExtAudiofileRef outfile;NSURL *mixdownURL = [NSURL fileURLWithPath:filePath isDirectory:NO];// internal data formatAudioStreamBasicDescription localFormat = AUCanonicalASBD(44100.0,2);// output file formatAudioStreamBasicDescription mixdownFormat = MixdownAAC();err = ExtAudiofileCreateWithURL((CFURLRef)mixdownURL,kAudiofileM4AType,&mixdownFormat,NulL,kAudiofileFlags_Erasefile,&outfile);err = ExtAudiofileSetProperty(outfile,kExtAudiofileProperty_ClIEntDataFormat,sizeof(AudioStreamBasicDescription),&localFormat);// prepAllRenderData *allData = &allRenderData;writeBuffer = malloc(sizeof(audiobufferlist) + (2*sizeof(AudioBuffer)));writeBuffer->mNumberBuffers = 2;writeBuffer->mBuffers[0].mNumberChannels = 1;writeBuffer->mBuffers[0].mDataByteSize = bufferBytes;writeBuffer->mBuffers[0].mData = malloc(bufferBytes);writeBuffer->mBuffers[1].mNumberChannels = 1;writeBuffer->mBuffers[1].mDataByteSize = bufferBytes;writeBuffer->mBuffers[1].mData = malloc(bufferBytes);memset(writeBuffer->mBuffers[0].mData,bufferBytes);memset(writeBuffer->mBuffers[1].mData,bufferBytes);UInt32 framesToGet;UInt32 frameCount = allData->gloopStartFrame;UInt32 startFrame = allData->gloopStartFrame;UInt32 lastFrame = allData->gloopEndFrame;// write one silent bufferExtAudiofileWrite(outfile,bufferFrames,writeBuffer);while (frameCount < lastFrame){    // how many frames do we need to get    if (lastFrame - frameCount > bufferFrames)        framesToGet = bufferFrames;    else        framesToGet = lastFrame - frameCount;    // get dem frames    err = theBigolCallback((voID*)&allRenderData,1,framesToGet,writeBuffer);    // write to output file    ExtAudiofileWrite(outfile,writeBuffer);    frameCount += framesToGet;}// write one trailing silent buffermemset(writeBuffer->mBuffers[0].mData,bufferBytes);processlimiterInPlace8p24(limiter,writeBuffer->mBuffers[0].mData,writeBuffer->mBuffers[1].mData,bufferFrames);ExtAudiofileWrite(outfile,writeBuffer);err = ExtAudiofiledispose(outfile);

pcm帧已正确创建,但ExtAudiofileWrite在第二次/第三次调用时失败.

有任何想法吗?谢谢!

解决方法 我有一个非常类似的问题,我试图使用扩展音频文件服务,以便将PCM声音流式传输到iPad 2上的m4a文件.除了每次调用ExtAudiofileWrite都返回错误代码-66567(kExtAudiofileError_MaxPacketSizeUnkNown)之外,一切似乎都有效. .我最终找到的修复方法是将“Codec Manufacturer”设置为软件而不是硬件.所以放置

UInt32 codecManf = kAppleSoftwareAudioCodecManufacturer;ExtAudiofileSetProperty(fileToWrite,kExtAudiofileProperty_CodecManufacturer,sizeof(UInt32),&codecManf);

在您设置客户端数据格式之前.

这将使我相信Apple的硬件编解码器只能支持非常特定的编码,但软件编解码器可以更可靠地执行您想要的 *** 作.在我的情况下,m4a的软件编解码器转换比将完全相同的文件写入LPCM格式要长50%.

有谁知道Apple是否指定了音频编解码器硬件的功能?似乎软件工程师正在玩这个长达数小时的猜谜游戏,即为客户端设置AudioStreamBasicDescription和AudioChannelLayout中的~20个参数,并将文件设置为每个可能的排列,直到某些工作正常…

总结

以上是内存溢出为你收集整理的ExtAudioFileWrite到m4a/aac在双核设备上失败(ipad 2,iphone 4s)全部内容,希望文章能够帮你解决ExtAudioFileWrite到m4a/aac在双核设备上失败(ipad 2,iphone 4s)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1086250.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存