Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use AVAssetReader to get back a stereo channel layout?

I'd like to be able to get back AudioBufferList from AVAssetReader which has 2 buffers so that I can process the left and right audio through an AudioUnit. I tried using the output settings below but it will not read as long as I specify the stereo layout set by kAudioChannelLayoutTag_Stereo.

Is it possible for AVAssetReader to return a non-interleaved result?

If not, how would I convert it to a non-interleaved AudioBufferList? I have tried to use Audio Converter Services but I cannot get it to accept either the the input or output values for the AudioStreamBasicDescription. (ASBD) If I cannot get the data in the format I want from AVAssetReader I would like to at least be able to convert it to the format I need.

Any tips are appreciated.

- (NSDictionary *) getOutputSettings {
    AudioChannelLayout channelLayout;
    memset(&channelLayout, 0, sizeof(AudioChannelLayout));
    channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
    NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey, 
                                    [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                    [NSNumber numberWithInt:2], AVNumberOfChannelsKey,
                                    [NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
                                    [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
                                    [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
                                    [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
                                    [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
                                    nil];

    return outputSettings;
}
like image 311
Brennan Avatar asked Apr 29 '11 05:04

Brennan


1 Answers

I think that kAudioChannelLayoutTag_Stereo is requesting interleaved samples, so I'd lose it.

It all depends on what kind of AVAssetReaderOutput you're creating with those output settings. AVAssetReaderTrackOutput does no conversion beyond decoding to LPCM, but AVAssetReaderAudioMixOutput accepts a bunch more format keys, in fact it probably IS an AVAssetReaderTrackOutput + AudioConverter.

like image 159
Rhythmic Fistman Avatar answered Oct 14 '22 00:10

Rhythmic Fistman