首页 > 解决方案 > 使用 AVAudioEngine for MPMediaItem 音质不佳

问题描述

我正在尝试使用 AVAudioEngine 将过滤器应用于从苹果音乐库中获取的声音:

首先,我得到 AVAudioFile:

NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
NSError *error;
AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:assetURL error:&error];

然后我尝试将其转换为 AVAudioPCMBuffer:

AVAudioFormat *format = audioFile.processingFormat;
AVAudioFrameCount capacity = (AVAudioFrameCount)audioFile.length;
AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:format frameCapacity:capacity];
[audioFile readIntoBuffer:buffer error:nil];

最后我尝试使用 AVAudioEngine 连接所有内容并安排缓冲区:

[engine attachNode:audioEQ];
[engine attachNode:avHighPassFilter];
[engine attachNode:audioPlayerNode];
[engine connect:audioPlayerNode to:mainMixer format:[mainMixer outputFormatForBus:0]];
[engine connect: audioPlayerNode to:audioEQ format:buffer.format];
[engine connect: audioEQ to:avHighPassFilter format:buffer.format];
[engine connect:avHighPassFilter to:mainMixer format:buffer.format];
[audioPlayerNode scheduleBuffer:buffer atTime:nil options:AVAudioPlayerNodeBufferLoops completionHandler:nil];

它播放这首歌,但质量很差。当我尝试先将 MPMediaItem 导出到我的文档目录时,声音质量稍微好一点,但仍然不够好。

谁能帮我解决它?“com.apple.m4a-audio”格式有问题吗?

标签: objective-cavaudioenginempmediaitem

解决方案


推荐阅读