gpt4 book ai didi

ios - 当我使用 installTap(onBus 进行多声道音频?

转载 作者:行者123 更新时间:2023-12-01 19:53:23 26 4
gpt4 key购买 nike

当我使用 installTap(onBus 进行多声道音频?

如果 channel 数 > 1,那么它将包含左麦克风?或者它将包含来自左麦克风和右麦克风的样本?

当我使用 iphone 模拟器时 Format = pcmFormatFloat32, channelCount = 2, sampleRate = 44100.0, not Interleaved

我使用此代码

let bus = 0
inputNode.installTap(onBus: bus, bufferSize: myTapOnBusBufferSize, format: theAudioFormat) {
(buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
self.onNewBuffer(buffer)
}

func onNewBuffer(_ inputBuffer:AVAudioPCMBuffer!)
{
var samplesAsDoubles:[Double] = []

for i in 0 ..< Int(inputBuffer.frameLength)
{
let theSample = Double((inputBuffer.floatChannelData?.pointee[i])!)
samplesAsDoubles.append( theSample )
}
}

print("number of input busses = \(inputNode.numberOfInputs)")

它打印
输入总线数 = 1

对于我在 block 内部的缓冲区中的 samplesAsDoubles 数组中的每个样本,它将来自哪个 channel ?这个样本是什么时候记录的?

最佳答案

从 floatChannelData 的标题注释中:

The returned pointer is to format.channelCount pointers to float. Each of these pointers is to "frameLength" valid samples, which are spaced by "stride" samples.

If format.interleaved is false (as with the standard deinterleaved float format), then the pointers will be to separate chunks of memory. "stride" is 1.



FloatChannelData 为您提供了一个 2D 浮点数组。对于非交错的 2 channel 缓冲区,您可以像这样访问单个样本:
let channelCount = Int(buffer.format.channelCount)
let frameCount = Int(buffer.frameLength)

if let channels = buffer.floatChannelData { //channels is 2D float array
for channelIndex in 0..<channelCount {
let channel = channels[channelIndex] //1D float array
print(channelIndex == 0 ? "left" : "right")
for frameIndex in 0..<frameCount {
let sample = channel[frameIndex]
print(" \(sample)")
}
}
}

关于ios - 当我使用 installTap(onBus 进行多声道音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44234717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com