Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the number of Channels from an AVAsset

I am loading Audio assets via AVAssets. I want to figure out how many channels (mono or stereo basically) are in the asset. What is the best way to do this?

like image 722
TurqMage Avatar asked Aug 03 '11 17:08

TurqMage


1 Answers

This appears to be what I am looking for.

AVAssetTrack* songTrack = [mAssetToLoad.tracks objectAtIndex:0];
NSArray* formatDesc = songTrack.formatDescriptions;
for(unsigned int i = 0; i < [formatDesc count]; ++i) {
    CMAudioFormatDescriptionRef item = (CMAudioFormatDescriptionRef)[formatDesc objectAtIndex:i];
    const AudioStreamBasicDescription* bobTheDesc = CMAudioFormatDescriptionGetStreamBasicDescription (item);
    if(bobTheDesc && bobTheDesc->mChannelsPerFrame == 1) {
        mIsMono = true;
    }
}
like image 116
TurqMage Avatar answered Oct 23 '22 21:10

TurqMage