我已尝试使用更多AudioStreamBasicDescription来处理m4a文件格式。我仍然遇到一些问题。
请有人告诉我m4a文件格式的确切AudioStreamBasicDescription。
答案 0 :(得分:5)
您可以使用ExtAudioFileGetProperty从现有的m4a音频文件中获取ASBD。
有关详情Click here。
答案 1 :(得分:0)
您可以使用2种(至少)不同的方法获取文件的ASBD。您可以使用'ExtAudioFileGetProperty'或'AudioFileGetProperty'。
AudioFileGetProperty:
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports System.Reflection
<TestClass()>
Public Class Application
<TestMethod()>
Public Sub TestEnums()
Dim ass As Assembly = Assembly.Load("Elektro.Application")
Dim types As IEnumerable(Of Type) =
From t As Type In ass.GetTypes() Where t.IsEnum
For Each t As Type In types
EnumHasRepeatedValues(t)
Next
End Sub
Public Sub EnumHasRepeatedValues(ByVal t As Type)
Assert.AreEqual([Enum].GetValues(t).Length,
[Enum].GetNames(t).Length,
String.Format("Enum {0}.{1} has defined repeated values.",
t.Namespace, t.Name))
End Sub
End Class
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;
*/
}
}