我刚看了WWDC视频(AVAudioEngine实践中的会话502 )AVAudioEngine,我非常高兴能够建立一个基于这种技术的应用程序.
我无法弄清楚如何对麦克风输入或调音台输出进行电平监控.
有人可以帮忙吗?为了清楚起见,我所说的是监控当前输入信号(并在UI中显示),而不是通道/轨道的输入/输出音量设置.
我知道你可以做到这一点AVAudioRecorder,但是这不是AVAudioNode它的AVAudioEngine需要.
HEJ.我想用AVAudioEngineSwift中的new实现一个实时音频应用程序.有人有新框架经验吗?实时应用程序如何工作?
我的第一个想法是将(已处理的)输入数据存储到一个AVAudioPCMBuffer对象中,然后让它AVAudioPlayerNode在我的演示类中看到:
import AVFoundation
class AudioIO {
var audioEngine: AVAudioEngine
var audioInputNode : AVAudioInputNode
var audioPlayerNode: AVAudioPlayerNode
var audioMixerNode: AVAudioMixerNode
var audioBuffer: AVAudioPCMBuffer
init(){
audioEngine = AVAudioEngine()
audioPlayerNode = AVAudioPlayerNode()
audioMixerNode = audioEngine.mainMixerNode
let frameLength = UInt32(256)
audioBuffer = AVAudioPCMBuffer(PCMFormat: audioPlayerNode.outputFormatForBus(0), frameCapacity: frameLength)
audioBuffer.frameLength = frameLength
audioInputNode = audioEngine.inputNode
audioInputNode.installTapOnBus(0, bufferSize:frameLength, format: audioInputNode.outputFormatForBus(0), block: {(buffer, time) in
let channels = UnsafeArray(start: buffer.floatChannelData, length: Int(buffer.format.channelCount))
let floats = UnsafeArray(start: channels[0], length: Int(buffer.frameLength))
for var i …Run Code Online (Sandbox Code Playgroud) 我已经配置了AVAudioSinkNodeAttach to ,AVAudioEngine如下inputNode所示:
let sinkNode = AVAudioSinkNode() { (timestamp, frames, audioBufferList) -> OSStatus in
print("SINK: \(timestamp.pointee.mHostTime) - \(frames) - \(audioBufferList.pointee.mNumberBuffers)")
return noErr
}
audioEngine.attach(sinkNode)
audioEngine.connect(audioEngine.inputNode, to: sinkNode, format: nil)
audioEngine.prepare()
do {
try audioEngine.start()
print("AudioEngine started.")
} catch {
print("AudioEngine did not start!")
}
Run Code Online (Sandbox Code Playgroud)
我已经单独将其配置为使用“内置麦克风”设备(我确信它确实使用了)。
如果我将麦克风的采样率设置为 44100(使用 Apple 在所有 Mac 上提供的“音频 MIDI 设置”应用程序),一切都会按预期工作:
AudioEngine started.
SINK: 692312319180567 - 512 - 2
SINK: 692312348024104 - 512 - 2
SINK: 692312359634082 - 512 - 2
SINK: …Run Code Online (Sandbox Code Playgroud)