Похоже, что у вас есть пара вопросов, собранных там.
Когда вы настраиваете 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 или Remote I / O, и он будет воспроизводиться правильно.
Для воспроизведения звука с использованием инфраструктуры AudioQueue данные должны следовать этомуflow:
AVAssetReader -> NSData Buffer -> 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*/);
}