首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是m4a文件格式的AudioStreamBasicDescription

什么是m4a文件格式的AudioStreamBasicDescription
EN

Stack Overflow用户
提问于 2011-01-11 15:41:34
回答 2查看 3.8K关注 0票数 4

我已经尝试了更多的m4a文件格式的AudioStreamBasicDescription。不过,我还是遇到了一些问题。

请告诉我确切的m4a文件格式的AudioStreamBasicDescription。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-04 17:40:21

您可以使用ExtAudioFileGetProperty从现有的m4a音频文件中获取ASBD。

有关更多详细信息,请访问Click here

票数 5
EN

Stack Overflow用户

发布于 2016-12-14 22:11:49

你可以用2种(至少)不同的方法来获取一个文件的ASBD。你可以使用'ExtAudioFileGetProperty‘或'AudioFileGetProperty’。

AudioFileGetProperty:

代码语言:javascript
复制
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"m4a"];
CFURLRef soundFileURL = (__bridge CFURLRef)[NSURL fileURLWithPath:soundFilePath];

if (soundFileURL != nil) {

    AudioFileID audioFile;
    OSStatus theError = noErr;

    theError = AudioFileOpenURL(soundFileURL,
                                kAudioFileReadPermission,
                                0,
                                &audioFile);
    if(theError != noErr) {
        printf("AudioFileOpenURL failed!");
        return;
    }

    AudioStreamBasicDescription asbd;
    UInt32 size = sizeof(asbd);
    theError = AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &size, &asbd);

    if(theError != noErr) {
        printf("kAudioFilePropertyDataFormat failed!");
        return;
    } else {
        printf("Sample Rate : %f\n", asbd.mSampleRate);
        /*
         Float64             mSampleRate;
         AudioFormatID       mFormatID;
         AudioFormatFlags    mFormatFlags;
         UInt32              mBytesPerPacket;
         UInt32              mFramesPerPacket;
         UInt32              mBytesPerFrame;
         UInt32              mChannelsPerFrame;
         UInt32              mBitsPerChannel;
         UInt32              mReserved;
         */
    }
}

ExtAudioFileGetProperty:

代码语言:javascript
复制
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"m4a"];
CFURLRef soundFileURL = (__bridge CFURLRef)[NSURL fileURLWithPath:soundFilePath];

if (soundFileURL != nil) {
    OSStatus theError = noErr;

    ExtAudioFileRef fileRef;
    theError = ExtAudioFileOpenURL(soundFileURL, &fileRef);

    if(theError != noErr) {
        printf("ExtAudioFileOpenURL failed!");
        return;
    }

    AudioStreamBasicDescription asbd;
    UInt32 size = sizeof(asbd);
    theError = ExtAudioFileGetProperty(fileRef, kExtAudioFileProperty_FileDataFormat, &size, &asbd );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4655277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档