user1528944
user1528944

Reputation: 223

How does AudioKit's AKNodeOutputPlot pull it's data?

I'm very new to the AudioKit framework and I have been trying to understand a bit more about the DSP side to it. Whilst rummaging around in the source code I realised that AKNodeOutputPlot does not pull data from the node the same way others would.

In the DSP code for the AKAmplitudeTracker an RMS value is calculated for each channel and the result is briefly written to the output buffer but at the end of the for loop the node is essentially bypassed by setting the output to the original input:

void process(AUAudioFrameCount frameCount, AUAudioFrameCount bufferOffset) override {

    for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {

        int frameOffset = int(frameIndex + bufferOffset);

        for (int channel = 0; channel < channels; ++channel) {
            float *in  = (float *)inBufferListPtr->mBuffers[channel].mData  + frameOffset;
            float temp = *in;
            float *out = (float *)outBufferListPtr->mBuffers[channel].mData + frameOffset;
            if (channel == 0) {
                if (started) {
                    sp_rms_compute(sp, leftRMS, in, out);
                    leftAmplitude = *out;
                } else {
                    leftAmplitude = 0;
                }
            } else {
                if (started) {
                    sp_rms_compute(sp, rightRMS, in, out);
                    rightAmplitude = *out;
                } else {
                    rightAmplitude = 0;
                }
            }
            *out = temp;
        }
    }
}

This makes sense since outputting the RMS value to the device speakers would sound terrible but when this node is used as the input to the AKNodeOutputPlot object RMS values are plotted.

input and rms plot

I assumed that the leftAmplitude and rightAmplitude variables were being referenced somewhere but even if they are zeroed out the plot works just fine. I'm interested in doing some work on the signal without effecting the output so I'd love it someone could help me figure how the AKPlot is grabbing this data.

Cheers

Upvotes: 4

Views: 540

Answers (1)

Aurelius Prochazka
Aurelius Prochazka

Reputation: 4573

AKNodeOutputPlot works with something called a "tap":

https://github.com/AudioKit/AudioKit/blob/master/AudioKit/Common/User%20Interface/AKNodeOutputPlot.swift

There are also a few other taps that are not necessarily just for user interface purposes:

https://github.com/AudioKit/AudioKit/tree/master/AudioKit/Common/Taps

Taps allow you to inspect the data being pulled through another node without being inserted into the signal chain itself.

Upvotes: 2

Related Questions