小编Sam*_*uel的帖子

从Linear PCM中提取音频通道

我想从LPCM原始文件中提取通道音频,即提取立体声LPCM文件的左右声道.LPCM是16位深度,交错,2个通道,litle端.从我收集的字节的顺序是{LeftChannel,RightChannel,LeftChannel,RightChannel ...},因为它是16位深度,每个通道将有2个字节的样本对吗?

所以我的问题是,如果我想提取左通道,那么我将采用0,2,4,6 ... n*2地址中的字节?而右边的通道是1,3,4,...(n*2 + 1).

在提取音频通道后,我应该将提取的通道的格式设置为16位深度,1通道?

提前致谢

这是我目前用来从AssetReader中提取PCM音频的代码.这段代码可以正常编写音乐文件而不提取其频道,所以我可能是由格式或其他东西引起的......

    NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
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];
NSError *assetError = nil;
AVAssetReader *assetReader = [[AVAssetReader assetReaderWithAsset:songAsset
                                                            error:&assetError]
                              retain];
if (assetError) {
    NSLog (@"error: %@", assetError);
    return;
}

AVAssetReaderOutput *assetReaderOutput = [[AVAssetReaderAudioMixOutput 
                                           assetReaderAudioMixOutputWithAudioTracks:songAsset.tracks
                                           audioSettings: outputSettings]
                                          retain]; …
Run Code Online (Sandbox Code Playgroud)

iphone audio pcm

8
推荐指数
1
解决办法
4790
查看次数

标签 统计

audio ×1

iphone ×1

pcm ×1