如果我们从麦克风获取输入,则哪些值将进入输入模拟声音的PCM缓冲区?

时间:2019-02-04 13:40:24

标签: ios swift buffer pcm avkit

我正在一个Swift IOS项目中,我必须从麦克风中获取输入,但是我得到了诸如PCM缓冲区B [82,90,-63]形式的值,我想知道是否这些振幅或电压产生声音信号?

AVKIT如何将声音输入到PCM缓冲区。

我做了google研究并在输入缓冲区上实现了相位逆函数,但是我不知道它实际上如何工作,就像在日志中我得到B [82,93,-68]值一样。

do
{
        let audioFile = try AVAudioFile(forWriting: URLFor(filename: "my_file.caf")!, settings:(targetFormat?.settings)!)
        engine.inputNode.installTap(onBus: 0, bufferSize: 1024, format: format, block: { (buffer: AVAudioPCMBuffer, time:AVAudioTime) -> Void in
            do {
                try audioFile.write(from: buffer)
            } catch let error as NSError {
                NSLog("Error writing %@", error.localizedDescription)
            }
        })
        self.engine.prepare()
        self.startEngine()
    }catch{

    }

相移码

do {
        let inFile: AVAudioFile = try AVAudioFile(forReading: URLFor(filename: "my_file.caf")!)
        let frameCount: AVAudioFrameCount = UInt32(inFile.length)
        let outFile: AVAudioFile = try AVAudioFile(forWriting: URLFor(filename: "my_file1.caf")!, settings: (targetFormat?.settings)!)
        let forwardBuffer: AVAudioPCMBuffer = AVAudioPCMBuffer(pcmFormat: targetFormat!, frameCapacity: frameCount)!
        let invertBuffer: AVAudioPCMBuffer = AVAudioPCMBuffer(pcmFormat: targetFormat!, frameCapacity: frameCount)!

        try inFile.read(into: forwardBuffer)
        let frameLength = forwardBuffer.frameLength
        invertBuffer.frameLength = frameLength
        print(forwardBuffer.frameLength)
        var floatArray = Array(UnsafeBufferPointer(start: forwardBuffer.floatChannelData?[0], count:Int(forwardBuffer.frameLength)))
        for i in 0..<floatArray.count{
            invertBuffer.floatChannelData!.pointee[i] = -floatArray[i]
        }
        try outFile.write(from: invertBuffer)
    } catch let error {
        print(error.localizedDescription)
    }
    }

我希望有人具备必需的知识,并且可以向我描述过程,并告诉我幕后情况。我有逆相,我只想知道输入是如何处理的,值是什么,它们代表什么?

0 个答案:

没有答案