CoreAudio - kAudioFileUnsupportedDataFormatError

北慕城南 提交于 2019-12-13 07:03:24

问题


I'm just getting started with CoreAudio. Just trying to create an audio file, but getting a kAudioFileUnsupportedDataFormatError with the following.

Can any give me an idea why? It all looks okay to me, but I must be doing something wrong.

// Prepare the format
AudioStreamBasicDescription asbd;
memset(&asbd, 0, sizeof(asbd));

asbd.mSampleRate = SAMPLE_RATE;        // 44100

asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mFormatFlags = kAudioFormatFlagIsBigEndian;
asbd.mBitsPerChannel = 16;
asbd.mChannelsPerFrame = 1;
asbd.mFramesPerPacket = 1;
asbd.mBytesPerFrame = 2;
asbd.mBytesPerPacket = 2;

// Set up the file
AudioFileID audioFile;
OSStatus audioErr = noErr;
audioErr = AudioFileCreateWithURL((CFURLRef)fileURL,
                                 kAudioFileAIFFType,
                                 &asbd,
                                 kAudioFileFlags_EraseFile,
                                 &audioFile);

回答1:


The "Core Audio Data Types Reference" contains the reference material for AudioStreamBasicDescription. But it's pretty dense and difficult to understand.

"Audio Unit Hosting Guide for iOS" has a section called "Working with the AudioStreamBasicDescription structure" that's a bit more helpful.

d.




回答2:


Well, I got it to work by changing mFormatFlags to:

asbd.mFormatFlags = kLinearPCMFormatFlagIsBigEndian | 
                    kLinearPCMFormatFlagIsSignedInteger | 
                    kLinearPCMFormatFlagIsPacked;

I'm now looking for an Apple doc or other resource that tells you what flags are needed for which format, and why.




回答3:


mFormatFlags are bit-field flags so they can be combined using bitwise logical operators, hence the density and possible difficulty of understanding. Another useful document to look at before "going for the flags" may be this one:

https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html

Else, this objective-C utility for getting a human readable form of the flags has also been posted:

https://gist.github.com/eppz/11272305

Regards!



来源:https://stackoverflow.com/questions/8597941/coreaudio-kaudiofileunsupporteddataformaterror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!