4

我有 AVAudioPCMBuffer ,我想将其中的一部分复制到其他缓冲区(从它的末尾剪掉一部分声音)

    let samples = Array(UnsafeBufferPointer(start: buffer.floatChannelData![0], count:Int(buffer.frameLength)))
    let newPcmBuffer = AVAudioPCMBuffer(pcmFormat: FileThatContainsTheBuffer.processingFormat, frameCapacity: AVAudioFrameCount(_playFile.length))

    let count = Int(CGFloat(samples.count) * (/* some value between 0 and 1 */))

    for i in 0 ..<  count
    {
        newPcmBuffer.floatChannelData![0][i] = buffer.floatChannelData![0][i]
    }

    if let url = getFileUrl(fileExtension: "caf")
    {
        let newPlayFile = try AVAudioFile(forWriting: url as URL, settings: [:], commonFormat: self.format!.commonFormat, interleaved: false)
        try newPlayFile.write(from: newPcmBuffer)
    }

当我尝试播放 newPlayFile 时,它​​会播放静音(或根本不播放)我知道问题出在 for 循环中,这样做的正确方法是什么?

4

0 回答 0