AudioKit-如何从麦克风获取实时floatChannelData? [英] AudioKit - How to get Real Time floatChannelData from Microphone?

查看:64
本文介绍了AudioKit-如何从麦克风获取实时floatChannelData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Audiokit的新手,我正在尝试对来自麦克风的输入音频进行一些实时数字信号处理.

I'm new to Audiokit and I'm trying to do some real-time digital signal processing on input audio from the microphone.

我知道我想要的数据在AKAudioFile的FloatChannelData中,但是如果我想实时获取该怎么办?我目前正在使用AKMicrophone,AKFrequencyTracker,AKNodeOutputPlot,AKBooster,并且正在绘制跟踪器的幅度数据.但是,该数据与音频信号不同(如您所知,它是RMS).有什么方法可以从麦克风获取信号的Float数据吗?甚至从AKNodeOutputPlot中?我只需要读取权限即可.

I know the data I want is in AKAudioFile's FloatChannelData, but what if I want to obtain this in real-time? I'm currently using AKMicrophone, AKFrequencyTracker, AKNodeOutputPlot, AKBooster and I'm plotting the tracker's amplitude data. However, that data is not the same as the audio signal (as you know, it's the RMS). Is there any way I can obtain the signal's Float data from the mic? Or even from the AKNodeOutputPlot? I just need read-access.

AKSettings.audioInputEnabled = true
mic = AKMicrophone()
plot = AKNodeOutputPlot(mic, frame: audioInputPlot.bounds)
tracker = AKFrequencyTracker.init(mic)
silence = AKBooster(tracker,gain:0)
AudioKit.output = silence
AudioKit.start()

推荐的创建者此处:

AKNodeOutputPlot有效,它的一个简短文件.基本上,您只需要轻按节点并获取数据即可.

AKNodeOutputPlot works, its one short file. You're basically just tapping the node and grabbing the data.

如果我有一个plot实例(AKNodeOutputPlot),mic(AKMicrophone)并想将这些值输出到标签,这在我的viewController中将如何工作?

How would this work in my viewController if if have an instance of plot (AKNodeOutputPlot), mic(AKMicrophone) and want to output those values to a label?

推荐答案

使用水龙头在要从中获取数据的节点上进行点击.我在上面的引用中使用了AKNodeOutputPlot,因为它非常简单,只是将数据用作绘图的输入,但是您可以获取数据并对其进行任何处理.在此代码中(来自 AKNodeOutputPlot ):

Use a tap on which ever node you want to get the data out from. I used AKNodeOutputPlot in my quote above because its is fairly straightforward, just using that data as input for a plot, but you could take the data and do whatever with it. In this code (from AKNodeOutputPlot):

internal func setupNode(_ input: AKNode?) {
    if !isConnected {
        input?.avAudioNode.installTap(
            onBus: 0,
            bufferSize: bufferSize,
            format: nil) { [weak self] (buffer, _) in

                guard let strongSelf = self else {
                    AKLog("Unable to create strong reference to self")
                    return
                }
                buffer.frameLength = strongSelf.bufferSize
                let offset = Int(buffer.frameCapacity - buffer.frameLength)
                if let tail = buffer.floatChannelData?[0] {
                    strongSelf.updateBuffer(&tail[offset], withBufferSize: strongSelf.bufferSize)
                }
        }
    }
    isConnected = true
}

您可以实时获取缓冲区数据.在这里,我们只是将其发送到"updateBuffer",在此处对其进行绘制,但无需绘制其他内容.

You get the buffer data in real time. Here we just send it to "updateBuffer" where it gets plotted, but instead of plotting you'd do something else.

这篇关于AudioKit-如何从麦克风获取实时floatChannelData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆