1

尝试将 M4A 转换为 PCM 一开始很顺利。我能够转换和读取字节。但是我不确定这是否是正确的方法。当我尝试获取 NSData 中的字节时,我得到了 16384 个字节。

这是我的功能

func getData(sampleRef:CMSampleBufferRef) -> NSMutableData{


    let dataBuffer = CMSampleBufferGetDataBuffer(sampleRef)
    let length = CMBlockBufferGetDataLength(dataBuffer!)

    var data = NSMutableData(length: length)


     CMBlockBufferCopyDataBytes(dataBuffer!, 0, length, data!.mutableBytes)

        print(data!)// this prints 16384 bytes 



    return data!


}

我尝试将此数据转换为 Int16

 // 3 lines below i was just testing how it converts to Int16
    let count = data!.length / sizeof(Int16)
    var array = [Int16](count: count, repeatedValue: 0)

    data!.getBytes(&array, length: data!.length)

这些是我从 M4A 文件解码 PCM 的设置。

    let outputSettings = [
        AVFormatIDKey: Int(kAudioFormatLinearPCM),
        AVSampleRateKey: 44100,
        AVLinearPCMBitDepthKey:16,
        AVLinearPCMIsFloatKey:0,
        AVNumberOfChannelsKey: 1 as NSNumber,

    ]

PS。我用相同的设置记录文件

4

0 回答 0