Tapping Audio in Audio Graphs
TapAudioNode
can be used to capture buffers going through any point of an audio graph. onBufferUpdate
callback can be used to get access to AudioBuffer
object. AudioBuffer
has a helper method getInterleavedData
that can return pointer to a interlaved audio data.
TapAudioNode
is a Sink node, which means it does not have any output. To add this node in between two nodes you will need to use BusSplitterNode
.
- Swift
- C++
import SwitchboardSDK
var audioBuffer = SBAudioBuffer()
let tapAudioNode = SBTapAudioNode()
let splitterNode = SBBusSplitterNode()
tapAudioNode.onBufferUpdate = { [weak self] in
guard let self = self else { return }
audioBuffer = self.tapAudioNode.buffers
// get pointer to buffers
let buffers = audioBuffer.getReadPointer()
// you can also get pointer to interleaved buffer
let interleavedBuffer = audioBuffer.getInterleavedData()
}
audioGraph.addNode(tapAudioNode)
audioGraph.addNode(splitterNode)
audioGraph.connect(audioGraph.inputNode, to: splitterNode)
audioGraph.connect(splitterNode, to: tapAudioNode)
audioGraph.connect(splitterNode, to: audioGraph.outputNode)
#include <switchboard_v2/TapAudioNode.hpp>
#include <switchboard_v2/BusSplitterNode.hpp>
tapAudioNode.onBufferUpdate = [this]() {
// get read pointer to buffers
auto readPointer = tapAudioNode.buffer->getReadPointer()
// you can also get pointer to interleaved buffer
auto interleavedData = tapAudioNode.buffer->getInterleavedData()
};
audioGraph.addNode(tapAudioNode);
audioGraph.addNode(busSplitterNode);
audioGraph.connect(audioGraph.getInputNode(), busSplitterNode);
audioGraph.connect(busSplitterNode, tapAudioNode);
audioGraph.connect(busSplitterNode, audioGraph.getOutputNode());
note
onBufferUpdate
is called on the audio thread, so make sure any file writing operations you do in the onBufferUpdate
are on a separate thread to avoid blocking the audio thread.
Read more about the C++ classes in our API reference.