m4a 文件格式的 AudioStreamBasicDescription 是什么

发布于 2024-10-11 05:52:58 字数 122 浏览 2 评论 0原文

我尝试了更多用于 m4a 文件格式的 AudioStreamBasicDescription 。我仍然遇到一些问题。

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

I have tried with more AudioStreamBasicDescription for m4a file format. Still I am getting some issues with that.

Please anyone tell me the exact AudioStreamBasicDescription for m4a file format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2024-10-18 05:52:58

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

有关更多详细信息点击此处

you can use ExtAudioFileGetProperty to get the ASBD from existing m4a audio file.

For more details Click here.

叹梦 2024-10-18 05:52:58

您可以使用 2(至少)两种不同的方法获取文件的 ASBD。您可以使用“ExtAudioFileGetProperty”或“AudioFileGetProperty”。

AudioFileGetProperty:

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:

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 );
}

You can get ASBD of a file with 2 (at least) different methods. You can use 'ExtAudioFileGetProperty' or 'AudioFileGetProperty'.

AudioFileGetProperty:

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:

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 );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文