听起来像你有几个问题堆积在那里。
当您设置AVAssetReader时,您可以传入设置字典。这里是我创造我AVAssetReaders ...
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*/);
}
我不关注“立体声”和“交错”之间的区别。我认为你要处理的是有两个双声道音频流(交错,其中L和R是交替的),而不是两声道单声道声音。单位可以处理,但一个队列将会与一个交错流更快乐。 – invalidname 2011-06-15 21:06:56