m4a文件格式的AudioStreamBasicDescription是什么

m4a文件格式的AudioStreamBasicDescription是什么,ios,audio,m4a,Ios,Audio,M4a,我尝试了更多关于m4a文件格式的AudioStreamBasicDescription。但我还是有一些问题 请告诉我m4a文件格式的确切AudioStreamBasicDescription。您可以使用ExtAudioFileGetProperty从现有m4a音频文件获取ASBD 有关详细信息。您可以使用2种(至少)不同的方法获取文件的ASBD。您可以使用“ExtAudioFileGetProperty”或“AudioFileGetProperty” AudioFileGetProperty:

我尝试了更多关于m4a文件格式的AudioStreamBasicDescription。但我还是有一些问题


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

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


有关详细信息。

您可以使用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;
         */
    }
}
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 );
}
ExtAudioFileGetProperty:

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

如果你找到了结果,真希望你已经发布了!那么,在m4a文件上运行ExtAudioFileGetProperty时,结果如何?