Nie*_*een 4 core-audio avfoundation ios
像这样加载 AVAsset 后:
AVAsset *asset = [AVAsset assetWithURL:url];
Run Code Online (Sandbox Code Playgroud)
我想知道音频轨道的采样率是多少。目前,我得到这样的音轨:
AVAssetTrack *audioTrack = [[asset tracksWithMediaCharacteristic:AVMediaCharacteristicAudible] objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
哪个有效。但是我似乎找不到任何类型的属性,即使在使用 Google 之后也找不到 ;-) ,这给了我采样率。这如何正常工作?甚至有可能吗?(我开始越来越怀疑,因为谷歌搜索并没有给我很多信息......)
let asset = AVAsset(url: URL(fileURLWithPath: "asset/p2a2.aif"))
let track = asset.tracks[0]
let desc = track.formatDescriptions[0] as! CMAudioFormatDescription
let basic = CMAudioFormatDescriptionGetStreamBasicDescription(desc)
print(basic?.pointee.mSampleRate)
Run Code Online (Sandbox Code Playgroud)
我正在使用 Swift,所以它看起来有点不同,但它仍然可以与 Obj-C 一起使用。
print(track.naturalTimeScale)
Run Code Online (Sandbox Code Playgroud)
似乎也给出了正确的答案,但由于这个名字,我有点担心。
找到了。我正在使用 MTAudioProcessingTap,因此在准备()函数中我可以使用:
void prepare(MTAudioProcessingTapRef tap, CMItemCount maxFrames, const AudioStreamBasicDescription *processingFormat)
{
sampleRate = processingFormat->mSampleRate;
NSLog(@"Preparing the Audio Tap Processor");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4120 次 |
| 最近记录: |