what is AudioStreamBasicDescription for m4a file format

喜你入骨 提交于 2019-12-23 12:12:00

问题


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.


回答1:


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

For more details Click here.




回答2:


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


来源:https://stackoverflow.com/questions/4655277/what-is-audiostreambasicdescription-for-m4a-file-format

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