相关疑难解决方法(0)

提取iPod库原始PCM样本并播放声音效果

我试图从iPod库中的MP3中提取原始PCM样本,以便我可以播放歌曲并操纵音调,速度和应用声音效果(如滤镜).我已经走了AVPlayer和AVAudioPlayer的路线,它们都不能完全控制播放.

以下代码就我所知.我现在处于一个不知道如何处理我的while循环中的CMSampleBufferRef的地步,因为我不知道使用哪个框架来播放音频并应用这些效果.

知道什么是实现这一目标的最佳方法?我已经查看了使用AVAssetWriter转换文件的情况,但这不会为我删除它,因为该过程太耗时.当然我可以将PCM样本读入内存进行播放,而不必先将它们写入磁盘?

注意:我知道下面的代码引用了项目中的一个mp3,但是我知道这种方法与我从MPMediaPropertyAssetURL中提取NSURL的方法相同


-(IBAction)loadTrack:(id)sender {

 NSString *songPath = [[NSBundle mainBundle] pathForResource:@"Smooth_Sub Focus_192" ofType:@"mp3"];
 NSURL *assetURL = [[NSURL alloc] initFileURLWithPath:songPath];

 AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];

 NSError *assetError = nil;
 AVAssetReader *assetReader = [[AVAssetReader assetReaderWithAsset:songAsset
                error:&assetError] retain];
 if (assetError) {
  NSLog (@"Error: %@", assetError);
  return;
 }

 AVAssetReaderOutput *assetReaderOutput = [[AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:songAsset.tracks
                           audioSettings: nil] retain];
 if (![assetReader canAddOutput:assetReaderOutput]) {
  NSLog (@"Incompatible Asser Reader Output");
  return;
 }

 [assetReader addOutput: assetReaderOutput];
 [assetReader startReading];

 CMSampleBufferRef nextBuffer;
 while (nextBuffer = [assetReaderOutput copyNextSampleBuffer]) {
  /* What …
Run Code Online (Sandbox Code Playgroud)

iphone mp3 ipod objective-c pcm

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

iphone ×1

ipod ×1

mp3 ×1

objective-c ×1

pcm ×1