gpt4 book ai didi

ios - 您如何将 iPod 库 Assets 连接到音频队列服务并使用音频单元进行处理?

转载 作者:可可西里 更新时间:2023-11-01 05:48:09 24 4
gpt4 key购买 nike

我需要处理来自 iPod 库的音频。读取 iPod 库 Assets 的唯一方法是 AVAssetReader。要使用音频单元处理音频,它需要是立体声格式,所以我有左右声道的值。但是当我使用 AVAssetReader 从 iPod 库中读取 Assets 时,它不允许我以立体声格式将其取出。它以交错格式出现,我不知道如何分成左右声道。

要到达我需要去的地方,我需要执行以下操作之一:

  1. 让 AVAssetReader 给我一个立体声格式的 AudioBufferList
  2. 将交错数据转换为非交错数据以获得我需要的立体声输出
  3. 通过音频队列服务发送它以通过自动缓冲获得我需要的内容

我似乎受到现有公共(public) API 可以做什么以及 AVAssetReader 在读取 iPod 库 Assets 时支持的内容的限制。你会怎么做?我怎样才能得到我需要用音频单元处理的东西?

我的另一个限制是我无法一次读取整首歌曲,因为它会填满内存并导致应用程序崩溃。这就是我要使用音频队列服务的原因。如果我可以将 iPod 库中的 Assets 视为立体声格式的流,那么我的所有要求都会得到解决。

这能做到吗?是否有任何文档、博客或文章可以解释如何做到这一点?

最佳答案

听起来你有几个问题堆在那里。

当你设置一个 AVAssetReader 时,你可以传入一个设置字典。这是我创建 AVAssetReader 的方式...

    AVAssetReader* CreateAssetReaderFromSong(AVURLAsset* songURL) {

if([songURL.tracks count] <= 0)
return NULL;


AVAssetTrack* songTrack = [songURL.tracks objectAtIndex:0];

NSDictionary* outputSettingsDict = [[NSDictionary alloc] initWithObjectsAndKeys:

[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
// [NSNumber numberWithInt:AUDIO_SAMPLE_RATE],AVSampleRateKey, /*Not Supported*/
// [NSNumber numberWithInt: 2],AVNumberOfChannelsKey, /*Not Supported*/

[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsNonInterleaved,

nil];

NSError* error = nil;
AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:songURL error:&error];

{
AVAssetReaderTrackOutput* output = [[AVAssetReaderTrackOutput alloc] initWithTrack:songTrack outputSettings:outputSettingsDict];
[reader addOutput:output];
[output release];
}

return reader;
}

就拆分左右声道而言,您可以根据“AVLinearPCMBitDepthKey”遍历数据。

所以像这样的 16 位...

for (j=0; j<tBufCopy; j++, pAD+=2) {            // Fill the buffers...
mProcessingBuffer.Left[(tBlockUsed+j)] = ((sint32)pAD[0]);
mProcessingBuffer.Right[(tBlockUsed+j)] = ((sint32)pAD[1]);
}

现在我假设您需要这个来进行处理。但是拥有交错格式的数据真的很不错。您通常可以采用直接交错格式并将其直接传递回 AudioQueue 或远程 I/O 回调,它会正确播放。

为了使用 AudioQueue 框架播放音频,数据应遵循以下流程:

AVAssetReader -> NSData 缓冲区 -> AudioQueueBuffer

然后在要求更多数据的 AudioQueue 回调中,只需传递 AudioQueueBuffer。像...

- (void) audioQueueCallback:(AudioQueueRef)aq  buffer:(AudioQueueBufferRef)buffer {

memcpy(buffer->mAudioData, srcData, mBufferByteSize);
//Setup buffer->mAudioDataSize

//...

AudioQueueEnqueueBuffer(mQueue, buffer, 0 /*CBR*/, 0 /*non compressed*/);
}

关于ios - 您如何将 iPod 库 Assets 连接到音频队列服务并使用音频单元进行处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6268317/

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