gpt4 book ai didi

ios - 设备上的 MTAudioProcessingTap 问题

转载 作者:行者123 更新时间:2023-12-02 08:21:34 25 4
gpt4 key购买 nike

我正在尝试根据此博客条目中的教程创建 MTAudioProcessingTap - http://chritto.wordpress.com/2013/01/07/processing-avplayers-audio-with-mtaudioprocessingtap/

问题在于处理各种音频格式。我已经能够使用 M4A 成功创建一个 Tap,但它不适用于 MP3。对我来说更奇怪的是 - 代码可以在两种格式的模拟器上运行,但不能在设备上运行(只有 m4a 可以运行)。我在进程 block 中收到 OSStatusError 代码 50,如果我尝试使用 AudioBufferList 数据,则会出现错误的访问。我正在使用的点击设置和回调如下。进程 block 似乎是罪魁祸首(我认为),但我不知道为什么。

更新 - 经过一段时间的休息后,它似乎第一次可以偶尔工作,但只是第一次。我感觉我的音频文件被某种锁定。有谁知道在未准备的区 block 中应该做什么来清理?

取消准备 block -

void unprepare(MTAudioProcessingTapRef tap)
{
NSLog(@"Unpreparing the Audio Tap Processor");
}

进程 block (将得到 OSStatus 错误 50)-

void process(MTAudioProcessingTapRef tap, CMItemCount numberFrames,
MTAudioProcessingTapFlags flags, AudioBufferList *bufferListInOut,
CMItemCount *numberFramesOut, MTAudioProcessingTapFlags *flagsOut)
{
OSStatus err = MTAudioProcessingTapGetSourceAudio(tap, numberFrames, bufferListInOut,
flagsOut, NULL, numberFramesOut);
if (err) NSLog(@"Error from GetSourceAudio: %ld", err);
}

点击设置 -

NSURL *assetURL = [[NSBundle mainBundle] URLForResource:@"DLP" withExtension:@"mp3"];
assert(assetURL);

// Create the AVAsset
AVAsset *asset = [AVAsset assetWithURL:assetURL];
assert(asset);

// Create the AVPlayerItem
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
assert(playerItem);

assert([asset tracks]);
assert([[asset tracks] count]);

self.player = [AVPlayer playerWithPlayerItem:playerItem];
assert(self.player);

// Continuing on from where we created the AVAsset...
AVAssetTrack *audioTrack = [[asset tracks] objectAtIndex:0];
AVMutableAudioMixInputParameters *inputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack];

// Create a processing tap for the input parameters
MTAudioProcessingTapCallbacks callbacks;
callbacks.version = kMTAudioProcessingTapCallbacksVersion_0;
callbacks.clientInfo = (__bridge void *)(self);
callbacks.init = init;
callbacks.prepare = prepare;
callbacks.process = process;
callbacks.unprepare = unprepare;
callbacks.finalize = finalize;

MTAudioProcessingTapRef tap;
// The create function makes a copy of our callbacks struct
OSStatus err = MTAudioProcessingTapCreate(kCFAllocatorDefault, &callbacks,
kMTAudioProcessingTapCreationFlag_PostEffects, &tap);
if (err || !tap) {
NSLog(@"Unable to create the Audio Processing Tap");
return;
}
assert(tap);

// Assign the tap to the input parameters
inputParams.audioTapProcessor = tap;
// Create a new AVAudioMix and assign it to our AVPlayerItem
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = @[inputParams];
playerItem.audioMix = audioMix;

// And then we create the AVPlayer with the playerItem, and send it the play message...
[self.player play];

最佳答案

这显然是 6.0 中的一个错误(我的设备仍在运行)。模拟器版本为 6.1

将设备升级到 6.1.2,错误消失。

关于ios - 设备上的 MTAudioProcessingTap 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15351507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com