开发者

what is AudioStreamBasicDescription for m4a file format

开发者 https://www.devze.com 2023-02-03 08:45 出处:网络
I have tried with more AudioStreamBasicDescription for m4a file format. Still I am getting some issues with that.

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

Please anyone tell me the exact Aud开发者_运维技巧ioStreamBasicDescription for m4a file format.


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

For more details Click here.


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

精彩评论

暂无评论...
验证码 换一张
取 消