what is AudioStreamBasicDescription for m4a file format
Question
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.
Solution
you can use ExtAudioFileGetProperty to get the ASBD from existing m4a audio file.
For more details Click here.
OTHER TIPS
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 );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow